Is there a way to create more than one deployment with msbuild on a single build?

为君一笑 提交于 2019-12-23 03:55:13

问题


I am using msbuild command line multiple times to create a deployment zip file for my dev / test / production websites. I have already configured the parameters and configuration xml for each one. I want to know if i can condense my 3 calls to msbuild down to one, and have it build all three at once?

right now i have to run

msbuild.exe myproject.sln /T:Build /p:DeployOnBuild=True /p:PublishProfile="Dev Server"
msbuild.exe myproject.sln /T:Build /p:DeployOnBuild=True /p:PublishProfile="Prod Server"

etc

The continuous deployment solution i'm using (bamboo) is struggling with this multiple call to msbuild for some reason (i have an open ticket and they are perplexed as well). I'm trying to simplify things.


回答1:


I have a template for building out all skus of the same solution in parallel.

This is the same concept as Stijn's approach that uses an ItemGroup as a project definition rather than a series of options for a particular property + the msbuild task will build both at the same time, saving you time and bubbling up any configuration issues when building in parallel.

<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <SolutionToBuild Include="$(MSBuildThisFileDirectory)\MyProject.sln">
        <Properties>DeployOnBuild=True;PublishProfile="Dev Server"</Properties>
    </SolutionToBuild>
    <SolutionToBuild Include="$(MSBuildThisFileDirectory)\MyProject.sln">
        <Properties>DeployOnBuild=True;PublishProfile="Prod Server"</Properties>
    </SolutionToBuild>
  </ItemGroup>
  <Target Name="Build">
    <MsBuild BuildInParallel="true" ContinueOnError="true" Projects="@(SolutionToBuild)" />
  </Target>
  <Target Name="Clean">
    <MsBuild BuildInParallel="true" ContinueOnError="true" Projects="@(SolutionToBuild)" Targets="Clean" />
  </Target>
</Project>



回答2:


You can only invoke multiple different targets on the commandline, but you can't supply multiple different values for properties. At least not in a way that I'm aware off. The workaround however is simple, easier to extend than a commandline, and the typical msbuild way of doing things: create a master build file like below and call it from Bamboo instead of the solution.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
         DefaultTargets=Build>
  <Target Name="Build">
    <ItemGroup>
      <PublishProfiles Include="Dev Server"/>
      <PublishProfiles Include="Prod Server"/>
    </ItemGroup>
    <MsBuild Projects="myproject.sln" Targets="Build" 
             Properties="DeployOnBuild=True;PublishProfile=%(PublishProfile.Identity)"/>
  </Target>
</Project>

(this will invoke MsBuild myproject.sln once for each item in the PublishProfiles list with the properties as shown)



来源:https://stackoverflow.com/questions/21434142/is-there-a-way-to-create-more-than-one-deployment-with-msbuild-on-a-single-build

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!