MSBuild MSB3030 error when building in Azure DevOps with Sonar analysis enabled

Hi all,

Situation

We are moving with our organization from SonarQube to SonarCloud for all our C# projects. We are a big fan of the PR integration feature in combination with Azure DevOps and till now everything went well for the projects that we’ve converted. However we have encountered a strange build issue on one of our largest (and oldest) code bases (C#, .Net 4.6.1 Full Framework) after enabling SonarCloud. We receive Error MSB303: Could not copy file as shown on the image below


This error pop ups every time for this project with SonarCloud enabled and is the same on every retry. We have not encountered this issue with our on-premise SonarQube for this project.

Build Steps & Logs

We started from a working release build of our code base that builds perfectly on our local machine and on the build server with the following configuration SonarCloud steps disabled:

  • Set Assembly Version
  • NuGet Restore
  • Prepare Analysis Configuration (disabled)
  • Visual Studio Build
  • Test Assemblies MsTest
  • Run Code Analysis (disabled)

But as soon as we enable the SonarCloud build steps, the error pops up. I have investigated the build logs of both versions of the builds and compared them but I don’t see the problem that causes this issue. I have checked the build server too and the files are indeed not present in the specified folders. The issue starts with the copy action of the app.config file that goes wrong:

2018-11-09T12:40:55.0968665Z _CopyAppConfigFile:
2018-11-09T12:40:55.0968861Z Copying file from "app.config" to "..\bin\Release\HR.Services.Core.Integration.dll.config".
2018-11-09T12:40:55.1177770Z ##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4187,5): Error MSB3030: Could not copy the file "obj\Release\HR.Services.Core.Integration.dll" because it was not found.
2018-11-09T12:40:55.1184773Z C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(4187,5): error MSB3030: Could not copy the file "obj\Release\HR.Services.Core.Integration.dll" because it was not found. [D:\Agent01\_work\9\s\src\HR.Services.Core.Integration\HR.Services.Core.Integration.csproj]
2018-11-09T12:40:55.1815864Z Done Building Project "D:\Agent01\_work\9\s\src\HR.Services.Core.Integration\HR.Services.Core.Integration.csproj" (default targets) -- FAILED.

I can provide the detailed builds logs in a pm if this can help with the analysis.

Can you help me with the analysis of this issue?

Thanks in advance!

Sorry for the late answer here, we’ll continue this thread on a private channel to be able to share logs and more context. Once we found the solution, we can come back here to post it so that other users benefit from it.

Hi Laurenz and Fabrice,

did you find any solution for this problem?

Thanks in advance!

Kind regards
Paddy

Hi Paddy. We don’t have a solution for this yet, partly because we haven’t been able to reproduce the issue locally. If you have a simple repro you can share that would be very helpful.

Thanks,
Duncan

Hi there,

Currently evaluating SonarSource tooling and seeing the same issue but in regards to AspNet Core razor compiled dll’s.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4551,5): Error MSB3030: Could not copy the file “…\Src\Presentation\SomeApp.Webapi\obj\x64\Release\netcoreapp2.2\win10-x64\SomeApp.Webapi.Views.pdb” because it was not found."

Can’t share the source unfortunately but any help/clues to investigate would be appreciated.

Setup:
Code all projects targeting netcore 2.2
Azure DevOps talking to custom build server on a VM in Azure
Community edition being used for the build of sln file.
Setup as per MS lab here - https://sonarcloud.io/documentation/integrations/vsts/

Hi,

The error stack you provide is showing a PDB file, are you executing your pipeline in debug ?

Mickaël

Hi @davidjsteele,

(cc @paddy)

With help from @laurenz and his colleagues we were eventually able to work out that the issue described in the original post was due to this obscure compiler bug.

In short, there are circumstances in which asking the compiler to write analysis issues to a file stops the compiler from generating the .dll file (so it seems likely it wouldn’t produce the .pdb file either). However, the compiler doesn’t emit any errors either. The build then fails in a later step when MSBuild tries to copy the non-existent file.

You can check if you’re affected by this bug by doing the following:

  1. Disable the SonarQube/SonarCloud analysis steps.
  2. Execute the build and check that it completes successfully
  3. Now add the following MSBuild parameter in the MSBuild step: /p:ErrorLog=RoslynIssues.json then check that the build still completes successfully.

If (2) succeeds but (3) fails then you’re affected by the compiler bug.

Workarounds/solutions: the bug has been fix in MSBuild 16.1 so the fix is to upgrade to the latest version of the compiler. If that isn’t possible, then an option is to change the severities of the issues being raised from Error to Warning by editing the ruleset.

@duncanp Thanks for the info - as per guidance above i can replicate the issue on a clean proj as per below
image
@mickaelcaro unsure why its generating or looking to copy the PDB, VS Build task is definitely set to release configuration.

Unfortunately can’t update the build server with VS2019 or similar build tools currently. As part of evaluating Sonarcloud, my initial thoughts were to get rid of custom rulesets and control it centrally within SonarCloud anyway, is this possible?

Sorry, should have looked before asking, found quality profiles. One thing i couldn’t find an answer to was whether custom profiles can be used in conjunction with SonarLint?

@davidjsteele yes, you can centrally control the rules that are executed using Quality Profiles in SonarCloud (create a custom quality, enable/disable rules within that Quality Profile and then specify which projects you want it to be used with).

During the build, the SonarCloud tasks will dynamically combine your custom rulesets with a ruleset generated from the Quality Profile in SonarCloud.

However, if you want to ignore your custom rulesets for now without editing your project files then just add the following MSBuild parameter in the MSBuild step: /p:CodeAnalysisRuleset=""

That will clear whatever ruleset is specified in the project files leaving only the ruleset generated from SonarCloud.

Custom profiles and SonarLint: in short, yes. If you use connected mode (i.e. tell SLVS which Sonar project your solution is associated with) then SLVS will generate a ruleset from the Quality Profile for the Sonar project, and update the MSBuild projects in the solution so that they point to the generated ruleset.