Microsoft.CSharp.Core.targets 失踪
Microsoft.CSharp.Core.targets missing
我正在使用构建工具 2017 在 TFS 2017 Update 3 上构建 Web 服务项目。我收到以下错误
C:\Program Files (x86)\Microsoft Visual
Studio17\Enterprise\MSBuild.0\Bin\Microsoft.CSharp.CurrentVersion.targets(322,5):
Error MSB4019: The imported project "C:\Program Files (x86)\Microsoft
Visual
Studio17\Enterprise\MSBuild.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.
我需要采取哪些步骤来修复此错误?
首先建议您直接在具有TFS 构建服务帐户的构建代理上使用msbuild 命令。如果问题与您的代理环境或您的 TFS 构建定义相关,这将缩小范围。
根据您的错误信息,路径 C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\Roslyn\Microsoft.CSharp.Core.targets
正在寻找 Visual Studio 2017 年的路径。
但是,对于构建工具,路径不同应该是 C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild.0\Bin\Roslyn
您似乎还没有在构建代理上安装 VS2017。这可能是问题的根本原因。
最简单的解决方案是在您的构建代理上安装 VS2017。请注意,您需要重新配置构建代理或重新启动构建代理服务以捕获这些新功能。否则,您需要更改 .csproj
项目文件中的相应导入部分。
我更新到TFS2018,问题解决了。
根据此 GitHub issue,您需要设置 $(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.
在我的例子中,打开现有的解决方案文件(扩展名为.sln
),它安装了所有缺少的依赖项。
否则在 nuget.org manually and install them (e.g. MSBuild.Microsoft.VisualStudio.Web.targets
处检查是否缺少目标包。
如果您在尝试弄清楚为什么在 Ubuntu 20.04 中收到类似消息后从 google/duckduckgo 来到此页面,也许这会有所帮助:https://askubuntu.com/a/1231973/1073658 (tl;dr apt install mono-roslyn
来自 mono-project 的 repo)
我正在使用构建工具 2017 在 TFS 2017 Update 3 上构建 Web 服务项目。我收到以下错误
C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\Microsoft.CSharp.CurrentVersion.targets(322,5): Error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.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.
我需要采取哪些步骤来修复此错误?
首先建议您直接在具有TFS 构建服务帐户的构建代理上使用msbuild 命令。如果问题与您的代理环境或您的 TFS 构建定义相关,这将缩小范围。
根据您的错误信息,路径 C:\Program Files (x86)\Microsoft Visual Studio17\Enterprise\MSBuild.0\Bin\Roslyn\Microsoft.CSharp.Core.targets
正在寻找 Visual Studio 2017 年的路径。
但是,对于构建工具,路径不同应该是 C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild.0\Bin\Roslyn
您似乎还没有在构建代理上安装 VS2017。这可能是问题的根本原因。
最简单的解决方案是在您的构建代理上安装 VS2017。请注意,您需要重新配置构建代理或重新启动构建代理服务以捕获这些新功能。否则,您需要更改 .csproj
项目文件中的相应导入部分。
我更新到TFS2018,问题解决了。
根据此 GitHub issue,您需要设置 $(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.
在我的例子中,打开现有的解决方案文件(扩展名为.sln
),它安装了所有缺少的依赖项。
否则在 nuget.org manually and install them (e.g. MSBuild.Microsoft.VisualStudio.Web.targets
处检查是否缺少目标包。
如果您在尝试弄清楚为什么在 Ubuntu 20.04 中收到类似消息后从 google/duckduckgo 来到此页面,也许这会有所帮助:https://askubuntu.com/a/1231973/1073658 (tl;dr apt install mono-roslyn
来自 mono-project 的 repo)