Azure DevOps XML Transformation During Release Not Working

前端 未结 4 674
北荒
北荒 2020-12-17 01:29

I want to configure our pipeline to allow one build to be used for multiple environments without having to create separate builds. According to the docs, it seems like it is

相关标签:
4条回答
  • 2020-12-17 02:13

    None of the answers I found on the internet worked for me on their own for my build and release pipeline. The web.config I got from the release pipeline was always pointing to the non transformed values.

    After a few hours pulling my hair I got it to work though.

    Some short info about my setup

    I want to be able to deploy on all environments with just one build and one release pipeline.

    My setup:

    • One build pipeline that builds all of our standard branches (test, release, master).
    • One release pipeline that has different stages depending on branch that started the release.

    Our test stage releases the test branch on our test server. Stage/Production comes from the same release branch but have their own transform files.

    Solution

    I followed some of the guide from Microsoft and set up my web.<environment_name>.config to match the release stage names.

    I did not need to remove the <Dependent Upon> rows from my .csproj for each transform. Instead all I did was set the property Build Action of each transform to Content as shown by the image bellow.

    I then added these commands to the build pipeline's Build Solution -> MSBuild Arguments:

    • /p:MarkWebConfigAssistFilesAsExclude=false
    • /p:TransformWebConfigEnabled=false
    • /p:AutoParameterizationWebConfigConnectionStrings=False

    The build now does not try to transform the .config on it's own and also does not exclude the transform files from the artifact, allowing the release pipeline to do the transformation instead. Also, keeping the <Dependent On> for the transform files lets us have a "cleaner" look inside our code editors.

    0 讨论(0)
  • 2020-12-17 02:17

    I just got this working so I could have one build with deployment to multiple environments. This is what I did.

    In the code, I set each Web.<Environment>.config property to Build Action = "Content". I also set all mine to Copy to Output Directory = "Copy Always". I also unloaded the project and edit the csproj file, then removed the <DependendUpon>Web.config</DependentUpon> lines. This dumps all your web.configs to the root (no file nesting).

    In the build, I set pipeline variable BuildConfiguration = "Release". I don't have a Web.Release.config in my project.

    In the release, I named the deployment stage after the environment (in my case, Development, Staging, and Production). In all stages, on the Azure deployment task, I checked the XML transform checkbox.

    In Azure, I set the ASPNETCORE_ENVIRONMENT to the naming of the staging environment, in my case, Development, Staging, and Production).

    0 讨论(0)
  • 2020-12-17 02:17

    I just got this working as well. My issue was actually at the Visual Studio Solution level. I had the MVC project pointed to a different Configuration than the others. So always double check the configs!

    0 讨论(0)
  • 2020-12-17 02:34

    1) Make sure you transform works. Test it here.

    2) Ensure in your VS project that you are including the transform file, Web.Preview.config, and copying to output dir.

    3) Disable the config transform during the build, you just need to add argument /p:TransformWebConfigEnabled=False in MSBuild Arguments section of your Build task. You also need to add /p:AutoParameterizationWebConfigConnectionStrings=False if you want to update the connection string during the release. This will use the Web.Preview.config to "transform" the web.config.

    4) Double check that in your release for the IIS Web App Deploy task under File Transforms & Variable Substitution Options you have XML transformation checked.

    0 讨论(0)
提交回复
热议问题