NuGet 自动包还原不适用于 MSBuild [英] NuGet auto package restore does not work with MSBuild

查看:31
本文介绍了NuGet 自动包还原不适用于 MSBuild的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MSBuild 12.0 构建一个缺少 packages 内容(除了 repositories.config 里面)的解决方案.我希望它在构建之前自动恢复所有丢失的包,但事实并非如此 - MsBuild 报告了大量错误:

<块引用>

您是否缺少 using 指令或程序集引用?"

NuGet Manager 是 2.7(我在 Visual Studio 2013 中看到了关于 box 的内容).我什至试图传递 EnableNuGetPackageRestore=true 参数 - 没有运气.我错过了什么?

解决方案

已更新至 v3.3.0 的最新官方 NuGet 文档

包恢复方法

<块引用>

NuGet 提供了三种使用是从命令行构建解决方案时需要;它是在 NuGet 的早期版本中引入的,但在 NuGet 2.7 中得到了改进.

nuget.exe 还原 contoso.sln

<小时><块引用>

MSBuild 集成包还原方法是原始的包恢复实现,虽然它在许多场景中继续工作,它不涵盖全套其他两种方法解决的场景.

I'm trying to build a solution with packages content missing (except repositories.config inside) with MSBuild 12.0. I expect it to auto restore all missing packages before building but this is not the case - MsBuild reports tons of errors:

"are you missing a using directive or an assembly reference?"

NuGet Manager is 2.7 (I see this in Visual Studio 2013 about box). I even tried to pass EnableNuGetPackageRestore=true parameter - no luck. What am I missing?

解决方案

UPDATED with latest official NuGet documentation as of v3.3.0

Package Restore Approaches

NuGet offers three approaches to using package restore.


Automatic Package Restore is the NuGet team's recommended approach to Package Restore within Visual Studio, and it was introduced in NuGet 2.7. Beginning with NuGet 2.7, the NuGet Visual Studio extension integrates into Visual Studio's build events and restores missing packages when a build begins. This feature is enabled by default, but developers can opt out if desired.


Here's how it works:

  1. On project or solution build, Visual Studio raises an event that a build is beginning within the solution.
  2. NuGet responds to this event and checks for packages.config files included in the solution.
  3. For each packages.config file found, its packages are enumerated and Checked for exists in the solution's packages folder.
  4. Any missing packages are downloaded from the user's configured (and enabled) package sources, respecting the order of the package sources.
  5. As packages are downloaded, they are unzipped into the solution's packages folder.


If you have Nuget 2.7+ installed; it's important to pick one method for > managing Automatic Package Restore in Visual Studio.

Two methods are available:

  1. (Nuget 2.7+): Visual Studio -> Tools -> Package Manager -> Package Manager Settings -> Enable Automatic Package Restore
  2. (Nuget 2.6 and below) Right clicking on a solution and clicking "Enable Package Restore for this solution".


Command-Line Package Restore is required when building a solution from the command-line; it was introduced in early versions of NuGet, but was improved in NuGet 2.7.

nuget.exe restore contoso.sln


The MSBuild-integrated package restore approach is the original Package Restore implementation and though it continues to work in many scenarios, it does not cover the full set of scenarios addressed by the other two approaches.

这篇关于NuGet 自动包还原不适用于 MSBuild的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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