问题
I have a C# solution with 3 projects.
- App.Console\App.Console.csproj
- App.Web\App.Web.csproj
- App.Shared\App.Shared.csproj
Both App.Console
and App.Web
reference App.Shared
. Currently, I build each project separately as they have slightly different MSBuild arguments.
My current build process is as follows
MSBuild.SonarQube.Runner.exe begin /k:"MyApp" /n:"My App" /v:"1.0"
msbuild.exe msbuild App.Console\App.Console.csproj /t:'Rebuild' /p:Configuration=Release /p:OutDir=C:\Out\Console
msbuild.exe msbuild App.Web\App.Web.csproj /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=C:\Out\Web
MSBuild.SonarQube.Runner.exe end
I see statistics for both App.Console
and App.Web
, however, statistics for App.Shared
is missing. Instead, I notice a warning in the SonarQube runner output.
WARNING: Duplicate project GUID: "21889c3d-d9c4-40d6-a4e4-971735d19ee2". Check that the project is only being built for a single platform/configuration and that that the project guid is unique. The project will not be analyzed by SonarQube. Project file: C:\Projects\MyApp\App.Shared\App.Shared.csproj
I believe this warning is the root of my problem.
If I do the following:
MSBuild.SonarQube.Runner.exe begin /k:"MyConsoleApp" /n:"My Console App" /v:"1.0"
msbuild.exe msbuild App.Console\App.Console.csproj /t:'Rebuild' /p:Configuration=Release /p:OutDir=C:\Out\Console
MSBuild.SonarQube.Runner.exe end
MSBuild.SonarQube.Runner.exe begin /k:"MyWebApp" /n:"My Web App" /v:"1.0"
msbuild.exe msbuild App.Web\App.Web.csproj /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=C:\Out\Web
MSBuild.SonarQube.Runner.exe end
I now have 2 separate projects in SonarQube which both contain statistics for App.Shared
. This is bad because this information is duplicated between the two projects and does not accurately give me an overall technical debt for my solution.
I have been able to get all three set of statistics in one project by building the solution only:
MSBuild.SonarQube.Runner.exe begin /k:"MyApp" /n:"My App" /v:"1.0"
msbuild.exe msbuild App.sln /t:'Rebuild' /p:Configuration=Release
MSBuild.SonarQube.Runner.exe end
This is not ideal because building the solution does not build the web project the way I need, thus I must do a 2nd build after SonarQube completes (build the way I need it, not the way SonarQube wants it).
Is it possible to run msbuild
multiple times in-conjunction with the SonarQube MSBuild runner and get one set of complete statistics?
回答1:
In the shared app, you can conditionally set a <SonarQubeExclude>true</SonarQubeExclude>
property, such that it will be set only when building either App.Web
or App.Console
.
You can find a proposal on how to achieve this in the Microsoft ALM Rangers guide to SonarQube under Appendix 3, "Explicitly associating an MSBuild project with a SonarQube project": http://redirect.sonarsource.com/doc/sq-setup-guide-for-dotnet-users.html
回答2:
The issue might be that you have an extra *.sln file in your solution. I encountered this when there was an old, dormant .sln file in a project folder. Deleting it resolved the issue.
来源:https://stackoverflow.com/questions/33788988/gather-statistics-for-shared-project