Custom tags in web.config

Hi everyone! My web.config looks like this:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="..." />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

  <externalApiConfiguration url="..." userTimeout="5000" applicationTimeout="3000" authHeader="..." /> 

Does anyone has suggestions or ideas on what’s the smartest way to perform a substitution of the entityFramework tag parameter value and the externalApiConfiguration url and authHeader values in Octopus?

Hi Patricia,

Thanks for getting in touch. One way we’ve used to solve this is to have a Release.config file that transforms the desired value to an Octopus variable. For example, you might transform the externalApiConfiguration.url value to something like #{ExternalApiUrl}.

Then in your Octopus define ExternalApiUrl as a variable with the required values per environment etc and enable the Configuration Variables feature on the deployment step.

Hope that helps and let me know if you have any further questions.

Regards
Shannon

Hi Shannon,

Thanks for posting! Unfortunately that’s what I did, but it didn’t worked out. I guess I’m missing some configuration somewhere, because the deploy process is not failing but is not applying the transformations. What am I doing wrong or missing? Thanks!

(externalUrl variable properly defined for the target environment)

Ok, so I think you’re right, it’ll just be something slightly out in the configuration somewhere.

Let’s double check a few things:

  • Is the transform file called web.Release.config ?
  • Is it definitely in the package?
  • Is the Configuration Variables feature enabled on the step?
  • Is the task log for the deployment showing any signs that it’s trying to do the transforms? In the Verbose logs I think it should says where it’s search for transforms to apply.

If you’re able to attach any screenshots or task logs that would be good. If they have sensitive information you can send to support@octopus.com with a link to this thread.

Regards
Shannon

Hi Shannon,

Thanks very much. I was able to solve this issue, however I would like to check if Octopus works like this or if maybe some setting is not properly configured.

1- The transform file exists and it’s named Web.Release.config.
2- Declared Web.Release.config => Web.config explicitly in the extra transformations box.
3- The transformation rule is valid, I tested it using Visual Studio.
4- All variables are properly declared

What happened was:

  • Octopus did not applied transformations
  • Web.Release.config was not in the Octopus package, but it was in the Build package.

How I made it “work”:

  • Added an extra tag for web.release.config inside my csproj file.
  • Maintained explicit Web.Release.config => Web.config declaration
  • Declared Web.Release.config explicitly in the extra substitutions box (without this one it replaced the custom keys in Web.config for the ones in the Web.Release.config, but without any variable substitutions, so it was showing #{variable_name} instead of the variable value for each variable used)

Now I see:

  • Web.Release.config is deployed, as well as all the files (I just want this file to be used when the Release is being created), so I guess I have to add an step for deleting it after the Deployment step)

What I was expecting was:
Octopus will find out I have a Web.Release.config file and (as it has the default naming and those boxes I used they all say “extra”) it will apply the transformations to my Web.config without any extra explicit instructions to do so and to substitute the variables once the Web.config is already transformed.

My question is now:
Is Octopus supposed to work like I was expecting it to work or in the way it is actually behaving? Thanks very much!

Hi Patricia,

I’m so sorry this slipped through the cracks and I’ve taken so long to reply. Glad to hear you got it working.

The file not being in the package would certainly have been major contributor. If you’re applying those transforms during the build then their default setup is ok, but they need to be marked as Content to have them included in the package for Octopus to use (like you’ve done in the csproj).

Once the transform file is in the package, my recollection is that you should just need these two features enabled

image

Web.Release.config should be one of the default transforms it runs so there shouldn’t be further config required. There should be details in the verbose/raw log regarding paths it’s considering/process for transforms and substitutions, would you be able to send a screenshot of the Configuration Transforms section on the step, and a raw log from a deployment, to support@octopus.com (inc a link to this thread)?

Regards
Shannon

Sorry, I forgot to mention about the deleting the file. Yes, you’d probably want a PostDeploy script to delete those if you don’t want them there.

The alternative would be to have MSBuild apply the transform during the build, then the file doesn’t need to be in the package, doesn’t need to be marked content in the csproj, only the Configuration Variables feature would be required in the Octopus step, and the file would never end up in the deployment so wouldn’t need to be deleted.

Regards
Shannon

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.