我有一个azure webjob项目,它使用config转换来创建dev/test/release配置.我们使用TFS进行Azure的CI/CD部署.我想让MSBuild为dev应用转换,以便我们可以在本地进行调试.但是,当我们在CI/CD管道中构建TFS时,我需要在构建步骤中禁用配置转换.
TFS在发布步骤中有一个"应用XML转换"复选框,这是我们希望应用转换的地方,因为我们在发布期间设置了环境变量.遗憾的是,这不起作用,因为转换已在构建期间应用,因此发布工件只有完成的输出文件,而不是单独的转换文件.
我已经尝试编辑.csproj文件来禁用转换.我假设变换正在由项目文件的以下部分执行:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="Exists('App.$(Configuration).config')">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.$(Configuration).config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
<!--Override After Publish to support ClickOnce AfterPublish. Target replaces the untransformed config file copied to the deployment directory with the transformed one.-->
<Target Name="AfterPublish">
<PropertyGroup>
<DeployedConfig>$(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension)</DeployedConfig>
</PropertyGroup>
<!--Publish copies the untransformed App.config to deployment directory so overwrite it-->
<Copy Condition="Exists('$(DeployedConfig)')" SourceFiles="$(IntermediateOutputPath)$(TargetFileName).config" DestinationFiles="$(DeployedConfig)" />
</Target>
Run Code Online (Sandbox Code Playgroud)
我尝试在这些部分添加诸如"$(Configuration)| $(Platform)'=='Debug | AnyCPU'"之类的条件,但它没有帮助(转换仍然适用于所有三种环境).我甚至完全评论了这一部分,我仍然得到了变换.这让我有三个问题:
Edd*_*SFT 16
要在构建期间禁用配置转换,只需/p:TransformWebConfigEnabled=False在构建任务的MSBuild Arguments部分中添加参数即可./p:AutoParameterizationWebConfigConnectionStrings=False如果要在发布期间更新连接字符串,还需要添加.

此外,如果要生成用于部署的msdeploy软件包,则需要更新项目文件,以便Web.XXX.Config文件将包含在软件包中.
这些“ MSBuild参数”对我有用:
重要的是:
当我还添加以下内容时,它开始起作用:
感谢@Eddie Chen-MSFT和@Wessel T.
问候汉斯
| 归档时间: |
|
| 查看次数: |
2757 次 |
| 最近记录: |