如何仅在构建计算机上执行 MSBuild 复制操作?
我想
- 在执行构建之后和
- 运行集成测试之前在构建计算机上(但不在开发人员计算机上)执行一些复制操作。
我该怎么做?
也许,我应该将问题分成子问题并举一些例子。
问题 1:我需要做什么才能让 MSBuild 脚本检测到它正在构建计算机上执行并因此执行复制操作?我是否需要修改 *.csproj 文件?我需要在构建定义文件中执行某些操作吗?构建服务器是我们的 TFS 2010 后端的一部分。
问题 2:我需要使用什么变量来引用构建计算机上的构建文件夹?绝对路径是
C:\Builds\1\ProjectX\Continous Integration\
我需要将一些受版本控制并最终位于 Sources 文件夹中的文件复制到 Binaries 文件夹中。
C:\Builds\1\ProjectX\Continous Integration\Binaries
C:\Builds\1\ProjectX\Continous Integration\Sources
C:\Builds\1\ProjectX\Continous Integration\TestResults
I want to perform some copy actions on the build machine (but not on the developer machines)
- after a build is performed and
- before the integration tests run.
How do I do that?
Perhaps, I should split the question up into sub-questions and give some examples.
Question 1: What do I need to do so that the MSBuild script detects that it is being executed on the build machine and therefore does a copy operation? Do I adapt the *.csproj file? Do I do something within the Build Definition file? The build server is part of our TFS 2010 backend.
Question 2: What variable do I need to use to reference the build folder on the build machine? The absolute path is
C:\Builds\1\ProjectX\Continous Integration\
I need to copy some files which are under version control and end up in the Sources folder to the Binaries folder.
C:\Builds\1\ProjectX\Continous Integration\Binaries
C:\Builds\1\ProjectX\Continous Integration\Sources
C:\Builds\1\ProjectX\Continous Integration\TestResults
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
无论您使用什么自动化构建,都应该能够将属性传递给 MSBuild。在命令行上,您可以执行以下操作:
在脚本中,您可以使用基于
$(RunningOnBuildMachine) == 'true'
的条件来触发临时步骤。或者,已经有一个内置变量 $(BuildingInsideVisualStudio) 告诉 MSBuild 是否从 VS 内调用它,这可能足以满足您的需求。至于输出目录在哪里,这有点棘手。是什么决定了这个位置?是 CI 服务器吗?如果是这样,您可以尝试将输出目录作为属性传递给脚本。
Whatever you are automating the build with ought to be able to pass a property through to MSBuild. On the command line you do something like:
In your script you can then use a condition based on
$(RunningOnBuildMachine) == 'true'
to trigger the interim step. Alternatively there is already an inbuilt variable $(BuildingInsideVisualStudio) which tells MSBuild whether it's being called from within VS or not which may be sufficient for your needs.As to where your output directory is, that's a bit trickier. What determines that location? Is it the CI server? If so you could try getting that to pass the output directory as a property to the script as well.
如果您使用的是使用 Windows Workflow Foundation 的默认生成过程模板 (DefaultTemplate.xaml),而不是使用 MSBuild 的升级模板,那么您可以使用开箱即用的 CopyDirectory 工作流活动,并将其放在编译部分之间以及工作流程的测试部分。
您在 TFS 2010 中使用哪个构建过程模板?
If you are using the default build process template (DefaultTemplate.xaml) that is using Windows Workflow Foundation instead of the Upgrade Template that uses MSBuild then you can use a CopyDirectory workflow activity that is included out of the box and put it between the compilation section and the testing section of the workflow.
Which build process template are you using in TFS 2010?
构建文件夹:
您是否尝试过 MSBuild 保留属性
MSBuildProjectDirectory
?您可以按照与其他属性相同的方式访问它,例如
$(MSBuildProjectDirectory)\Binaries
。或者你还有别的意思吗?Build folder:
Have you tried MSBuild reserved property
MSBuildProjectDirectory
?You can acces it in the same manner as other properties, e.g.
$(MSBuildProjectDirectory)\Binaries
. Or did you mean something else?如果您对工作流程感到满意,您可以操纵现有的工作流程来执行 Ed 已经指定的操作。
如果您希望它成为构建过程的一部分,以便您可以准备一个最终可以与 msdeploy 一起使用的包,您可以将其放入 msbuild 脚本中。
1)假设您有一个Web项目文件要构建,您可以创建与项目文件同名的msbuild脚本,扩展名为wpp.targets;它将被构建过程拾取,例如,如果您的项目名为 mywebproject.csprj,则新脚本将被称为 mywebproject.wpp.targets。在那里,您可以将目标放在特定的构建目标之后运行。关于房产,你有很多选择。保罗的例子很好。我通常定义一个默认的空属性,并使用构建参数覆盖该属性,或者修改工作流程以覆盖该属性。在使用 Visual Studio 进行常规构建时,我的参数将为空,我可以将其用作某些目标的条件。
2) 当我想将其他文件包含到 msdeploy 包中时,我经常使用 $(ProjectDir) 和 $(_PackageTempDir)。 $(ProjectDir) 也适合您。它指向构建服务器上项目文件所在的文件夹。
我希望这有帮助。
If you feel comfortable with Workflows you can manipulate the existing one to do that as Ed already specified.
If you want that to be part of your build process, so that you can prepare a package which you can use eventually with msdeploy you can put in your msbuild script.
1) Assuming that you have a web project file to build, you can create msbuild script with the same name as the project file with extension wpp.targets; it will get picked up by the build process, e.g. if you project is called mywebproject.csprj, the new script will be called mywebproject.wpp.targets. There you can put your targets to run after specific build in targets. About the property, you have lots of options. Paolo example is good. I normally define a default empty property which I override with the build parameters, or modify the workflow to override that property. In regular build with visual studio my parameter will be empty and I can use that as a condition of some of my targets.
2) I use a lot $(ProjectDir) and $(_PackageTempDir), when I want to include additional files to the msdeploy package. $(ProjectDir) will work for you as well. It is pointing to the folder where your project file on the build server is.
I hope that helps.