Monday, March 18, 2019

notes from troubleshooting Octopus variable swapping at appsettings.json!

My attempt to get this working proved painful. The problem was that in the "YourNameHere Template - Roslyn - VariableReplacement" step the "JSON Target Files" setting needed to be changed from appsettings.json by itself to:

appsettings.json
appsettings.Development.json
appsettings.Test.json
appsettings.Production.json

 
 

The reason the variables had to be written to the other files is that the other files were being used in other environments. For example in Development appsettings.Development.json was being referenced instead of appsettings.json and that was creating a scenario in which connection strings were empty strings until the problem was fixed. In the "Update Web.Config Environment" step under "Process" in Octopus' interface there was a PowerShell script like so at "Inline Source Code":

$path = 'IIS:\Sites\' + $webSiteName;
Write-Output "Website name $webSiteName"
Add-WebConfigurationProperty -Filter "/system.WebServer/aspNetCore/environmentVariables" -Verbose -PSPath $path
      -AtIndex 0 -Name Collection -Value
      @{name='ASPNETCORE_ENVIRONMENT';value=$ConfigurationEnvironment}

 
 

This is using the ConfigurationEnvironment variable out of the "Variables" in Octopus' UI wherein "Development" is the Development option, "Test" is the Test option, and, yes, "Production" is the Production option. Alright, in figuring this out I learned a few interesting things along the way:

  1. If Citrix NetScaler is is managing having an application straddle two different webservers using IIS, then if you stop an application pool at one of the webservers Citrix NetScaler should be smart enough to pick up on this and route all traffic to the second webserver.
  2. The ".NET CLR version" in IIS 8.5.9600.16384 for an application pool for a .NET Core API should be set to "No Managed Code" and not ".NET CLR Version v4.0.30319" instead.
  3. At Windows Server 2012 R2, if you type "Event Viewer" at the "Search" magnifying glass and look through what is in the Event Viewer, you may refresh what you see by picking: Action > Refresh
  4. Type "Environment Variables" at the magnifying glass and then click "Edit the system environment variables" to get the "Advanced" tab at a "System Properties" dialog box where you may click the "Environment Variables..." button to see a list of applicable variables.

No comments:

Post a Comment