Sagar
Sagar

Reputation: 710

"File Transforms and Variable substitution task" in "Azure App Service deploy task" not transforming config files

No option to provide File path in "File Transforms and Variable substitution task" in "Azure App Service deploy task"

  1. I am using "Azure app service deploy task" to deploy a zip file as Web app deployment
  2. My .config file are inside secrets folder in wwwroot
  3. This is because I am using below tab in web.config
  4. I have selected XML Transformation and XML Variable substitution both
  5. But connection-strings and app settings are not getting replaced with Library variable set
  6. Is this because there is NO "Target files" textbox to enter file paths ?

enter image description here

  1. I am thinking of first downloading and extracting the zip
  2. Apply file transform
  3. Deploy using Azure web deploy task

Upvotes: 0

Views: 609

Answers (1)

SiddheshDesai
SiddheshDesai

Reputation: 8215

There's no target path to be specified in while using XML transformation and XML Substitution Option in Azure release pipeline.

According to this MS Document:-

If you want to transform Web.config file, Create one web.release.config with the transformation code and add it in your repository along with the web.config file, Then select XML transformation while using the release pipeline, This will update the web.config file with the web.release.config. If you are using debug configuration create a transform file with name web.debug.config

web.config file:-


<?xml version="1.0" encoding="utf-8"?> <configuration>  
<connectionStrings>
    <add name="DefaultConnection"
         connectionString="Data Source=(LocalDb)\\MSDB;DbFilename=aspcore-local.mdf;" />  
</connectionStrings>   <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />   </appSettings>   <system.web>
    <authentication mode="None" />
    <compilation targetFramework="4.5" debug="true" />   </system.web> </configuration>

web.release.config:-


<?xml version="1.0"?> <configuration
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>
      <add name="MyDB"
           connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
           xdt:Transform="Insert" />
    </connectionStrings>   <appSettings>
    <add xdt:Transform="Replace" xdt:Locator="Match(key)" key="webpages:Enabled" value="true" />   </appSettings>   <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />   </system.web> </configuration>

Create a release pipeline by naming the stage as release and click on XML transformation like below:-

enter image description here

If the XML transformation does not work, You can make use of XML variable substitution, Here instead of creating a Transform file, You add the codes or parameters that needs to be updated in the environment variable like below:-

web.config:-


<?xml version="1.0" encoding="utf-8"?> <configuration>
    <configSection>
        <section name="entityFramework" />
    </configSection>
    <connectionStrings>
        <!-- Change connectionString in this line: --> 
        <add name="DefaultConnection"
             connectionString="Data Source=(LocalDB)\LocalDB;FileName=Local.mdf" />
    </connectionStrings>
    <appSettings>
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobstructiveJavascriptEnabled" value="true" />
        <!-- Change AdminUserName in this line: --> 
        <add key="AdminUserName" value="__AdminUserName__" />
        <!-- Change AdminPassword in this line: --> 
        <add key="AdminPassword" value="__AdminPassword__" />
    </appSettings>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.LocalDbConnectionFactory">
            <parameters></parameters>
        </defaultConnectionFactory>
        <providers>
            <!-- Change invariantName in this line: --> 
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer" />
        </providers>
    </entityFramework> </configuration>

enter image description here

And select XML variable substitution and run your pipeline:-

enter image description here

Azure App Service Deploy Task deploys the code as zip refer below:-

enter image description here

Additionally, If you want to deploy your app as zip refer this Document

Upvotes: 0

Related Questions