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 (41) -

  • Jeff

    3/15/2016 8:30:21 PM | Reply

    Thank you! Your post here helped me after about a week of testing and searching for the correct way to build multiple configurations.

  • DeV1L

    7/11/2016 9:55:34 AM | Reply

    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.

  • DeV1L

    7/11/2016 1:22:52 PM | Reply

    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.

    • Donovan

      8/28/2016 8:39:58 PM | Reply

      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.  

  • Keith Lemon

    1/12/2017 4:23:38 PM | Reply

    Great stuff!

  • Simon M

    1/23/2017 9:14:17 PM | Reply

    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?

    • Donovan

      1/23/2017 9:59:59 PM | Reply

      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.

      • Rohit

        7/6/2017 11:33:42 AM | Reply

        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.

        • Donovan

          7/6/2017 8:32:50 PM | Reply

          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.

          • Rohit

            7/7/2017 10:22:11 AM | Reply

            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.?

            • Donovan

              7/7/2017 11:34:29 AM | Reply

              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.

  • Soniya

    5/30/2017 6:37:31 AM | Reply

    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?

    • Donovan

      5/30/2017 12:12:47 PM | Reply

      I would like to better understand why you are not deploying the same bits in each environment. What is different in each config?

      • Soniya

        5/30/2017 12:41:07 PM | Reply

        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.

        • Donovan

          5/30/2017 4:14:23 PM | Reply

          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.

          • Soniya

            7/6/2017 6:44:21 AM | Reply

            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?

          • Jeeva

            7/6/2017 5:18:14 PM | Reply

            Hi Donovan, Does this extension work with Xamarin apps?

          • RenĂ©

            4/27/2018 8:10:24 AM | Reply

            Hi Donovan,

            our project consists of multiple release environments and therefor is using multiple configurations:
            "Web.config" (unoptimized builds, full debug info)
            "Web.Release (Test).config" (optimized builds, full debug info)
            "Web.Release (Production).config" (optimized builds, pdb-only debug info)

            According to your comment about DevOps best practices, we should build a single artifact and configure it later on in Release Management.

            Now the question is: How can we have TFS produce the environment specific DLLs and PDBs with full or minimal debug information when building once?

            On another note, how would we be able to differentiate between those builds?

            Please guide us.

            Thank you,
            René

  • Jeeva

    7/6/2017 5:41:54 PM | Reply

    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

    • Donovan

      7/6/2017 8:29:47 PM | Reply

      All the tasks get run for each configuration. What you might try is repeating that task with different values and use conditions for each task based on configuration. www.visualstudio.com/.../conditions

  • Jeeva

    7/19/2017 12:10:46 PM | Reply

    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?

  • Drake

    7/21/2017 7:06:55 AM | Reply

    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

  • Alok Srivastava

    11/29/2017 8:06:11 AM | Reply

    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?

    • Donovan

      12/3/2017 1:55:39 PM | Reply

      Make sure if you are publishing twice that the names are different. Maybe www_debug and www_release.

  • Jeremy Jameson

    12/17/2017 12:11:53 PM | Reply

    Hey Donovan, thanks for the blog post. It got me pointed in the right direction. However, it is apparently out-of-date due to some changes in VSTS.

    Would you please make a note in the post that "Multi-configuration" is now configured on the "Run on agent" task (in the "Execution plan" section)?

    The following Stack Overflow answer revealed the new location for this option:

    https://stackoverflow.com/a/46420172

    Thanks!

  • Tom Murnane

    1/10/2018 4:11:00 PM | Reply

    Hi Donovan, thanks for your work on this.

    So, I'm moving from a 2012 Build def to new web build def. How would I implement the following multi configurations, cut and pasted from my current build def:

    WhateverApps|Debug,WhateverApps|Release,WhateverApps64|Release,WhateverAppsCloud|Release

    or

    Configuration | Platform

    Debug | WhateverApps
    Release | WhateverApps
    Release | WhateverApps64
    Release | WhateverAppsCloud

    This is easily set up using the UI in my current process. As you can see we only build the Debug of WhateverApps and the release of the rest. Actually - now that I am through writing this - I guess I can create 2 Visual Build steps, 1 for the debug |Relase of whateverApps and one for the release of everything else. Is that be the correct way to do this? Thanks.

  • Charly

    3/22/2018 4:20:01 AM | Reply

    Hi Donovan,
    In the solution there are projects with Build Platform = Any CPU and x86. (Mixed Platforms).
    It builds fine in Visual studio. but in vsts, when Build Platform is set to any cpu, x86 projects are not built and caused
    error in building other projects depending on x86 projects.

  • Anindita

    7/2/2018 2:23:44 PM | Reply

    Hi Donovan,

    I am using VSTS for building .sln files, but whenever I am trying to build only in Release Mode , it gets triggered in both Debug and Release Mode. Can you tell me as to where am I possibly going wrong.
    And the second issue is the Quality Gates shows timeout error, thus unable to generate Code Analysis Report .how am I suppose to fix it .

    • Donovan

      7/10/2018 3:42:46 PM | Reply

      I would review your configuration settings from within Visual Studio. Make sure the config names are what you are expecting. Then check your build configuration in VSTS to make sure the build configuration is being set correctly.  Finally I would check the task to build the .sln and make sure it is being passed the build configuration variable.

      • Anindita

        7/11/2018 7:15:30 AM | Reply

        Thank you.
        What about the Quality gates extension,they are showing successfull  but no code coverage results as they are timed out

  • mohit

    9/11/2018 3:11:55 PM | Reply

    Hi Donovan,
    Is there any way to have a custom build run on VSTS? I've tried many configuration but none have succeeded. What I mean is, in the Visual Studio, you can create a new build configuration from the drop-down menu, by default there's "debug", and "release". But let's say I want to create a build configuration where I want to skip building one of the projects, so going in the dropdown I can create a new build configuration, "my-build", and in that one, uncheck the project that I don't want to be build in this configuration. But how I can achieve this in VSTS? I tried to go to variable tab, and set the "BuildConfiguration" variable to "my-build", but of course, when I queued the build it came up with (expected) error saying invalid build configuration, "my-build|any cpu" is invalid, which makes perfect sense as the VSTS agent doesn't know about this custom build configuration that I've created in my visual studio. So is there a way to get this done on VSTS?

  • Piyush

    1/7/2019 1:52:19 PM | Reply

    Hi Donovan,
    I am DevOps and need to speed-up build and release process. I am not sure if multi-configuration might help, hence thinking to use multi-agent. As per my understanding, when I use multi-agent the different tasks under a phase will run in parallel on different agent. We don't use MS hosted agent, we have agent on our VM. Is there a good example of using multi-agent?
    Also apart from phase settings, I also see organization settings for "retention and parallel jobs". What is the difference?
    Thanks, Piyush

    • Donovan

      1/7/2019 4:57:48 PM | Reply

      Tasks do not run in parallel phases do. So group tasks in phases then you can run the phases in parallel. You just need enough agents in your pool. I forget the pricing model for parallel jobs.

  • Janos

    1/8/2019 12:15:09 PM | Reply

    If I have a multipler variable named : MyVariable = a,b;

    Can I get the value of MyVariable, the actual value. I mean I want to skip a job if the value is a, and another one if the value is b.

    • Donovan

      1/8/2019 12:48:14 PM | Reply

      It is just a variable access it like you would any other $(MyVariable)

  • Venky Venkataraman

    3/27/2019 5:09:09 PM | Reply

    Donovan, At the time when we had traditional .NET framework projects, with multiple configuration option super useful. This was one of the best things I came across and it helped us a lot.

    Am I right to say, with .NET core, we don't have traditional multi configuration web.config transformation. Does this still apply to .NET core projects or we have to something different for dotnet build -c $(buildconfiguration)?

    Am I making sense?

    Thanks,
    Venky

    • Donovan

      3/27/2019 8:57:08 PM | Reply

      No matter the language configuration has to be managed as your code moves through different environments. For example the connection strings used in Dev, QA, and Prod still need to be changed. You may still want to build both debug and release builds for debugging purposes. .NET core gives you more options but the requirements still remain.

  • Imran Hamid

    5/29/2019 5:05:52 PM | Reply

    Hi Donovan,
    I'm using multiconfiguration and I can see it's building the DEV.UAT and LIVE. Somehow it only retains the last build in my case LIVE and tries to transform config using the LIVE configuration.

    Is defining this parameter : "$(build.artifactstagingdirectory)\\$(BuildConfiguration)\\"  in the argument is the right solution of it so it retains all the artefacts? With then you have to change the release environment with something like this : $(System.DefaultWorkingDirectory)\**\DEV\*.zip

    Is there a solution to have one artefact and transform it accordingly? currently it's transforming from the last build artefact.

    Any help is greatly appreciated.

    • Donovan

      6/1/2019 1:40:28 PM | Reply

      Not sure I follow what you mean by only retains one?  Are you trying to publish both as a build artifact and only one is showing up?  If so make sure both are being copied to the staging folder before you call the publish artifact task.  If you can provide a bit more info it might help.

  • David V. Corbin

    10/15/2020 7:15:15 PM | Reply

    Years later... Is there the ability to accomplish this in the latest YAML build definitions???

Add comment

Loading