MSBUILD: when csproj is shared in multiple solutions, but only included in one an exception occurs

217 views
Skip to first unread message

Mike Barry

unread,
Feb 9, 2016, 2:07:34 PM2/9/16
to SonarQube
Hi all,

This issue is for 5.3 with the 4.4 C# plugin and the most current msbuild runner.

It's pretty common for a .csproj to be shared across multiple solutions. Such a structure might look like the following (annotated to help clarity):

Root (Folder)
  Shared (Folder)
    Shared.csproj (File)
    Shared.sln (File)
  Client (Folder)
    Client.csproj (File)
    Client.sln (File)

I've made sure the analysis only runs once on the shared code by adding something like this to the project file. 

  <PropertyGroup>
<SonarQubeExclude>!$(SolutionPath.Contains("Shared.sln"))</SonarQubeExclude>
  </PropertyGroup>

Now when I run I get the below error indicating I need to set the sonar.visualstudio.skipIfNotBuilt which I thought was deprecated. I've attached a sample solution demoing the issue.

Caused by: java.lang.IllegalArgumentException: The property "sonar.cs.fxcop.assembly" must be set and the project must have been built to execute FxCop rules. This property can be automatically set by the Analysis Bootstrapper for Visual Studio Projects plugin, see: http://docs.codehaus.org/x/TAA1Dg.If you wish to skip the analysis of not built projects, set the property "sonar.visualstudio.skipIfNotBuilt".

Mike Barry

unread,
Feb 9, 2016, 4:07:31 PM2/9/16
to SonarQube
For posterity I had to change my build output to be: PerProject. With SingleFolder the Shared\bin\debug was re-used. The first build had the .xml file with the fxcop results. The second one did not since it was excluded. It unfortunately cleared the .xml when it was built the second time. This same behavior happens during local development basically making it impossible to run from the command line. I don't know exactly what can be done about this, but we should look at doing something. It's totally not obvious how to support this behavior.

Mike
Reply all
Reply to author
Forward
0 new messages