How to apply XML File Transformations on a ClickOnce application through Azure DevOps release pipeline?

只谈情不闲聊 提交于 2020-06-29 04:20:49

问题


My release pipeline deploys the application to multiple environments.

Based on the environment, I am trying to set up File Transformations to be executed, though I'm not sure how to set it up, if at all possible. I already have the app.Release.config file set up in the repository, but I'm not sure where to go from here.

In my release pipelines, I've enabled the native XML Transformation option, but it doesn't actually do anything. I've also tried adding the File Transform task and explicitly inputted the paths to the transform file as well as the .exe.config file, but no luck either. I get "Unable to apply transformation for the given package."

Is it something to do with the mismatch in names? Because this is a ClickOnce application, at compile time the name of the app.config changes to {nameOfApplication}.exe.config. I'm lost at how to accomplish what I need, and I'm starting to think it isn't possible?


回答1:


How to apply XML File Transformations on a ClickOnce application through Azure DevOps release pipeline?

File Transform task should work well in your scenario if we can meet its prerequisites:

1.Make sure the transform file(app.Release.config) and the source file({nameOfApplication}.exe.config) are in same path.

2.Make sure your transform file has correct xdt syntax, sample here.

3.Choose latest 2.0-preview version of File Transform task instead of old 1.0.

4.Try using valid file name when setting Xml Transformation rules.(Use {nameOfApplication}.exe.config instead of *.exe.config)

In my opinion, #1 and #3 above are always the direct cause of the error Unable to apply transformation for the given package. Check them carefully!

Some details for above four tips:

1.In project file(xx.csproj) I have this content to make sure the transform file will be copied to output folder. So it will be in same folder with source file xxx.exe.config.

<Content Include="App.release.config" >
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>

2.My test App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <appSettings>
      <add key="IsPackage" value="false" />
    </appSettings>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
    </startup>
</configuration>

My test App.release.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration  xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add xdt:Transform="Replace" xdt:Locator="Match(key)" key="IsPackage" value="true" />
  </appSettings>
</configuration>

3.Use latest version which fixes some issues:

4.According to some tests, valid name works better than something like *.exe.config when you already know the application name:

Hope all above helps :)



来源:https://stackoverflow.com/questions/61064440/how-to-apply-xml-file-transformations-on-a-clickonce-application-through-azure-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!