10

I am building a webservice project on a TFS2017 Update 3 with build tools 2017. I get the following error

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.CSharp.CurrentVersion.targets(322,5): Error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

What steps do I need to take to fix this error?

kenorb
  • 118,428
  • 63
  • 588
  • 624
doorman
  • 10,751
  • 14
  • 58
  • 113
  • Can you see "Microsoft.CSharp.Core.targets" file in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn" folder? – Eddie Chen - MSFT Nov 23 '17 at 07:09

5 Answers5

4

In my case, opening the existing Solution file (with .sln extension), it installed all the missing dependencies.

Otherwise check for missing target packages at nuget.org manually and install them (e.g. MSBuild.Microsoft.VisualStudio.Web.targets).

kenorb
  • 118,428
  • 63
  • 588
  • 624
2

As per this GitHub issue, you'll need to set $(RoslynTargetsPath).

If MSBuild is installed on the machine and your tests run in a Visual Studio Developer Command Prompt, then you shouldn't need to do anything. However, MSBuild 15.0 no longer places itself in the registry which makes it impossible for MSBuild to find itself. This is because of a mandate by Visual Studio where you can have multiple side-by-side installations. MSBuild in this case would be installed once per Visual Studio instance. MSBuild now finds itself by looking at environment variables set by the VS command prompt.

If you want to fully redistribute MSBuild via a combination of our packages and all of the other packages needed to do full project evaluation, you will have to set RoslynTargetsPath before you load projects. You could argue this is an issue with NuGet since all packages' <contentFiles /> go to the the root of your output directory and you can't specify a subdirectory for certain packages.

Community
  • 1
  • 1
kenorb
  • 118,428
  • 63
  • 588
  • 624
2

If you're coming to this page from google/duckduckgo after trying to figure out why you're getting a similar message in Ubuntu 20.04, maybe this can help: https://askubuntu.com/a/1231973/1073658 (tl;dr apt install mono-roslyn from mono-project's repo)

vydd
  • 31
  • 1
1

First suggest you directly use msbuild command on the build agent with TFS build service account. This will narrow down if the issue is related to your agent environment or your TFS build definition.

According to your error info, the path C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets is looking the path of Visual Studio 2017.

However, for Build Tools the path is different should be C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn

Seems you haven't installed VS2017 on your build agent. This maybe the root cause of the issue.

The simplest solution is installing VS2017 on your build agent. Note, you need to reconfigure the build agent or restart build agent service to capture those new capabilities. Otherwise you need to change the corresponding import section in your .csproj project files.

PatrickLu-MSFT
  • 44,639
  • 4
  • 24
  • 52
  • 2
    Hi @PatrickLu-MSFT I did have VS2017 installed on the build server and I reconfiguring the agents. However when building I still get C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.CSharp.CurrentVersion.targets(322,5): Error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn\Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. – doorman Nov 16 '17 at 11:11
  • And the project file has the following import statement – doorman Nov 16 '17 at 11:12
  • @doorman Could you go through corresponding path on the build agent ? If there are this fire or not? And if there is no, try to manually copy the file to that path, and build again see if this do the trick. Besides you could also set `system.bug=true` variable in the build log to get more detail log for troubleshooting. – PatrickLu-MSFT Nov 16 '17 at 15:19
0

I updated to TFS2018 and the problem got solved.

doorman
  • 10,751
  • 14
  • 58
  • 113