0

We use an on-premises build server (32-bit Windows 7; note: updating the machine is not an option) with Azure. The server automatically updated its version of VS 2017 to 15.9.30. After this update, most of our builds are now failing. The error messages vary somewhat, but they all have a similar pattern that seems to be related to MSBuild and/or NuGet. For example:

  • Error MSB4019: The imported project "C:\Program Files\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found
  • Error MSB4036: The "GetReferenceNearestTargetFrameworkTask" task was not found
  • Error MSB6003: The specified task executable "csc.exe" could not be run. Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies

Attempted fixes:

  • Builds were working before the update
  • Confirmed the offending files are actually missing. In some cases, parts of the path mentioned in the error message was not present on the build server
  • Although this seems like the wrong way to fix the problem, we copied the missing files to the appropriate locations on the build server. This seemed to fix a couple of the bad references, but some of the errors still persisted even when the correct file was provided
  • Confirmed that the "Nuget package manager" and the "Nuget targets and build tasks" components were installed through VS
  • Cleared the NuGet cache using the 'Tools | Options...' menu item in VS

Out of ideas at this point. Any suggestions/insights are welcomed. TIA.

user1617242
  • 53
  • 1
  • 5

1 Answers1

0

Error MSB4019

If you build the project with MSBuild command line, you should specify the parameter /p:VisualStudioVersion=15.0 in you command line, like:

msbuild.exe <project or solution to build> /p:VisualStudioVersion=15.0

Check the this thread for some more details.

If you build it with Visual Studio 2017, you can overwrite the value of

$(VCTargetsPath):

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\

You could check this ticket for some more details.

Error MSB4036

It seems that you are using self-hosted agent, you probably need to update your MSBUILD Tools components. Please refer to this blog to update the tools.

Vito Liu
  • 7,525
  • 1
  • 8
  • 17
  • In addition, please also try to run the project locally and share the result here. Thanks – Vito Liu Dec 31 '20 at 06:21
  • Unfortunately, the links above we not of much help. The build server has VS 2017, MSBuild tools/targets and the Nuget manager installed. If the solution that fails in the pipeline is loaded into the build server's version of VS, that solution can be built by without issue. If the MSBuild command created by the build pipeline is run in a VS command window on the build server, the command fails with the same errors mentioned above. I have confirmed that the MSBuild command does contain the "/p:VisualStudioVersion=15.0" switch you mention. I think MSBuild needs to be reinstalled, if possible. – user1617242 Jan 04 '21 at 02:11