多人团队使用NuGet和源代码控制 [英] Multiperson team using NuGet and source control

查看:120
本文介绍了多人团队使用NuGet和源代码控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个两人小组,使用 Team Foundation Server 作为我们的源代码控制.我开始了一个新的解决方案.对于该解决方案,我创建了几个项目.在许多应用程序中,我使用NuGet来安装AutoMapper和Unity.然后,我右键单击该解决方案,然后选择添加到源代码管理".然后,我检查了产生的未决更改.

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.

我们团队中的另一个人做了最新的事情,所有NuGet参考文献都因为他而失败.

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

因此,我认为我需要添加 packages文件夹.所以我做到了.

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

这样做之后,NuGet引用仍然失败(对他而言).

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

此外,当我尝试将NuGet程序包添加到文件时,现在出现此错误:

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

拒绝访问路径"C:\ src \ MyPath \ ToMySolution \ packages \ repositories.config".

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

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

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. 我该如何或通过什么方式进行检查,以使NuGet软件包在我的同事获得最新信息时才有效?
  2. 当我需要使用NuGet时,是否有一种方法不必手动检出NuGet文件?

我做错了吗?还是NuGet并非真的适合与源代码管理一起使用?

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

推荐答案

编辑2014/03/31:不再需要基于MSBuild的手动软件包还原支持,另请参见

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.

编辑2012/02/07:这是NuGet vsix的内置功能,称为启用程序包还原".

过时的选择

有一个用于此的NuGet程序包,称为NuGetPowerTools.它将两个新命令添加到Visual Studio的NuGet程序包管理器控制台中,其中Enable-PackageRestore是您感兴趣的命令.

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.

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

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).

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

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.

所以,简而言之:

  1. 不签入包裹
  2. 签入配置文件(repositories.config和packages.config文件)
  3. 使用启用程序包还原
  4. 签入.nuget文件夹

只要有人获得了源代码,无论是团队中的另一位开发人员还是构建代理,都将指示msbuild流程在预构建步骤中获取所有必需的软件包.

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.

此外,当程序包未提交到TFS Source Control中时,您不会遇到只读标志问题,也不会与二进制文件合并冲突.

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.

这篇关于多人团队使用NuGet和源代码控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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