docker - 如何在容器内使用 dotnet 工具?
问题描述
我正在试验 Visual Studio Code Remote。我想使用SonarScanner进行代码质量分析。我已经按照指南在主机上安装了该工具,但是当我尝试从容器中使用它时,我得到:
# dotnet sonarscanner -h
No executable found matching command "dotnet-sonarscanner"
在主机上:
$ dotnet sonarscanner -h
SonarScanner for MSBuild 4.7.1
Using the .NET Core version of the Scanner for MSBuild
Usage:
SonarScanner.MSBuild [begin|end] /key:project_key [/name:project_name] [/version:project_version] [/d:sonar.key=value] [/s:settings_file]
When executing the begin phase, at least the project key must be defined.
Other properties can dynamically be defined with '/d:'. For example, '/d:sonar.verbose=true'.
A settings file can be used to define properties. If no settings file path is given, the file SonarQube.Analysis.xml in the installation directory will be used.
Only the token should be passed during the end phase, if it was used during the begin phase.
解决方案
这篇文章可以帮助你!
我们可以在容器中运行 dotnet 工具全局命令,设置以下行:
ENV PATH="${PATH}:/root/.dotnet/tools"
Dockerfile
FROM microsoft/dotnet:2.1-sdk as build-env
WORKDIR /src
COPY question-metrics-api/question-metrics-api.csproj question-metrics-api/
COPY question-metrics-data/question-metrics-data.csproj question-metrics-data/
COPY question-metrics-domain/question-metrics-domain.csproj question-metrics-domain/
COPY tests/question-metrics-domain-tests/question-metrics-domain-tests.csproj tests/question-metrics-domain-tests/
RUN dotnet restore tests/question-metrics-domain-tests
RUN dotnet restore question-metrics-api/question-metrics-api.csproj
COPY . .
#Run tests
RUN dotnet test tests/question-metrics-domain-tests/question-metrics-domain-tests.csproj
#Begin Sonar
RUN dotnet tool install -g dotnet-sonarscanner
ENV PATH="${PATH}:/root/.dotnet/tools"
RUN dotnet sonarscanner begin /k:"question-metrics-api" /d:sonar.host.url="http://sonarqube:9000" /d:sonar.login="7ed84e09a17a31e783fa8522d876e27fe4624977"
RUN dotnet build
RUN dotnet sonarscanner end /d:sonar.login="7ed84e09a17a31e783fa8522d876e27fe4624977"
推荐阅读
- python - kivy:在幻灯片过渡开始时播放声音并在按下按钮时停止
- ios - 如何让 Mapbox 地图完全离线工作?
- sql - 如何限制laravel中每个类别的结果
- python - 在 Pandas itertuples() 中,字符串 'class' 在 namedtuple 中被转换为 '_1'
- java - 在可完成的未来内/之后抛出异常
- javascript - 在 map 函数上使用 Promise
- ruby - 使用 Mina 从 github 部署到 Digital Ocean - 挂在“获取提交”上
- python - pytest 在具有构造函数的类中运行测试
- c++ - Emacs c ++选项卡写入空格删除
- javascript - 如何让 WebStorm 正确查看包功能?