Bamboo does not transform Web.config file for any custom build configuration

一曲冷凌霜 提交于 2019-12-12 15:06:33

问题


Here is the scenario: I have a website which has a web.config file along with many other environment specific config files like Web.Staging.config/Web.Release.config/Web.OnPrem.config Now, I have configured the BeforeBuild Target in the csproj file of my website project:

<Target Name="BeforeBuild">
    <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>

This works well when I setup bamboo to build and create artifacts in Release mode (so the deployed application has the transformed web.config file from web.Release.config But, when I change the bamboo to build and create artifacts using OnPrem configuration, it does not transform the web.config file correctly.

When I say setup bamboo to build in OnPrem config, I have actually change the configuration option to below:

/p:Configuration=OnPrem and also, I have changed the BambooBuild.proj to have

<ConfigurationToBuild Include="OnPrem|Any CPU">
  <FlavorToBuild>OnPrem</FlavorToBuild>
  <PlatformToBuild>Any CPU</PlatformToBuild>
</ConfigurationToBuild>

What am I missing here?


回答1:


Because you can only build for one active configuration at a time, whichever configuration you're building is the one that will get substituted into the $(Configuration) variable.

What I normally do is:

  1. build (with no transforms) to produce my DLL & other software artifacts
  2. then I have a separate build process which runs transforms only, and produces separate (in your case) Web.Staging.config, Web.Release.config & Web.OnPrem.config files
  3. in my deployment plans for separate environments, I pick the Web.xxx.config file I need for that environment and rename it to Web.config

You can use MSBuild from the command line just to run transformations. (Note the only difference here is Web.Staging.config or Web.Release.config):

Msbuild.exe /target:Transform "/property:TransformInputFile=path\to\Web.config;TransformFile=path\to\Web.Staging.config;TransformOutputFile=path\to\artefacts\Web.Staging.config" MSBuild.xml
Msbuild.exe /target:Transform "/property:TransformInputFile=path\to\Web.config;TransformFile=path\to\Web.Release.config;TransformOutputFile=path\to\artefacts\Web.Release.config" MSBuild.xml

A MSBuild.xml file suitable for use like this would contain something like the following:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
         DefaultTargets="Deploy"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <UsingTask TaskName="TransformXml"
         AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

  <Target Name="Transform">
    <TransformXml Source="$(TransformInputFile)"
          Transform="$(TransformFile)"
          Destination="$(TransformOutputFile)"
          StackTrace="$(StackTraceEnabled)" />
  </Target>

</Project>


来源:https://stackoverflow.com/questions/46972402/bamboo-does-not-transform-web-config-file-for-any-custom-build-configuration

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