将 NuGet 中的包签入版本控制?

发布于 2024-10-17 06:13:37 字数 190 浏览 3 评论 0原文

在 NuGet 之前,签入项目中使用的所有外部 DLL 是普遍接受的“最佳实践”。通常位于 Libs3rdParty 目录中。

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

束缚m 2024-10-24 06:13:38

既然提出了这个问题,现在有一个简单的工作流程可以使用 NuGet,而无需将包提交到源代码控制

从包管理器控制台,您需要安装'NuGetPowerTools'

Install-Package NuGetPowerTools

然后使您的项目能够支持包恢复时,您需要运行另一个命令:

Enable-PackageRestore

现在您已准备好在没有软件包文件夹的情况下提交代码库。上一个命令更改了您的项目文件,以便如果包丢失,它们会自动下载并添加。

来源

使用 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':

Install-Package NuGetPowerTools

Then to enable your projects to support pack restore you need to run another command:

Enable-PackageRestore

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

别理我 2024-10-24 06:13:38

是的。考虑“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.

榆西 2024-10-24 06:13:38

尽管这里有所有答案,但它仍然是一个普通的“可怕的解决方案”,因为没有将所有依赖项置于“某种”版本控制之下。

对于 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.

终难遇 2024-10-24 06:13:38

自从提出这个问题以来,我采用了以下方法,这样我就不必检查 toplovel Packages 目录。

在顶级 build.msbuild 文件中:

<Target Name="NuGet">
    <ItemGroup>
       <NuGetPackage Include="*\packages.config" />
    </ItemGroup>
    <Exec Command='libs\NuGet.exe install "%(NuGetPackage.FullPath)" -o Packages'  />

    <!-- optional for project that has JavaScript content -->
    <CreateItem Include="Packages\*\Content\Scripts\*">
       <Output TaskParameter="Include" ItemName="NuGetJSFiles"/>
    </CreateItem>
    <Copy SourceFiles="@(NuGetJSFiles)" DestinationFolder="MainProj\Scripts\" OverwriteReadOnlyFiles="true" SkipUnchngedFiles="true" />
    <Delete Files="MainProj\Scripts\.gitignore" />
    <WriteLinesToFile File="MainProj\Scripts\.gitignore" Lines="%(NuGetJSFiles.Filename)%(NuGetJSFiles.Extension)" /
    <Delete Files="@(PostNuGetFiles)" />
</Target>

在每个 project.csproj 文件中

<Target Name="BeforeBuild">
    <Error Condition="!Exists('..\Packages\')" Text="You must run > msbuild build.msbuild to download required NuGet
Packages" />

    <!-- optional for project that has JavaScript content -->
   <ReadLinesFromFile File="Scripts\.gitignore">
     <Output TaskParameter="Lines" ItemName="ReqJSFiles" />
   </ReadLinesFromFile>
   <Message Text="@(ReqJSFiles)" />
   <Error Condition="!Exists('Scripts\%(ReqJSFiles.Identity)')" Text="You must run > msbuild build.msbuild to download required NuGet JS Package - Scripts\%(ReqJSFiles.Identity)" />
 </Target>

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:

<Target Name="NuGet">
    <ItemGroup>
       <NuGetPackage Include="*\packages.config" />
    </ItemGroup>
    <Exec Command='libs\NuGet.exe install "%(NuGetPackage.FullPath)" -o Packages'  />

    <!-- optional for project that has JavaScript content -->
    <CreateItem Include="Packages\*\Content\Scripts\*">
       <Output TaskParameter="Include" ItemName="NuGetJSFiles"/>
    </CreateItem>
    <Copy SourceFiles="@(NuGetJSFiles)" DestinationFolder="MainProj\Scripts\" OverwriteReadOnlyFiles="true" SkipUnchngedFiles="true" />
    <Delete Files="MainProj\Scripts\.gitignore" />
    <WriteLinesToFile File="MainProj\Scripts\.gitignore" Lines="%(NuGetJSFiles.Filename)%(NuGetJSFiles.Extension)" /
    <Delete Files="@(PostNuGetFiles)" />
</Target>

In each project.csproj file

<Target Name="BeforeBuild">
    <Error Condition="!Exists('..\Packages\')" Text="You must run > msbuild build.msbuild to download required NuGet
Packages" />

    <!-- optional for project that has JavaScript content -->
   <ReadLinesFromFile File="Scripts\.gitignore">
     <Output TaskParameter="Lines" ItemName="ReqJSFiles" />
   </ReadLinesFromFile>
   <Message Text="@(ReqJSFiles)" />
   <Error Condition="!Exists('Scripts\%(ReqJSFiles.Identity)')" Text="You must run > msbuild build.msbuild to download required NuGet JS Package - Scripts\%(ReqJSFiles.Identity)" />
 </Target>
孤者何惧 2024-10-24 06:13:38

我意识到这个问题最初发布并回答时现实情况有所不同,但幸运的是答案发生了一些变化。现在可以使用 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

孤独岁月 2024-10-24 06:13:38

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

素染倾城色 2024-10-24 06:13:38

这篇文章已经变得非常过时了。答案仍然是否定的,但解决方案已经改变。
从 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文