Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET 5 Environment Name in Azure Web App

Where is it best to set the environment name for each deployment of a ASP.NET 5 web application when publishing to Azure Web Apps?

I understand that the ASPNET_DEV environment variable needs to be set. Is this possible on publish?

This is our powershell publish script:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]

$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword}

Write-Output "Restarting web app..."
Restart-AzureWebsite -Name $websiteName

Write-Output "Publishing web app..."
$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\default-publish.ps1"

. $publishScript -publishProperties $publishProperties  -packOutput $packOutput

Or do we have set the environmental variable in the Azure portal? Will this persist between deployments?

I am using the ASP.NET 5 beta6 libraries with the dnx451 target framework, if that matters.

like image 549
Dave New Avatar asked Aug 26 '15 05:08

Dave New


1 Answers

Where is it best to set the environment name for each deployment of a ASP.NET 5 web application when publishing to Azure Web Apps?

@cory-fowler is right. Use App Settings to set the environment name. There are at least four ways to do that.

portal.azure.com

Browse > All resources > MyApp > Settings > Application settings.

manage.windowsazure.net

Web apps > MyApp > CONFIGURE > app settings.

Azure Command Line Interface (CLI)

npm install -g azure-cli
azure account download
azure account import '~\Downloads\my-credentials.publishsettings'
site appsetting add ASPNET_ENV=Test MyApp 
azure site appsettings list MyApp 

Azure PowerShell

choco install -y windowsazurepowershell 
Get-AzurePublishSettingsFile
Import-AzurePublishSettingsFile '~\Downloads\my-credentials.publishsettings'
$hash = (Get-AzureWebsite -Name "MyApp").AppSettings
$hash.Add("ASPNET_ENV", "Test")
Set-AzureWebsite -Name "MyApp" -AppSettings $hash

As you can see, it is trickier with PowerShell than with the CLI. Note: restart the console window after installing Azure PowerShell.

like image 163
Shaun Luttin Avatar answered Sep 22 '22 09:09

Shaun Luttin