Microsoft.CSharp.Core.targets missing
Asked Answered
V

5

13

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?

Vanhook answered 13/11, 2017 at 8:45 Comment(1)
Can you see "Microsoft.CSharp.Core.targets" file in "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Roslyn" folder?Hypermeter
V
-1

I updated to TFS2018 and the problem got solved.

Vanhook answered 24/11, 2017 at 23:52 Comment(1)
this does little to assist anyone else who is experiencing the same problem. Perhaps a little more description about how "the problem got solved"?Eat
C
6

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).

Craner answered 18/9, 2018 at 12:15 Comment(0)
C
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.

Craner answered 11/9, 2018 at 16:16 Comment(1)
Could you expand about HOW to set $(RoslynTargetsPath) ? Especially on Mac?Yates
J
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)

Jellicoe answered 27/4, 2020 at 14:59 Comment(0)
A
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.

Ahouh answered 14/11, 2017 at 8:19 Comment(3)
Hi @Ahouh 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 <Import> declaration is correct, and that the file exists on disk.Vanhook
And the project file has the following import statement <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />Vanhook
@Vanhook 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.Ahouh
V
-1

I updated to TFS2018 and the problem got solved.

Vanhook answered 24/11, 2017 at 23:52 Comment(1)
this does little to assist anyone else who is experiencing the same problem. Perhaps a little more description about how "the problem got solved"?Eat

© 2022 - 2024 — McMap. All rights reserved.