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?
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
).As per this GitHub issue, you'll need to set
$(RoslynTargetsPath)
.I updated to TFS2018 and the problem got solved.
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.