0
votes

I have this web.config file i place in the root of my project that is built by azure devops here:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\ManagementStudio.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
        <environmentVariables>
          <environmentVariable name="MS_CONNECTIONSTRING" value="" />
          <environmentVariable name="CENTRAL_APPLICATION_SETTINGS" value="" />
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="" />
          <environmentVariable name="MS_COOKIEEXPIRYTIMEINMINUTES" value="" />
          <environmentVariable name="MS_STATICFILECACHEINSECONDS" value="" />
          <environmentVariable name="MS_COOKIEDOMAIN" value="" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

I then set these bunch of variables in the release section:

ASPNETCORE_ENVIRONMENT
Development
CENTRAL_APPLICATION_SETTINGS
csa
CLOUDFRONT_DOMAIN
csd
MS_CONNECTIONSTRING
connstring
MS_COOKIEDOMAIN
dev.website.com

I set them as settable at release time.

In my IIS Web App Deploy, I ticked XML Variable Substitution.

However, it doesn't seem like any of my variables are changed at all.

2

2 Answers

1
votes

Only the section appSettings, connectionStrings and applicationSettings are substitued (see the documentation), and section must contain configuration element with key or name like:

<connectionStrings>
    <add name="MyDB" connectionString="..." />
</connectionStrings>

where you can define a variable MyDB to set the connection string

--Update--

For environmentVariables section you could test this suggestion from the documentation :

If you are looking to substitute values outside of these elements you can use a (parameters.xml) file, however you will need to use a 3rd party pipeline task to handle the variable substitution.

0
votes

For the reason of why it does not be applied successfully, I agree with Troopers.

But, it does not mean you could not use environment variable anymore. If environment variable is the preferred choice you want, you can consider to use replace token task to achieve what you want.

For detailed used about this task, you can refer to my previous reply.