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

StackOverflow https://stackoverflow.com/questions/21434142

  •  04-10-2022
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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>

نصائح أخرى

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)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top