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

查看:70
本文介绍了使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构建服务器配置为构建此解决方案,则默认行为是将构建输出放置到单个文件夹发布"中.

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的工作方式非常简单.如果您查看网络应用程序的项目文件,则会在底部附近看到一个导入:

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)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />

在我的计算机上,MSBuildExtensionsPath属性的评估结果为C:\ Program Files \ MSBuild,如果我们打开Microsoft.WebApplication.targets文件,我们会发现它是一个非常简单的MSBuild文件,可以识别该版本不是桌面版本,也就是说,这是一个TFS构建,并将输出复制到:

On my machine the MSBuildExtensionsPath property evaluates to C:\Program Files\MSBuild, 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)\bin" SkipUnchangedFiles="true" />

Microsoft.WebApplication.target中有很多东西仅与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天全站免登陆