添加对 Microsoft.Net.Compilers 的依赖后无法加载 Visual Studio 2015 项目

Unable to load Visual Studio 2015 project after adding dependency on Microsoft.Net.Compilers

我的项目依赖于 NuGet 包 Microsoft.Net.Compilers:

<package id="Microsoft.Net.Compilers" version="1.3.2" 
         targetFramework="net461" developmentDependency="true" />

但是,如果我在清除包文件夹后加载 Visual Studio,我的项目将不会加载并出现以下错误:

The imported project "C:\MyService\packages\Microsoft.Net.Compilers.1.3.2\tools\Microsoft.CSharp.Core.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
C:\Program Files (x86)\MSBuild.0\bin\Microsoft.CSharp.CurrentVersion.targets

所以它不会加载项目,因为它缺少一个文件,该文件在构建时使用 Nuget 恢复,只有在我可以加载项目时才有效。

您可以使用 Nuget 命令行工具来恢复您的包。如果您的系统还没有它,您可以在这里找到它:https://www.nuget.org/

在命令行上发出这个:

nuget restore