【发布时间】:2018-07-03 02:45:57
【问题描述】:
我有一个 azure webjob 项目,它使用配置转换来创建开发/测试/发布配置。我们使用 TFS 将 CI/CD 部署到 Azure。我想让 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>
我尝试向这些部分添加“$(Configuration)|$(Platform)' == 'Debug|AnyCPU'” 之类的条件,但没有帮助(转换仍然适用于所有三个环境)。我什至完全评论了这一部分,我仍然得到了转换。这给我留下了三个问题:
- 如何禁用配置转换?
- 我怎样才能有条件地 禁用它们以便在 VS 中调试时仍然应用它们?
- 这是 正确的方法,或者有更好的方法来获得正确的 在 TFS 2017 中使用 CI/CD 时应用了转换?
【问题讨论】: