让 TFS 将每个项目输出到自己的目录的最佳方法是什么? [英] What's the best way to get TFS to output each project to its own directory?

查看:14
本文介绍了让 TFS 将每个项目输出到自己的目录的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将大型代码库放入 Team Foundation Server.我希望构建过程能够为我们的项目创建一个准备部署"的构建版本.

I'm putting a large codebase into Team Foundation Server. I would like the build process to create a "ready to deploy" build of our projects.

我们一直在这样做的正常方法是将每个项目的输出放在自己的文件夹中.因此,例如,我们最终会得到类似

The normal way we've been doing this is to have each project's output be in its own folder. So, for example, we wind up with something like

C:project1
            assembly1.dll
            assembly2.dll
            project1.exe
            project1.exe.config
C:project2
            assembly2.dll
            assembly3.dll
            project2.exe
            project2.exe.config
C:project3
            assembly1.dll
            assembly3.dll
            project3.exe
            project3.exe.config

这是我们喜欢的方式.

不过,TFS 似乎想把所有东西都放在同一个目录中.

TFS, though, seems to want to stick everything in the same directory.

C:output
          assembly1.dll
          assembly2.dll
          assembly3.dll
          project1.exe
          project1.exe.config
          project2.exe
          project2.exe.config
          project3.exe
          project3.exe.config

虽然它节省了一些磁盘空间(每个程序集只有一次),但这并不是我们想要的.

which, although it saves some amount of disk space (the assemblies are only there one time each) is not how we want it.

指定 TFS/MSBuild 应将输出文件放在哪里的最佳方法是什么?我是否需要单独编辑 sln/csproj 文件来实现这一点,还是可以在 TFSBuild.proj 文件中进行?(即,在特定于 MSBuild 的文件中)

What's the best way to specify where TFS/MSBuild should put the output files? Do I need to edit sln/csproj files individually to achieve this or can I do it in the TFSBuild.proj file? (i.e., in a MSBuild-specific file)

推荐答案

我刚刚在这里写了另一种方法:

I just blogged another method here:

http://mikehadlow.blogspot.com/2009/06/tfs-build-publishedwebsites-for-exe-and.html但如果你懒得点击链接,这里是完整的:

http://mikehadlow.blogspot.com/2009/06/tfs-build-publishedwebsites-for-exe-and.html but if you can't be bothered to follow the link, here it is in full:

如本模式和实践 PDF 团队开发 TFS 指南中所述,将团队控制下的所有代码收集到一个单一的超级解决方案中通常是一种很好的做法.如果您随后配置 TFS 构建服务器来构建此解决方案,则默认行为是将构建输出放入单个文件夹Release"中.

It’s generally good practice to collect all the code under your team’s control in a single uber-solution as described in this Patterns and Practices PDF, Team Development with TFS Guide. If you then configure the TFS build server to build this solution, it’s default behaviour is to place the build output into a single folder, ‘Release’.

解决方案中的任何 Web 应用程序项目也将输出到名为 _PublishedWebsites 的文件夹中.这非常好,因为这意味着您可以简单地通过 robocopy 部署 Web 应用程序.

Any web application projects in your solution will also be output to a folder called _PublishedWebsites. This is very nice because it means that you can simply robocopy deploy the web application.

不幸的是,其他项目类型(如 WinForms、控制台或库)没有类似的默认行为.如果我们可以有一个 _PublishedApplications 子文件夹,其中包含任何选定项目的输出,那就太好了.幸运的是,这并不难.

Unfortunately there’s no similar default behaviour for other project types such as WinForms, console or library. It would be very nice if we could have a _PublishedApplications sub folder with the output of any selected project(s). Fortunately it’s not that hard to do.

_PublishedWebsites 的工作方式非常简单.如果您查看 Web 应用程序的项目文件,您会注意到底部附近有一个导入:

The way _PublishedWebsites works is pretty simple. If you look at the project file of your web application you’ll notice an import near the bottom:

<Import Project="$(MSBuildExtensionsPath)MicrosoftVisualStudiov9.0WebApplicationsMicrosoft.WebApplication.targets" />

在我的机器上,MSBuildExtensionsPath 属性评估为 C:Program FilesMSBuild,如果我们打开 Microsoft.WebApplication.targets 文件,我们可以看到它是一个非常简单的 MSBuild 文件,可以识别构建何时不是桌面构建,即它是一个 TFS 构建,并将输出复制到:

On my machine the MSBuildExtensionsPath property evaluates to C:Program FilesMSBuild, if we open the Microsoft.WebApplication.targets file we can see that it’s a pretty simple MSBuild file that recognises when the build is not a desktop build, i.e. it’s a TFS build, and copies the output to:

$(OutDir)_PublishedWebsites$(MSBuildProjectName)

我只是简单地复制了 Micrsoft.WebApplication.targets 文件,将它置于源代码管理之下,并使用我的项目文件的相对路径,并将 _PublishedWebsites 更改为 _PublishedApplications 并将文件重命名为 CI.exe.targets.对于我想输出到 _PublishedApplications 的每个项目,我只是在项目文件的底部添加了这个导入:

I simply copied the Micrsoft.WebApplication.targets file, put it under source control with a relative path from my project files and changed _PublishedWebsites to _PublishedApplications and renamed the file CI.exe.targets. For each project that I want to output to _PublishedApplications, I simply added this import at the bottom of the project file:

<Import Project="<your relative path>CI.exe.targets" />

您可以编辑 CI.exe.targets(或任何您想称呼的名称)来进行出价.就我而言,到目前为止唯一的更改是添加几行来复制 App.config 文件:

You can edit CI.exe.targets (or whatever you want to call it) to do your bidding. In my case, the only change so far is to add a couple of lines to copy the App.config file:

<Copy SourceFiles="$(OutDir)$(TargetFileName).config" DestinationFolder="$(WebProjectOutputDir)in" SkipUnchangedFiles="true" />

Microsoft.WebApplication.targets 中有很多内容仅与 Web 应用程序相关,可以为其他项目类型剥离,但我将其留给读者作为练习.

There’s a lot of stuff in Microsoft.WebApplication.targets that’s only relevant to web applications and can be stripped out for other project types, but I’ll leave that as an exercise for the reader.

这篇关于让 TFS 将每个项目输出到自己的目录的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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