How to build multiple configurations in a single VSTS build

Problem:

When I try to build debug and release at the same time I get the following error:

The specified solution configuration "release, debug|any cpu" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration.

Solution:

Enable the Multi-configuration option.

image

Explanation:

By default the Multi-configuration option is disabled. To build multiple configurations at once, you actually have to do more than just check the box. First you need to update the BuildConfiguration variable to a comma-delimited string of configurations.

  1. Select the build
  2. Click the Edit link
  3. Click the Variables tab
    Field Value
    BuildConfiguration release,debug

    image

With the build configuration updated, you can now enable the Multi-configuration option.

  1. Click the Options tab
  2. Check the Multi-configuration checkbox
    Field Value
    Multipliers BuildConfiguration
  3. Click Save

Now when you queue a new build, both configurations will build.

image

Comments (24) -

  • Thank you! Your post here helped me after about a week of testing and searching for the correct way to build multiple configurations.
  • Donovan, is it possible to build multiple configurations in a single queue?
    For now another builds wedged between each configuration and Multi-configuration build takes a long time.
  • Hello, Donovan!
    Is it possible to make Multi-configuration build in a single queue?
    For now another builds wedged between building each configuration and Multi-configuration build takes a long time.
    • If you only have a single agent in your queue each build will happen one after the other.  If your builds to happen at the same time you must have multiple agents in your queue.  
  • Quick question. If I have a release and debug version of a website, how do you stop it from building into the same zip, etc?
    • Change MSBuild Arguments from:
      /peployOnBuild=true /p:WebPublishMethod=Package /packageAsSingleFile=true /p:SkipInvalidConfigurations=true /packageLocation="$(build.artifactstagingdirectory)\\"

      To
      /peployOnBuild=true /p:WebPublishMethod=Package /packageAsSingleFile=true /p:SkipInvalidConfigurations=true /packageLocation="$(build.artifactstagingdirectory)\\$(BuildConfiguration)\\"

      By adding $(BuildConfiguration) each config will get a different zip.
      • Objective: I want to  have a single Build only, and to release it to different environment by changing the web.config using tokenizer..!!!
        Im struck at a point where I get a build package as zip folder inside which I have only single web.config file. how to proceed after this.
        • You have a couple options. One use an extension to unzip the file. Change the web.config and re-zip the file. Option two is don't zip in your build and publish the unzipped site as an artifact to release. That way when release downloads the artifact the web.config is there to be transformed. Then in release you zip the files and deploy.
          • Donovan, can you provide me any source which can help me to achieve my Objective? i Want to use tokenizer but it is expecting json. Any source where i get any help regarding the same.?
            • Which tokenizer task are you using? I use the one from Colin and it is not based on json. Just vars in the build or release.
  • Hey Donovan,

    Can CD release definitions with Multi-configuration builds?
    I have configured this multi-configuration build + CD Release definition for some 4-5 configurations in my current project. However the challenge that I have is if for eg. my environments are dev, bvt, st, sit in the same order in same build and release definition to deploy one after other, and If I need to build only DEV and ST, then the Release will get created and deployed on DEV alright. But after deploying on dev it will look for BVT artifact which it won't find so it will fail the release deployment on BVT and it won't go further and deploy on ST.
    Do you have any ideas for this that the release should somehow figure out that the the artifact is available for specific configurations and should deploy only to those environments?
    • I would like to better understand why you are not deploying the same bits in each environment. What is different in each config?
      • That is because each environment configuration file has urls etc for that specific environment in Azure. Our environment corresponds to a Resource group in Azure.
        • I would recommend you use tokenization to config changes between environments. That way you deploy the exact build in every environment and have release management update the configuration values as part of the release. This extension has the tasks you need marketplace.visualstudio.com/items
          This will help you adhere to DevOps best practices. You want to deploy the same build in every environment and not a build per environment.
          • Hi Donovan,

            We have tried that for webapp deployment. But it doesnot work for Service Fabric API deployment and also for SSDT post deployment scripts Frown
            Also is there any way to deploy configuration seperately after the main code is deployed for service fabric, webapp?
          • Hi Donovan, Does this extension work with Xamarin apps?
  • Hi Donovan,
    I have a Powershell script / Shell script task to update a app secret to a configuration. But when using Multi-Configuration, Is there a way to rerun the script as a pre-condition to the next configuration. Any suggestion how to handle this use case.

    We would like to make use of Multi-Configuration feature but at the same time need to update the Mobile Center app secrets for different build configuration.

    TFS version: TFS 2015 On-Premise hosted.
    Type of app: Xamarin native apps.

    Thanks
  • Hi Donovan,

    We have a case where the BuildConfiguration is used in one of the bash shell script to update the app secrets for the active build config. But when using the Multi Configuration option the BuildConfiguration parameter holds comma separated config names. Is there pre defined build variable to get hold of the configuration used to build from the shell script?

  • Hi Donovan,

    I'm very new to TFS.
    I'm trying to build and package multi targeted Framework nuget packages (netstandard1.6,net462) .
    Is that also possible with the Multi-configuration option?
    Any recommendations?

    Drake
  • Hi Donovan,
    Thanks for this information, i have updated my build definition to support multiple configuration. everything is now working fine but i am getting "Artifact WWW already exists for build 5150.error ", in my build definition i have one artifact to publish the code, for release version it is working fine but for debug it is giving error "Artifact WWW already exists for build 5150."
    Any recommendations?
    • Make sure if you are publishing twice that the names are different. Maybe www_debug and www_release.

Add comment

Loading