如何在 Visual Studio 中启用 NuGet 包还原? [英] How do I enable NuGet Package Restore in Visual Studio?

查看:40
本文介绍了如何在 Visual Studio 中启用 NuGet 包还原?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

堆栈上有一个,我能够使用此处描述的方法解决该问题.

  1. 从解决方案中删除 '.nuget' 解决方案目录
  2. 从您的 .csproj.vbproj 文件中删除对 nuget.targets 的所有引用.虽然不受官方支持,但如果您有很多项目需要,该文档链接到 PowerShell 脚本被清理干净.我手动编辑了我的,所以我无法就我的体验提供任何反馈.

手动编辑文件时,以下是您要查找的内容:

解决方案文件 (.sln)

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F4AEBB8B-A367-424E-861C895"ProjectSection(SolutionItems) = preProject.nu​​getNuGet.Config = .nugetNuGet.Config.nu​​getNuGet.exe = .nugetNuGet.exe.nu​​getNuGet.targets = .nugetNuGet.targets结束项目部分结束项目

项目文件 (.csproj/.vbproj)

 <属性组><ErrorText>此项目引用了此计算机上缺少的 NuGet 包.启用 NuGet 包还原以下载它们.有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105.丢失的文件是 {0}.</ErrorText></PropertyGroup><错误条件=!Exists('$(SolutionDir).nugetNuGet.targets')";Text=$([System.String]::Format('$(ErrorText)', '$(SolutionDir).nugetNuGet.targets'))";/></目标>

There's a similar post on stack but it doesn't help with my issue possibly because I am using Visual Studio 2015.

How do I get the "Enable NuGet Package Restore" option to appear in VS2015?

I chose File > New Project and created an empty ASP.NET Web Application. I'm looking for this menu option.

I should mention that I have looked for any pre-existing nuGet files in my project folder and there are none.

解决方案

It took far too long but I finally found this document on Migrating MSBuild-Integrated solutions to Automatic Package Restore and I was able to resolve the issue using the methods described here.

  1. Remove the '.nuget' solution directory along from the solution
  2. Remove all references to nuget.targets from your .csproj or .vbproj files. Though not officially supported, the document links to a PowerShell script if you have a lot of projects which need to be cleaned up. I manually edited mine by hand so I can't give any feedback regarding my experience with it.

When editing your files by hand, here's what you'll be looking for:

Solution File (.sln)

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{F4AEBB8B-A367-424E-8B14-F611C9667A85}"
ProjectSection(SolutionItems) = preProject
    .nugetNuGet.Config = .nugetNuGet.Config
    .nugetNuGet.exe = .nugetNuGet.exe
    .nugetNuGet.targets = .nugetNuGet.targets
EndProjectSection
EndProject

Project File (.csproj / .vbproj)

  <Import Project="$(SolutionDir).nugetNuGet.targets" Condition="Exists('$(SolutionDir).nugetNuGet.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).nugetNuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir).nugetNuGet.targets'))" />
  </Target>

这篇关于如何在 Visual Studio 中启用 NuGet 包还原?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆