我研究了这个问题,但没有一个解决办法有效。我安装了Visual Studio Professional 2015,我正在使用TFS。我的NuGet版本是3.1.6。这个问题只发生在我的c# Web API/MVC项目中。

我得到以下错误:

这个项目引用了NuGet包(s),这是缺失的 电脑。使用NuGet包还原来下载它们。更多的 信息,见http://go.microsoft.com/fwlink/?LinkID=322105。的 丢失的文件是 . . \ \ Microsoft.Net.Compilers.1.0.0 \制造\ Microsoft.Net.Compilers.props包

I do not have .nuget folder in my solutions. I have a packages folder in the solution and when I delete it, it seems like NuGet does rebuild the dependencies but the project still has the above error. I tried removing the project from TFS and it didn't fix it. Along with the above error, all the references in the project have yellow warning signs and say they are missing. When I checked the NuGet Package Manager for the project, everything that is "missing" has a green tick next to it, including Microsoft.Net.Compilers. I tried adding a new Web API/MVC project and it faced a similar problem where most references such as Owin were "missing" with the yellow warning sign.


当前回答

对我来说,问题是当我将解决方案复制到一个新文件夹并打开它时,它缺少如下所示的Nuget文件夹。我复制了这个文件夹,一切正常。注意:这个文件夹在我们的源代码控制中,但不在这个解决方案项目中,它在上面一个目录中。

其他回答

不同的用户名是常见的原因,Nuget下载一切到:“C:\Users\USER_NAME\source\repos”,如果你之前在不同的用户名上设置了项目。csproj文件可能仍然包含旧的用户名,只需打开它,并做一个搜索替换“C:\Users\ old_user_name \source\repos”到“C:\Users\NEW_USER_NAME\source\repos”。

注释WebConfig中的编译器选项:

<!--<system.codedom>
<compilers>
  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
</compilers>
</system.codedom>-->

更新包配置文件中的最新版本

  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.4" targetFramework="net452" />

重建如果一切正常,不需要继续,否则 右键单击项目,点击“卸载项目” 再次右键单击该项目并编辑.csproj文件

验证Codedom的路径,它在之前的路径中没有net45,手动添加,保存,加载,重建。它应该会起作用。

<Import Project="..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.4\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props" Condition="Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.4\build\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" />

我今天也犯了同样的错误(丢失了完全相同的包裹)。我还创建了一个MVC + Web API项目。

发生这种情况是因为我将应用程序文件(包括.csproj)文件移动到另一个位置。我手动更新了.sln文件,但所有包依赖项现在(Visual Studio 2015)存储在.csproj文件中。

编辑.csproj文件并更正解决方案文件夹(其中包含packages文件夹)的相对路径,为我解决了这个问题。

注意——这将更新整个解决方案的包,而不仅仅是项目。

如果你还有一个丢失的nuget包,在构建解决方案时给出错误,请使用以下命令,从工具> nuget包管理器>包管理器控制台使用nuget命令控制台。它将重新安装您的所有当前包。

Update-Package –reinstall

更新:

您可以将特定的项目名称作为参数传递。

Update-Package –reinstall -ProjectName SampleApp

遇到这个问题

按以下步骤求解

清除packages文件夹中的内容(先备份) 使用“更新-包-重新安装”从包管理控制台的NuGet中重新获取和重新安装包(Tools -> NuGet包管理器->包管理控制台) 从.csproj文件中删除冗余路径。注意:NuGet会添加新的路径到csproj文件,但它不会删除旧的路径… (有一些机会csproj文件有多个路径为同一文件)

为什么我们需要“Microsoft.Net.Compilers.props”? 它将提供“\roslyn”文件夹。如果没有它,你可能仍然可以编译程序,但不能使用@{html.RenderPartial…}