Octopus transforms omitting values

I am looking to transform the below part of the web.config file:

    <compilation debug="true" targetFramework="x.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Helpers, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Routing, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Mvc, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.WebPages, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
      </assemblies>
    </compilation>

My environment config file looks as below; web.environment.config

      <system.web>
      	<compilation debug="true" targetFramework="x.0" xdt:Transform="InsertIfMissing"/>
        <identity impersonate="false" xdt:Transform="Replace"/>
      </system.web>

When the transform happens the debug key and value is omitted. If I change the value or xdt:Transform to “Replace” (xdt:Transform=“Replace”/>, the assemblies are replaced/Omitted with the debug and targetframework key value pairs being retained.

Can I please get some help in trying to keep the debug and transform key and value pairs as well as the assemblies

When I try this from Powershell, it seems to work perfect, but when Octopus is doing it, it is omitting as above

Thank you

Hi @supafly270,

Thank you for reaching out with your question surrounding transforms.

Just to be upfront, this is not my area of expertise so I will need to do a little more digging into this internally.

But I just wanted to let you know that your question has been picked up and will look into this for you.

In the meantime, let me share some links to our docs for some additional guidance and troubleshooting tips for .NET transformations in case you haven’t seen this.

There is also a testing tool from the team at AppHarbor to test out your transformations. It would be interesting to see if you are getting the same behaviors outside of Octopus. The tool can be found here:

I hope you find the links useful.

All the best,
Doug

Hey Doug,

Thanks this this, I’ll check the links out and test it with Apphb as well

Looking forward to understand what you find

Thanks

Hi @supafly270,

Also, would it be possible to share your RAW task logs where the transform is taking place to see what Octopus may be doing with the transform behaviors/actions on behalf of the package.

Get the Raw Output From a Task.

You might want to open the file in a text editor and redact any sensitive information like hostnames or company information, before sending the log to us.

I look forward to hearing from you.

Thanks
Doug

Hi

With regards to the Raw output, I can see the details with regards to the transform as below; the uppercase text is where it is supposed to be updating the values, in this particular instance I am specifying “xdt:Transform=“InsertIfMissing”/>”, however it seems like it is Replacing

13:24:34 Verbose | Executing SetAttributes (transform line 77, 223)
13:24:34 Verbose | on /configuration/connectionStrings/add[@name=‘x’]
13:24:34 Verbose | Applying to ‘add’ element (source line 161, 6)
13:24:34 Verbose | Set ‘name’ attribute
13:24:34 Verbose | Set ‘connectionString’ attribute
13:24:34 Verbose | Set ‘providerName’ attribute
13:24:34 Verbose | Set 3 attributes
13:24:34 Verbose | Done executing SetAttributes
13:24:34 VERBOSE | EXECUTING REPLACE (TRANSFORM LINE 81, 56)
13:24:34 VERBOSE | ON /CONFIGURATION/SYSTEM.WEB/COMPILATION
13:24:34 VERBOSE | APPLYING TO ‘COMPILATION’ ELEMENT (SOURCE LINE 128, 6)
13:24:34 VERBOSE | REPLACED ‘COMPILATION’ ELEMENT
13:24:34 Verbose | Done executing Replace
13:24:34 Verbose | Executing Replace (transform line 89, 39)
13:24:34 Verbose | on /configuration/system.web/identity
13:24:34 Verbose | Applying to ‘identity’ element (source line 116, 6)
13:24:34 Verbose | Replaced ‘identity’ element
13:24:34 Verbose | Done executing Replace

Hi @supafly270,

Thank you for sending over the task logs.

I have had a look at trying to replicate (what I have understood from your example and question) and I have managed to get this working (I beleive).

Before I outline my steps I took, I just wanted to double check with you a couple of items.

For my test I ran this on Octopus Server version 2022.3, are you able to confirm the version of Octopus you are running this on. While I don’t believe we have modified the transform behavior within Octopus, I wanted to check in case this is an issue for the version of Octopus you may be running.

The next observation is that from your logs (as you mentioned) it appears to be replacing. Can I check how you have deployed the changes with the binaries modified? Are you creating a new release with a new package. If you are modifying the same package version, then chances are Octopus will be using the package from the cache, which is why the changes may not have been picked up.

As for my (simple) test, I did the following:

Create a Web.Config file:

<?xml version="1.0"?>
<configuration>
    <connectionStrings>    
        <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString=""/>    
     </connectionStrings> 
  <MyCustomSettingsSection>
    <TestMode>True</TestMode>
  </MyCustomSettingsSection>
  <system.web>
  <identity impersonate="true" other="true"/>
  <compilation debug="true" targetFramework="x.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Helpers, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Routing, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Mvc, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.WebPages, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

Create a Web.Development.Config file:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>    
        <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="DataSource=localhost\SQLExpress;Databasename=master;Integrated Security=true;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>    
     </connectionStrings> 
  <MyCustomSettingsSection>
    <TestMode xdt:Transform="Replace">false</TestMode>
  </MyCustomSettingsSection>
  <system.web>
    <compilation debug="true" targetFramework="x.0" xdt:Transform="InsertIfMissing"/>
    <identity impersonate="false" xdt:Transform="Replace"/>
  </system.web>
</configuration>

I packaged these into a zip file and uploaded to my Octopus Server instance.

Set up a simple test within my local Octopus Server instance (2022.3):

Run a deployment, and this successfully transformed my XML:

Output of my deployed Web.Config:

<?xml version="1.0"?>
<configuration>
    <connectionStrings>    
        <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="DataSource=localhost\SQLExpress;Databasename=master;Integrated Security=true;"/>    
     </connectionStrings> 
  <MyCustomSettingsSection>
    <TestMode>false</TestMode>
  </MyCustomSettingsSection>
  <system.web>
  <identity impersonate="false"/>
  <compilation debug="true" targetFramework="x.0">
      <assemblies>
        <add assembly="System.Web.Abstractions, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Helpers, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Routing, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.Mvc, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
        <add assembly="System.Web.WebPages, Version=x.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxxxx" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

Looking at my RAW task logs I can see the transform using the InsertIfMissing:

I also run the same test using the Web.config Transformation Tester (apphb.com) and my config transformed as expected.

I hope this helps.

All the best,
Doug