【问题标题】:Bamboo does not transform Web.config file for any custom build configurationBamboo 不会为任何自定义构建配置转换 Web.config 文件
【发布时间】:2017-10-27 09:59:05
【问题描述】:

这是场景: 我有一个网站,其中有一个 web.config 文件以及许多其他特定于环境的配置文件,如 Web.Staging.config/Web.Release.config/Web.OnPrem.config 现在,我已经在我的网站项目的 csproj 文件中配置了 BeforeBuild Target:

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

当我设置竹子以在发布模式下构建和创建工件时,这很有效(因此部署的应用程序具有来自 web.Release.config 的转换后的 web.config 文件但是,当我更改竹子以使用 OnPrem 构建和创建工件时配置,它不会正确转换 web.config 文件。

当我说设置竹子在 OnPrem 配置中构建时,我实际上已将配置选项更改为以下:

/p:Configuration=OnPrem 而且,我已将 BambooBuild.proj 更改为具有

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

我在这里错过了什么?

【问题讨论】:

    标签: c# .net web-config bamboo web.config-transform


    【解决方案1】:

    因为您一次只能为一个活动配置构建,所以无论您构建的是哪个配置,都会被替换到 $(Configuration) 变量中。

    我通常做的是:

    1. 构建(不进行转换)以生成我的 DLL 和其他软件工件
    2. 然后我有一个单独的构建过程,它只运行转换,并生成单独的(在您的情况下)Web.Staging.config、Web.Release.config 和 Web.OnPrem.config 文件
    3. 在针对不同环境的部署计划中,我选择了该环境所需的 Web.xxx.config 文件并将其重命名为 Web.config

    您可以从命令行使用 MSBuild 来运行转换。 (注意这里唯一的区别是 Web.Staging.config 或 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
    

    适合这样使用的 MSBuild.xml 文件将包含以下内容:

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

    【讨论】:

      猜你喜欢
      • 2011-06-17
      • 2012-09-20
      • 1970-01-01
      • 2015-02-16
      • 2013-07-15
      • 2012-01-15
      • 2016-04-16
      • 1970-01-01
      • 2011-07-11
      相关资源
      最近更新 更多