我有一个ASP。NET MVC5应用程序,昨天工作,现在我得到这个错误时,我试图构建:

该项目引用了这台计算机上缺少的NuGet包。

我已经检查了两个选项,允许nuget自动下载和安装丢失的包检查/打开。我还尝试删除packages文件夹中的所有文件,然后让nuget重新下载它们。另外,当我打开nuget并寻找更新时,它说没有需要安装的。我想不出还能做些什么来解决这个恼人的问题。

我还通过右键单击项目并选择该选项启用了nuget恢复。然后,它添加了一个nuget文件夹和该文件夹中的三个项目,但没有采取任何措施来解决问题。我已经尝试重新构建,但仍然得到相同的错误。


当前回答

当csproj和sln文件在同一个文件夹中时,我有这个(愚蠢,我知道)。一旦我把sln文件移动到csproj文件夹上面的文件夹

其他回答

我有同样的错误,但在我的情况下,这是无关的nuget包在所有。 我的解决方案有一个项目,该项目参考了其他项目,这些项目不是我的解决方案的一部分,也没有构建。在用其他解决方案构建它们(或者我也可以将它们包含到我的解决方案中),并在visual studio中重新打开我的解决方案后,问题就解决了。

一种解决方案是从.csproj文件中删除以下内容:

<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

该项目引用了这台计算机上缺少的NuGet包。启用NuGet包还原来下载它们。欲了解更多信息,请参见http://go.microsoft.com/fwlink/?LinkID=322105。丢失的文件为{0}。

我有同样的问题,当我引用类库到我的MVC web应用程序,

问题是两个项目之间的nuget包版本号不匹配。

例如:我的类库有1.2.3的log4net,但我的webapp有1.2.6

修正:只要确保两个项目有相同的版本号引用。

在我的例子中,它与Microsoft.Build.Bcl版本有关。 我的nuget包版本是1.0.21,但我的项目文件仍然指向1.0.14版本

所以我把我的。csproj文件从:

  <Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
   <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
  </Target>

to:

 <Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
  <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />

这个结构又开始工作了。

这个错误似乎是在代码的某个地方触发的。我们来看看。Csproj文件,可以在末尾找到它。

步骤1 从包中删除包。配置文件。

<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net46" />

步骤2 编辑.csproj项目文件并删除以下设置

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
  <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />

步骤3 进入包管理器控制台,执行Update-Package -重装命令