Bamboo不会为任何自定义构建配置转换Web.config文件 [英] Bamboo does not transform Web.config file for any custom build configuration

查看:227
本文介绍了Bamboo不会为任何自定义构建配置转换Web.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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.

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

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

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

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

我在这里想念什么?

推荐答案

因为您一次只能为一个活动配置进行构建,所以您要构建的任何配置都将被替换为$(Configuration)变量

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.

我通常要做的是:

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

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

适合这样使用的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>

这篇关于Bamboo不会为任何自定义构建配置转换Web.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆