使用 NuGet 和源代码控制的多人团队

发布于 2024-11-29 01:47:41 字数 773 浏览 2 评论 0原文

我在一个两人团队中,使用 Team Foundation Server 进行源代码控制。我开始了一个新的解决方案。对于该解决方案,我创建了几个项目。在其中许多中,我使用 NuGet 来安装 AutoMapper 和 Unity。然后,我右键单击该解决方案并选择“添加到源代码管理”。然后我检查了所产生的待处理更改。

我团队中的另一个人做了最新的获取,但所有 NuGet 参考资料对他来说都失败了。

因此,我认为我需要添加packages 文件夹。所以我就这么做了。

在我这样做之后,NuGet 引用仍然失败(对他来说)。

另外,当我尝试将 NuGet 包添加到文件中时,我现在收到此错误:

访问路径“C:\src\MyPath\ToMySolution\packages\repositories.config”被拒绝。

我认为这是因为 repositories.config 文件现在处于源代码控制之下(因此在手动签出之前它是只读的)。

所以,这是我的两个问题:

  1. 我该如何签入或签入什么,以便当我的同事获取最新版本时 NuGet 包对他有效?
  2. 有没有办法在我需要使用 NuGet 时不必手动签出 NuGet 文件?

我这样做错了吗?或者 NuGet 并不真正适合与源代码管理一起使用?

I am on a two-man team using Team Foundation Server for our source control. I started a new solution. For that solution I created several projects. In many of them I used NuGet to install AutoMapper and Unity. I then right clicked on the solution and selected "Add to Source Control". I then checked in the resulting pending changes.

The other person on my team did a get latest and all of the NuGet references are failing for him.

So, I figured I needed to add the packages folder. So I did that.

After I did that, the NuGet references are still failing (for him).

Also, when I try to add a NuGet Package to a file I get this error now:

Access to the path 'C:\src\MyPath\ToMySolution\packages\repositories.config' is denied.

I assume this is because the repositories.config file is now under source control (so it is read only until manually checked out).

So, here are my two questions:

  1. How or what do I check in so that the NuGet packages are valid for my coworker when he does a get latest?
  2. Is there a way to not have to manually check out the NuGet files when I need to use NuGet?

Am I doing this wrong? Or is NuGet not really meant for use with source control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

暮凉 2024-12-06 01:47:41

编辑 2014/03/31:不再需要手动启用基于 MSBuild 的包恢复,另请参阅 http://xavierdecoster.com/migrate-away-from-msbuild-based-nuget-package-restore

编辑于 2012 年 2 月 7 日:这现在是 NuGet vsix 的一项内置功能,称为“启用包还原”。

过时的替代方案

有一个 NuGet 包可以用于此目的,它称为 NuGetPowerTools。它向 Visual Studio 中的 NuGet 包管理器控制台添加了两个新命令,其中 Enable-PackageRestore 是您感兴趣的一个。

它将添加一个 .nuget 文件夹,其中包含 nuget.exe、nuget.settings.targets 和 nuget.targets。
当您运行启用包还原时,它将枚举解决方案中的所有项目,并在项目文件(实际上是 msbuild 文件本身)中添加 import nuget.targets 语句。

每当您构建项目或整个解决方案时,nuget 都会获取该项目/解决方案的所有包,如packages.config 文件中所定义。这发生在预构建步骤中。

因此,简而言之:

  1. 不要签入包
  2. 签入配置文件(repositories.config 和 packages.config 文件)
  3. 使用启用包恢复
  4. 签入 .nuget 文件夹

每当有人获取源代码时,无论是其他开发人员对于团队或构建代理,将指示 msbuild 进程在预构建步骤中获取任何所需的包。

此外,当包未提交到 TFS 源代码管理中时,您不会遇到只读标志问题,或与二进制文件合并冲突。

如果需要,您还可以查看此方法的底层推理 在我的博客上

Edit 2014/03/31: The manual MSBuild-based package restore enablement is no longer needed, see also http://xavierdecoster.com/migrate-away-from-msbuild-based-nuget-package-restore.

Edit 2012/02/07: This is now a built-in feature of the NuGet vsix, called Enable Package Restore.

Obsolete Alternative

There is a NuGet package for that, it's called NuGetPowerTools. It adds two new commands to the NuGet Package Manager Console in Visual Studio, amongst which Enable-PackageRestore is the interesting one for you.

It will add a .nuget folder which contains nuget.exe, nuget.settings.targets and nuget.targets.
When you run enable package restore, it will enumerate all projects in your solution and add an import nuget.targets statement in the project files (which are actually msbuild files themselves).

Whenever you build a project or the entire solution, nuget will fetch all packages for that project/solution, as defined in the packages.config file. This happens in a pre-build step.

So, in short:

  1. do not check-in packages
  2. do check-in the config files (repositories.config and packages.config files)
  3. use Enable Package Restore
  4. check-in the .nuget folder

Whenever someone gets the sources, whether that's another developer in the team or a build agent, the msbuild process will be instructed to fetch any required packages in a pre-build step.

Also, when the packages are not committed into TFS Source Control, you won't hit the read-only flag issues, or merge conflicts with binary files.

If you want, you can also check-out the underlaying reasoning for this approach on my blog.

煮茶煮酒煮时光 2024-12-06 01:47:41

不要签入包文件夹。

将以下预构建事件添加到您的项目中:

$(SolutionDir)build\nuget install $(ProjectDir)packages.config -source \\server\path\NuGetPackages -o $(SolutionDir)packages

如果不使用自定义包,则省略 -source 参数

nuget.exe 已签入 $(SolutionDir)build\nuget

Don't check the packages folder in.

Add the following prebuild event to your project:

$(SolutionDir)build\nuget install $(ProjectDir)packages.config -source \\server\path\NuGetPackages -o $(SolutionDir)packages

Omit -source parameter if not using custom packages.

nuget.exe is checked into $(SolutionDir)build\nuget.

拥醉 2024-12-06 01:47:41

我也有这个问题。我喜欢 NuGet 恢复的想法,但我觉得我不需要它。我希望我的 JR 开发人员能够检查出解决方案并拥有他们需要的一切。

所以我将包文件夹置于源代码管理之下。

在这种情况下启用 NuGet 的解决方案是注意上面的这一点:

“我认为这是因为 repositories.config 文件现在处于源代码控制之下(因此它是只读的,直到手动签出)。”

我打开了 repositories.config 文件并添加了一个空行。然后我添加了我需要的NuGet包。问题解决了。

I have this issue also. I like the idea of NuGet restore, but I don't feel I should need it. I want my JR developers to be able to check out a solution and have everything they need.

So I put my packages folder under source control.

My solution to enabling NuGet in this circumstance was to take note of this from above:

"I assume this is because the repositories.config file is now under source control (so it is read only until manually checked out)."

I opened the repositories.config file and added a blank line. Then I added the NuGet packages I need. Problem solved.

装纯掩盖桑 2024-12-06 01:47:41

我总是只签入 packages.config 文件夹并使用 Rake 开发人员(和构建服务器)可以用来在本地更新包的任务。

该任务如下所示:

def nuget_for_project(project_dir)
  sh "tools\\NuGet.exe " +
    "i Source\\#{project_dir}\\packages.config " +
    "-o Source\\Packages"
end

namespace :nuget do
  desc "nuget for servicebus"
  task "ServiceBus" do
    nuget_for_project "SampleProject.ServiceBus"
  end

  desc "nuget for web"
  task "Web" do
    nuget_for_project "SampleProject.Web"
  end

  desc "nuget for all"
  task "all" => ["nuget:ServiceBus", "nuget:Web"]
end

请注意,上述脚本使用 NuGet.exe 的本地版本,该版本位于签入源代码管理的工具文件夹中。

您可以为 MSBuildNAnt 代替。

我写了一篇更长的博客文章不久前这可能会有所帮助。

I always check in just the packages.config folder and use a Rake task that the developer (and build server) can use to update packages locally.

The task looks like:

def nuget_for_project(project_dir)
  sh "tools\\NuGet.exe " +
    "i Source\\#{project_dir}\\packages.config " +
    "-o Source\\Packages"
end

namespace :nuget do
  desc "nuget for servicebus"
  task "ServiceBus" do
    nuget_for_project "SampleProject.ServiceBus"
  end

  desc "nuget for web"
  task "Web" do
    nuget_for_project "SampleProject.Web"
  end

  desc "nuget for all"
  task "all" => ["nuget:ServiceBus", "nuget:Web"]
end

Note that the above script uses a local version of NuGet.exe that is in a tools folder checked into source control.

You could write this for MSBuild or NAnt instead.

I wrote a longer blog post on this a while back that may be helpful.

与他有关 2024-12-06 01:47:41

以防万一这对任何人都有帮助,我的解决方案非常简单:

  1. 中打开目标文件Notepad++
  2. 在编辑菜单中,一直在底部,单击“清除只读标志”
  3. 保存文件
  4. Profit

这对我来说是一个解决方案,在撰写本文时, 39个项目。

Just in case this helps anyone, my solution to this was very simple:

  1. Opened the target file in Notepad++
  2. In the edit menu, all the way at the bottom, click Clear Read-Only Flag
  3. Save the file
  4. Profit

This works for me on a solution with, at the time of this writing, 39 projects.

爱人如己 2024-12-06 01:47:41

我必须为这篇文章点赞:
http://www.jsinh.in/2013/11/enable -nuget-package-restore/
它准确地描述了要做什么以及为什么要做。

某些系统可能需要对各种包进行版本控制的概念来保​​持构建一致性,但是,如果packages.config 文件受版本控制并且可以下载包,则可以随时进行构建,而无需对实际包内容进行版本控制他们自己。注意:包的构建者可能会在您不知情的情况下将项目添加到旧版本中。

罕见,但有可能。

例如,您的项目中内置了版本 2.0.2 的“abc.package”包。您不对“abc.package”进行版本控制,但对packages.config 进行版本控制。几个月后,您需要向几个月前所做的构建添加错误修复。您可以使这些项目脱离版本控制。 Visual Studio 下载“abc.package”版本 2.0.2,但自上次构建以来,包的开发人员插入或修复了一些代码。此新代码在您的应用程序中的行为可能有所不同。

因此,有充分的理由对包进行版本控制!

I must give a shout-out to this article:
http://www.jsinh.in/2013/11/enable-nuget-package-restore/
It describes exactly what to do and why.

The notion of versioning various packages may be required for some systems to maintain build consistency, however, if the packages.config file is version controlled and the package can be downloaded, then the build can take place at any time without versioning the actual package contents themselves. Caution: The builder of the package, could without your knowledge, add items to an older build.

Rare, but possible.

For example, a package of 'abc.package' at version 2.0.2 is built into your project. You do not version the 'abc.package' but do version the packages.config. A few months later you need to add a bug-fix to the build you made a few months back. You get the items out of version control. Visual Studio downloads version 2.0.2 of 'abc.package', but since your last build, the developer of the package inserted or fixed some code. This new code may behave differently in your application.

So, there are good reasons to version control the packages!

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