Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 竹子不会为任何自定义生成配置转换Web.config文件_C#_.net_Web Config_Bamboo_Web.config Transform - Fatal编程技术网

C# 竹子不会为任何自定义生成配置转换Web.config文件

C# 竹子不会为任何自定义生成配置转换Web.config文件,c#,.net,web-config,bamboo,web.config-transform,C#,.net,Web Config,Bamboo,Web.config Transform,以下是场景: 我有一个网站,它有一个web.config文件以及许多其他特定于环境的配置文件,如web.Staging.config/web.Release.config/web.OnPrem.config 现在,我已经在我的网站项目的csproj文件中配置了BeforeBuild目标: <Target Name="BeforeBuild"> <TransformXml Source="Web.config" Transform="Web.$(Configuration

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

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

我在这里遗漏了什么?

因为您一次只能为一个活动配置生成,无论您生成的配置是将被替换到$(配置)变量中的配置

我通常做的是:

  • 构建(无转换)以生成我的DLL和其他软件工件
  • 然后我有一个单独的构建过程,它只运行转换,并生成单独的(在您的情况下)Web.Staging.config、Web.Release.config和Web.OnPrem.config文件
  • 在我针对不同环境的部署计划中,我选择该环境所需的Web.xxx.config文件,并将其重命名为Web.config
  • 您可以从命令行使用MSBuild来运行转换。(注意这里唯一的区别是Web.Staging.config或Web.Release.config):

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