将 NuGet 中的包签入版本控制?
在 NuGet 之前,签入项目中使用的所有外部 DLL 是普遍接受的“最佳实践”。通常位于 Libs
或 3rdParty
目录中。
使用 NuGet 时,我是否应该签入 packages
目录,或者 MSBuild 有没有办法从 nuget feed 自动下载所需的包?
Prior to NuGet, it was common accepted 'best practice' to check-in all external DLLs used on a project. Typically in a Libs
or 3rdParty
directory.
When working with NuGet, am I supposed to check-in the packages
directory, or is there a way for MSBuild to auto download the needed packages from the nuget feed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
否
既然提出了这个问题,现在有一个简单的工作流程可以使用 NuGet,而无需将包提交到源代码控制
从包管理器控制台,您需要安装'NuGetPowerTools':
然后使您的项目能够支持包恢复时,您需要运行另一个命令:
现在您已准备好在没有软件包文件夹的情况下提交代码库。上一个命令更改了您的项目文件,以便如果包丢失,它们会自动下载并添加。
来源
使用 NuGet 而不将包提交到源代码管理
No
Since this question was asked there is now an easy workflow to use NuGet without commiting packages to source control
From your package manager console you need to install the 'NuGetPowerTools':
Then to enable your projects to support pack restore you need to run another command:
Now you are ready to commit your code base without the packages folder. The previous command changed your project files so that if packages are missing they get automatically downloaded and added.
Source
Using NuGet without committing packages to source control
是的。考虑“packages”目录相当于您在问题中提到的“libs”目录。这是我个人在 OSS 项目中采用的方法。
我们正在研究允许 MSBuild 自动下载所需包的功能,但尚未实现(从 NuGet 1.1 开始)。
我认为有些人可能已经自己实现了这些功能,但我们的计划是希望将该功能内置到 NuGet 1.2 或 1.3 中。
Yes. Consider the "packages" directory to be equivalent to your "libs" directory that you mentioned in your question. This is the approach I personally take with my OSS projects.
We are investigating features that would allow MSBuild to auto download the needed packages, but that hasn't been implemented (as of NuGet 1.1).
I think some people may have already implemented such features on their own, but our plan is to look at having that feature built in to NuGet 1.2 or 1.3 hopefully.
尽管这里有所有答案,但它仍然是一个普通的“可怕的解决方案”,因为没有将所有依赖项置于“某种”版本控制之下。
对于 GIT,这意味着 GIT-LFS。
NPM 最近的一集说明了原因:如果您所依赖的互联网存储库出现故障、不可用等,那么您就完蛋了,不是吗?
你不再能够构建你的东西 - 因此无法交付。
Despite all the answers here, it is still a plain ole' horrible solution to not have all your dependencies under "some kind" of version control.
For GIT, this would mean GIT-LFS.
The recent episode with NPM shows why: If the internet repository of which you depend breaks, are unavailable etc., well then you're screwed aint you?
You are no longer able to build your stuff - and therefore not able to deliver.
自从提出这个问题以来,我采用了以下方法,这样我就不必检查 toplovel Packages 目录。
在顶级 build.msbuild 文件中:
在每个 project.csproj 文件中
Since asking the question, I've put in the following approach so that I do not have to check in the toplovel Packages directory.
In a toplevel build.msbuild file:
In each project.csproj file
我意识到这个问题最初发布并回答时现实情况有所不同,但幸运的是答案发生了一些变化。现在可以使用 NuGet 使用预构建事件通过 MSBuild 下载依赖项。您不需要将包文件夹放入代码存储库中,所有依赖项都将在构建时下载和/或更新。这可能是一种解决方法,但看起来足够不错。有关详细信息,请参阅以下博客文章: http://blog .davidebbo.com/2011/03/using-nuget-without-committing-packages.html
I realize the reality was different when this question has been originally posted and answered, but fortunately the answer changed a bit. It is now possible to use NuGet to download dependencies via MSBuild using a Pre-Build event. You don't need to put the packages folder in your code repository, all dependencies will be downloaded and/or updated on build. It may a workaround, but it looks decent enough. See the following blog post for details: http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html
截至 2013 年 9 月 20 日,有一种名为“Nuget Restore”的东西。如果您愿意,实际上不必签入包文件夹。 (特别是如果您使用 DVCS)
请查看:使用 NuGet 而不将包提交到源代码管理
http://docs.nuget.org/docs/workflows/using -nuget-without-committing-packages
AS of 09/20/13, there is something called "Nuget Restore". You actually don't have to check in package folder if you wish to do so. (Especially if you are using DVCS)
Check out this: Using NuGet Without commiting packages to source control
http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages
这篇文章已经变得非常过时了。答案仍然是否定的,但解决方案已经改变。
从 NuGet 2.7+ 开始,您可以启用自动包还原,而无需在源中包含 NuGet.exe 文件(至少可以说这是不可取的),并且如果您使用任何现代 DVCS,则可以忽略包文件夹。如果需要任何特殊的自定义,可以在解决方案根目录中创建 nuget.config 文件。
http://docs.nuget.org/docs/reference/package-restore
此外,使用新的 csproj 格式,您还可以避免额外的 nuget.config 文件,因为它现在已集成。请查看这篇文章,它更好地解释了这一点:
应该 。 nuget文件夹是否添加到版本控制中?
This post has become very outdated. The answer is still NO, but the solution has changed.
As of NuGet 2.7+ you can enable automatic package restore without including the NuGet.exe file in your source (this is undesirable to say the least) and if you use any modern DVCS you can ignore the packages folder. If you need any special customizations you can create a nuget.config file in the solution root.
http://docs.nuget.org/docs/reference/package-restore
Also, with the new csproj format you can avoid the extra nuget.config files as well since that is integrated now. Please check out this post which explains that better:
Should .nuget folder be added to version control?