Azure Pipelines Release XML Variable Substitution skipped - azure

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.

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.

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.

Related

How to debug Azure app service slot swap failure

I am getting the following error when trying to do a slot swap for our app service:
##[error]Error: Failed to swap App Service 'service1' slots - 'staging' and 'production'. Error: BadRequest - Cannot swap slots for site 'service1' because the application initialization in 'staging' slot either took too long or failed. Please check AppInit module configuration or try using swap with preview if application initialization time is very long. (CODE: 400)
This is what our web.config file looks like:
<?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=".\XXXXXXXXXX.Services.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="1073741824" />
</requestFiltering>
</security>
<applicationInitialization>
<add initializationPage="/api/warmup" />
</applicationInitialization>
<tracing>
<traceFailedRequests>
<clear />
<add path="/api/warmup">
<traceAreas>
<add provider="ASP" verbosity="Verbose" />
<add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
<add provider="ISAPI Extension" verbosity="Verbose" />
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,iisnode" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200-600" />
</add>
</traceFailedRequests>
</tracing>
</system.webServer>
</location>
</configuration>
The API that is used for initialization and tracing - /api/warmup - this is functioning with no issues, I am able to invoke the API manually in both the production and staging slot, successfully. In fact, in the pipeline file, I invoke this API prior to invoking the slot swap task, yet the slot swap task fails after about 45 seconds.
Further, no trace file is generated in the /LogFiles folder, and I'm not sure where next to look. I would assume a trace file would be created even when I manually invoke the API, but it's not being created, so is there maybe an issue with the web.config file?
I figured the issue - i had Configuration key WEBSITE_SWAP_WARMUP_PING_STATUSES set to 200,202. Once I removed the key, the swap completed successfully.

How to configure dotnet core web.config from dotnet publish?

I have this in my dotnet core 3.1 webapp tasks.json:
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000",
"LOCAL": "true"
},
When I run dotnet publish this is what the Debug web.config contains:
<?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=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
</system.webServer>
</location>
</configuration>
Because I want to host under IIS, this is what I want it to contain, so for now I need to manually edit it:
<?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=".\App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
<environmentVariable name="ASPNETCORE_URLS" value="http://localhost/app" />
<environmentVariable name="LOCAL" value="true" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
How can I configure either my solution or the .vscode .json files to make this change when I run dotnet publish?
1)You could use the below command to add the environment variable at the time of publishing:
dotnet publish -c Debug -r /p:EnvironmentName=Development
2)Add environmnet variable in publish profile
<PropertyGroup>
<EnvironmentName>Development</EnvironmentName>
</PropertyGroup>
3)Modify the project file (.CsProj) file
Referance link:
Publish to IIS, setting Environment Variable
how to set ASPNETCORE_ENVIRONMENT to be considered for publishing an asp.net core application?
If you want to do more than just setting the EnvironmentName:
On a project using "Microsoft.NET.Sdk.Web" target, config transforms are applied.
Add a web.{CONFIGURATION}.config in the project folder:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<location>
<system.webServer>
<aspNetCore>
<environmentVariables xdt:Transform="InsertIfMissing">
<environmentVariable name="Configuration_Specific"
value="Configuration_Specific_Value"
xdt:Locator="Match(name)"
xdt:Transform="InsertIfMissing" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>
Then after running a dotnet publish -c {CONFIGURATION}, the publish output contains the following auto generated web.config (some parts removed for brevity):
...
<aspNetCore ...>
<environmentVariables>
<environmentVariable name="Configuration_Specific" value="Configuration_Specific_Value"/>
</environmentVariables>
</aspNetCore>
...
See https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/transform-webconfig?view=aspnetcore-6.0#build-configuration

ASP.NET Core 2.0 ==> Swapping to Development environment will display more detailed information about the error that occurred

I have create 2 pages in asp.net core 2.0, both pages Login/Register open successfully as you can see in attached screen shot but when I click on login or register button after fill up all detail which is in form ,its giving me below error, I already try with changing environment variable , but its not helping me , please help !
Error.
An error occurred while processing your request.
Request ID: 0HLF8F6V3DFJ3:00000002
Development Mode
Swapping to Development environment will display more detailed information about the error that occurred.
Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
Modify your web.config file with the below. The web.config file is typically auto generated in the root folder of the application.
<aspNetCore processPath="dotnet" arguments=".\projectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
The web.config in its entirety should resemble the below (update "projectName.dll" for your project appropriately):
<?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=".\projectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</location>
</configuration>

ASPNETCORE_ENVIRONMENT overwritten on deploy

I have a dotnet core application I am deploying remotely on a test server. The ASPNETCORE_ENVIRONMENT variable should be set to "Development" on the remote machine. Each time I deploy, the ASPNETCORE_ENVIRONMENT variable is overwritten with "Develop". I have to go into the IIS Admin Configuration Editor and replace the incorrect ASPNETCORE_ENVIRONMENT variable each time I deploy.
Can anyone help me understand why this variable is being overwritten each time I deploy?
Here is my web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation>
<buildProviders>
<remove extension=".xml" />
<add extension=".xml"
type="System.Web.Compilation.ForceCopyBuildProvider" />
</buildProviders>
</compilation>
</system.web>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*"
modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet"
arguments=".\WorkersCompensation.dll" stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true">
<environmentVariables>
<clear />
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Development" />
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
Here is my Dev.pubxml file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.0</PublishFramework>
<UsePowerShell>True</UsePowerShell>
<publishUrl>\\esdev2.elwood.local\D$\Core\WorkersCompensation</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeFoldersFromDeployment>wwwroot\node_modules</ExcludeFoldersFromDeployment>
<UseMsDeployExe>true</UseMsDeployExe>
</PropertyGroup>
<ItemGroup>
<MsDeploySkipRules Include="SkipNodeModules">
<AbsolutePath>wwwroot\node_modules</AbsolutePath>
</MsDeploySkipRules>
</ItemGroup>
</Project>
I believe I have found the issue/solution for anyone else having this issue.
The web.config file deployed did not have the environmentVariable entry until I edited the environment variables in IIS Admin.
I altered the web.config and web.Debug.config files in my deploy and now I am getting the correct environment variables on the IIS server.
The web.config file should match the one in my question above, but the web.Debug.Config now looks like this:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<aspNetCore>
<environmentVariables>
<clear />
<environmentVariable name="ASPNETCORE_ENVIRONMENT"
value="Development" xdt:Locator="Match(name)" />
</environmentVariables>
</aspNetCore>
</configuration>

Run go web application on IIS

Is there a way to run Go web application on IIS?
I found a setting for azure but its not working on my dev machine
this is a web config for azure :
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="d:\home\site\wwwroot\go\bin\go.exe"
arguments="run d:\home\site\wwwroot\server.go"
startupTimeLimit="60">
<environmentVariables>
<environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />
</environmentVariables>
</httpPlatform>
</system.webServer>
</configuration>
Your local IIS does not work simply because you need to install a separate component, called HttpPlatformHandler module,
https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/
http://www.iis.net/downloads/microsoft/httpplatformhandler
Reverse proxy or FastCGI were the older approaches which are no longer necessary with this new approach.
HttpPlatformHandler module doesn't work for me. I found this post by Sutean Rutjanalard on Medium very helpful, which use ASP.NET Core Module instead.
Basically, you need to create Application pool with "No Managed Code" as you do with a .net core app. And the following is the web.config.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\YourGoApp.exe" />
</system.webServer>
</configuration>

Resources