-1

I am developing an ASP.NET Core API (.NET Core 3.1). Everything works as expected. When I deploy the application on the consumer environment using Octopus, it reads the appsettings.Production.json, not the appsettings.Uat.json even if I have set the ASPNETCORE_ENVIRONMENT to Consumer.

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\Mydll.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

launchsettings.json

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50900",
      "sslPort": 0
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "default",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS_UAT Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "default",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Consumer"
      }
    },
    "IIS_PRODUCTION Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "default",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      }
    },
    "ISOXMLValidationApi": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "default",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    }
  }
}

Octopus variables:

enter image description here

benPearce
  • 37,735
  • 14
  • 62
  • 96
Vivek Nuna
  • 25,472
  • 25
  • 109
  • 197

1 Answers1

1

Are you using the ASPNETCORE_ENVIRONMENT Octopus variable anywhere? Octopus won't automatically set the ENV variable with that name so you might need to add a script to do that during your deployment.

If you haven't done this yet, you can use a separate Run a Script step on the target or the custom deployment scripts feature on your Deploy a Package step.

Information on custom scripts and scripts in packages:

There's also a chance that you don't need the environmental JSON configuration files as Octopus can inject variable values directly into JSON configuration files.

To set an environment variable with PowerShell, it would look something like

$aspEnvironment = $OctopusParameters["ASPNETCORE_ENVIRONMENT"]
[System.Environment]::SetEnvironmentVariable('ASPNETCORE_ENVIRONMENT', $aspEnvironment, [System.EnvironmentVariableTarget]::User)

See https://www.tachytelic.net/2019/03/powershell-environment-variables/ as a reference.

ryan.rousseau
  • 1,595
  • 1
  • 11
  • 22
  • How to add script and what script? And how to run? – Vivek Nuna Oct 10 '20 at 00:58
  • There are a few different ways you can run a script during a deployment. Check https://octopus.com/docs/deployment-examples/custom-scripts and https://octopus.com/docs/deployment-examples/custom-scripts/scripts-in-packages The script would be to set the environment variable with your value in whichever language you prefer. Octopus can also put values directly into a json file directly, so you might not need the separate environmental files. See https://octopus.com/docs/deployment-process/configuration-features/structured-configuration-variables-feature – ryan.rousseau Oct 11 '20 at 17:15
  • You should not put this as answer. You are only providing suggestions which I already know – Vivek Nuna Oct 11 '20 at 17:18
  • can you tell me how to do? I have already gone through these links. Give the concrete solution instead of proving the links to refer – Vivek Nuna Oct 11 '20 at 17:20