<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<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>
至:
<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" />
<RestorePackages>true</RestorePackages>
...
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
...
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<RestorePackages>true</RestorePackages>
...
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
...
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
14 回答
当我将类库引入我的MVC Web应用程序时,我遇到了同样的问题,
问题是两个项目之间的nuget包版本号不匹配 .
例如:我的类库的log4net为1.2.3,但我的webapp有1.2.6
修复:只需确保项目具有相同的版本号 .
在我的情况下,我不得不从.csproj文件中删除以下内容:
实际上,在此代码段中,您可以看到错误消息的来源 .
我正在从 MSBuild-Integrated Package Restore 转换为 Automatic Package Restore (http://docs.nuget.org/docs/workflows/migrating-to-automatic-package-restore)
一种解决方案是从.csproj文件中删除以下内容:
怎么样?
右键单击项目 . 卸载项目 .
右键单击项目 . 编辑csproj .
从文件中删除部件 . 保存 .
右键单击项目 . 重新加载项目 .
在我的情况下,它发生在我将我的解决方案文件夹从一个位置移动到另一个位置后,重新组织了一点,并在此过程中其相对文件夹结构发生了变化 .
所以我必须在我的
.csproj
文件中编辑类似于以下条目的所有条目至
(注意从 *..\packages* 到 *packages* 的变化 . 在你的情况下它可能是一个不同的相对结构,但你明白了 . )
通过右键单击我的解决方案,然后单击 Enable NuGet Package Restore 选项,我轻松解决了这个问题
(P.S:确保你有Nuget安装工具 - >扩展和更新 - > Nuget包管理器for Visual Studio 2013.如果没有先安装这个扩展)
希望能帮助到你 .
在我的情况下,它与Microsoft.Build.Bcl版本有关 . 我的nuget包版本是1.0.21,但我的项目文件仍然指向版本1.0.14
所以我改变了我的.csproj文件:
至:
构建工作再次开始 .
If you are using TFS
从解决方案的
.nuget
文件夹中删除NuGet.exe
和NuGet.targets
文件 . 确保文件本身也从解决方案工作区中删除 . 保留NuGet.Config
文件以继续绕过将包添加到源代码管理 .编辑解决方案中的每个项目文件(例如.csproj,.vbproj)并删除对
NuGet.targets
文件的任何引用 . 在您选择的编辑器中打开项目文件,然后删除以下设置:If you are not using TFS
从解决方案中删除
.nuget
文件夹 . 确保文件夹本身也从解决方案工作区中删除 .编辑解决方案中的每个项目文件(例如.csproj,.vbproj)并删除对
NuGet.targets
文件的任何引用 . 在您选择的编辑器中打开项目文件,然后删除以下设置:参考:Migrating MSBuild-Integrated solutions to use Automatic Package Restore
包裹是否可能已恢复到错误的文件夹?检查csproj文件中的路径是否正确 .
如果它们不同,则可能是由于包现在正在恢复到不同的位置 . 这可能是由于在检查NuGet.Config文件时指定了这样的节点:
这些包正在恢复,项目仍在查看旧位置 .
我遇到过同样的问题 . 在我的情况下,安装 Microsoft.Bcl.Build 包修复了问题 .
这些是我用来解决问题的步骤:
要将nuget包添加到您的解决方案中:
右键单击要引用nuget包的项目(不是解决方案) .
选择:管理nuget包
在弹出窗口的左侧,您有三个选择 . 如果选择Online> Microsoft&.NET,您将能够安装Microsoft ASP.NET Web API 2.2软件包分组器(或者您需要的任何软件包 - 我的是这个) .
现在右键单击您的解决方案(而不是项目),然后选择启用nuget包还原 . 这将导致在编译时自动下载包 .
对我而言,我只是将.nuget文件夹从工作解决方案复制到现有文件夹,并引用它的内容!
编辑.sln和.csproj并不总是那么简单或可取 . 获得错误列表后,您可以看到哪些项目缺少包(同样,References节点通常表示缺少程序集,除非包是源代码,资源,图像或仅基于文本的包) .
删除然后添加包不是一件好事除非您使用最新版本的软件包 . 否则要为惊喜做好准备,而不是总是令人愉快 .
例如,如果包是EntityFramework然后从NuGet库获得最新版本,在撰写此评论时它是 6.1.3 .
因此,处理这种情况最安全的方法可能是逐个恢复丢失的软件包 . 是的,有点痛苦的运动,但由于不同的包装版本追逐微妙的错误可能更令人不愉快 .
有了这个说法,让EntityFramework再次成为缺失的包,您可以在Package-Manager控制台中发出以下命令:
这将安装正确的版本,即 6.0.1 ,这是在packages.config中指定的版本:
当您尝试从项目中删除postsharp时,可能会发生这种情况 .
确保你删除行Loren说 .
我在解决方案根文件夹中创建了一个名为“.nuget”的文件夹然后在此文件夹中添加了文件“NuGet.Config”,其中包含以下内容
然后创建文件'.nuGet.targets'如下$(MSBuildProjectDirectory).. \