0

我们从 Azure Pipelines (YAML) 开始,在 FileTransform 任务期间遇到以下错误:

##[error]Unable to apply transformation for the given package - Changes are already present in the package.

结果是没有发生任何转换,并且部署的配置与 Release.config 匹配

这是一个带有 Web.Config、Web.Stage.config、Web.Release.config 等的 ASP.NET Web 应用程序。

最终目标是设置不同的阶段并使用配置文件应用相应的转换。但现在,我只想获得“发布”版本并应用“阶段”转换,以确保此任务有效。

如果有帮助,这是 YAML 的一个片段:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

...

task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

...

- task: PublishBuildArtifacts@1
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)'
    ArtifactName: 'drop'
    publishLocation: 'Container'

- task: FileTransform@2
  inputs:
    folderPath: '$(Build.ArtifactStagingDirectory)/**/*.zip'
    xmlTransformationRules: '-transform **\*.Stage.config -xml **\*.config'

- task: AzureRmWebAppDeployment@4
  inputs:
    ConnectionType: 'AzureRM'
    azureSubscription: 'Microsoft Partner Network(blablabla)'
    appType: 'webApp'
    WebAppName: 'mywebapp'
    packageForLinux: '$(Build.ArtifactStagingDirectory)/**/*.zip'

更新:最终的 web.config 文件包含如下连接字符串:

<add name="DefaultConnection" connectionString="$(ReplacableToken_DefaultConnection-Web.config Connection String_0)" providerName="System.Data.SqlClient"/>

这是构建步骤的日志。您可以看到在构建过程中发生了转换。

这是构建步骤的日志。 我在这里想念什么?

谢谢!

4

1 回答 1

0

我测试并发现在以下情况下会出现上述错误。

1,当没有发现配置文件或转换文件与xmlTransformationRules. 这可能是文件模式不正确或包中不存在转换文件/配置文件。

2、当配置文件和transform文件不在指定包内的同一文件夹时。

上面的xmlTransformationRulesyaml 在我的测试中工作。所以你需要检查配置文件和转换文件是否在不同的文件夹中。您需要确保它们在同一个文件夹中才能使 XML 转换生效。

有关更多信息,请参阅XML 转换说明

更新

默认情况下,web.config 文件将在构建期间针对 web.{buildConfiguration}.config 进行转换。

/p:IsTransformWebConfigDisabled=true您可以通过传递给msbuildArgs属性来禁用 vsbuild 任务来转换 web.config 。请参见下面的示例:

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:IsTransformWebConfigDisabled=true /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
于 2020-06-02T05:51:40.863 回答