0

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.

JianYA
  • 2,750
  • 8
  • 60
  • 136

2 Answers2

1

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.

Troopers
  • 5,127
  • 1
  • 37
  • 64
0

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.

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • Hello, thanks for answering. Where do I use replace token? I tried using it in the Build but it keeps saying that it skips updating my file? – JianYA Mar 12 '20 at 09:39
  • @JianYA, of course do this replacement before you use the config. Mostly, I did this before the repos was build. For skipping issue, did you target the config in the task definition? Also, you need do some configuration in your config file (#{parameter name}#) so that it can replaced by your environment variable. – Mengdi Liang Mar 12 '20 at 09:45
  • Hello, I am trying it again now. Does that mean that my web.config files should have something like (#{parameter name}#) in the value? – JianYA Mar 12 '20 at 09:48
  • @JianYA. Yes, only this, the replace token task can found corresponding location to replace value. This is the disadvantage of this method if it has any disturb. – Mengdi Liang Mar 12 '20 at 09:57