堆栈中有similar post,但它对我的问题没有帮助,可能是因为我使用的是Visual Studio2015.

如何让"Enable NuGet Package Restore"选项出现在VS2015中?

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

在此处输入图像描述

我应该提到的是,我在我的项目文件夹中查找了任何预先存在的nuGet文件,但没有.

推荐答案

花了太长时间,但我终于在Migrating MSBuild-Integrated solutions to Automatic Package Restore上找到了这个文档,我能够使用这里描述的方法解决这个问题.

  1. 从解决方案中删除'.nuget'解决方案目录
  2. .csproj.vbproj文件中删除对nuget.targets的所有引用.虽然没有官方支持,但如果你有很多需要清理的项目,该文档会链接到PowerShell script.我手工编辑了我的,所以我不能给出任何关于我使用它的经验的反馈.

手工编辑文件时,您需要的是:

Solution File (.sln)

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

Project File (.csproj / .vbproj)

  <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>

Asp.net相关问答推荐

Razor中的共享本地化资源文件

域名 + 子域名在IIS部署

如何在编译时为我的 ASP.NET 项目中的每个控制器生成一个单独的 OpenAPI Swagger.json 文件?

C# - 将 xyz 平铺转换为纬度/经度,反之亦然,给出不同的结果

ReportViewer 控件 - 高度问题

如何为发布模式设置调试错误

Window.Open 使用 PDF 流而不是 PDF 位置

Directory.Exists 不适用于网络路径

使用 JavaScript 禁用 ASP.NET 验证器

如何使用 ASP.Net MVC 路由来路由图像?

asp.net 中的 Eval() 有什么用

从 ASP.NET 中的 POST 方法中检索数据

如何从 JS 访问 ViewBag

从后面的 asp.net 代码中读取表单身份验证 cookie

oAuth ASP.NET 成员资格提供程序

什么是实体框架中的复杂类型以及何时使用它?

测试 Web 表单应用程序 (ASP.NET) 的最佳方法是什么

如何将数据集转换为数据表

如何获取部署在 Azure 网站上的 ASP.NET 5 应用程序的错误详细信息?

ASP.NET - 从静态方法/静态类访问会话?