在使用包恢复时,是否有方法自动更新. nuget 文件夹中的 nuget.exe?

自从 Nuget 1.5以来,我的团队一直在使用 Enable Package Restore 选项来保持软件包不受源代码控制。当 Nuget 1.6发布的时候,我们注意到了一个问题,那就是它没有把软件包拉下来。需要更新到1.6以匹配 Package Manager 的 nuget 文件夹。

一旦 Nuget 被更新,更新解决方案的最佳方式是什么?我没有看到一个简单的方法从工作室告诉哪个版本的 nuget 是在解决方案文件夹。到目前为止,我们吹走了。并重新运行“启用包还原”命令。

30767 次浏览

I would suggest updating .nuget\nuget.exe with this command from the command line:

nuget.exe update -self

[EDIT] : Close VS Solution first. If there's an update and the solution is opened, nuget.exe will be removed from the solution.

You could automatically update nuget.exe on restore by modifying the .nuget\nuget.targets to add the above command. I'd look at the restore command in there as an example. But I'm not sure if it's worth it, nuget.exe updates aren't that common, and backward compatibility should break very rarely.

I've found the best way to handle this is by simply deleting the .nuget folder and re-enabling solution wide package restore. As said above, you could add a self update command to your build, but that will not update the targets or config files if there are changes between versions (or remove the reference from your solution). Perhaps its not that big of a deal, but this is the sure fire way to make sure you have the latest exe and configuration files. And at the end of the day, updating is only an issue if you need access to a new command or there is eventually a breaking change in a new release.

See David Ebbo's post at his blog

Basically, All you need to do is create a NuGet.Config file next to your .sln file, containing:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear/>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="aspnetwebstacknightlyrelease" value="https://www.myget.org/f/aspnetwebstacknightlyrelease/" />
</packageSources>
</configuration>