Articles
09

When an ASP.Net core application runs it inspects the ASPNETCORE_ENVIRONMENT environment variable to determine if it is running in development mode or production (or other) modes.

This can be set from a variety of places.  In .Net core 3 (maybe other versions) it can be set from the web config file...

      <environmentVariables>
        <!--This environment variable is overwritten from Launchsettings.json when you press F5 in Visual Studio-->
        <!--It is also overwritten by Octopus Deploy by a custom script step--> 
        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
      </environmentVariables>

 

But that value in the web config is also meddled with when you hit F5 in Visual Studio, where it gets overwritten by a value in launchsettings.json (only used by visual studio - not required on the live server).

Octopus deploy would be very happy if it said...

        <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="{OctopusVariable}" />
 

...Octopus is excellent at finding those variables and subbing values in there.  This does not work because every time you hit F5 the octopus variable gets overwritten with a value from launchsettings

So I added a custom deployment step to my Octopus Deploy based on Benjamin Tam's script https://library.octopus.com/step-templates/c7f96ab8-a0d3-4f01-928e-c8cb78ab108c/ 

I puzzled for AGES over finding out the directory that the .Net Core app was deployed, by a previous step, so that I could reference the web config file.  This worked for me...

#{Octopus.Action[ASP.Net Core Website].Output.Package.InstallationDirectoryPath}\web.config

Where "ASP.Net Core Website" is the actual name of the step deploying the .Net core website, as displayed in the Octopus UI.  I may not have made the perfect choice of Octopus internal variable, but it works for my simple requirements.

I also had to patch the script.  For me; the path in the web.config xml down to the environment variable section had to be corrected.

Original: $aspNetCore = $xml.configuration.location.'system.webServer'.aspNetCore

Modified by me: $aspNetCore = $xml.configuration.'system.webServer'.aspNetCore

 

Comments

There are currently no comments, be the first to post one!

Post Comment

Only registered users may post comments.
Copyright 2002-15 by Dynamisys Ltd