2016-11-02 46 views
0

我需要能夠在已部署的Azure Web App中修改appsettings.json中的設置。如何通過部署的Azure Web App中的PowerShell訪問appsettings.json?

我可以通過下面的命令通過PowerShell中訪問的AppConfig和的ConnectionStrings:

$webApp = Get-AzureRmWebApp -ResourceGroupName $resourceGroupName -Name $websiteName 
$webApp.SiteConfig.AppSettings 
$webApp.SiteConfig.ConnectionStrings 

但是,是否有可能通過PowerShell來訪問appsettings.json?

+0

你可以,但後來你會讀/寫作爲部署的一部分的文件。你確定你想要這樣做,這不會被推薦爲最佳做法嗎?我不完全確定你想要做什麼,但我不能想到有一個腳本更新靜態配置文件部署後的任何好理由。如果你能告訴我們用例是什麼,也許我們可以建議一個更好的方法來實現你的目標。 –

回答

0

據我所知,您可以在您的Azure Web App中添加應用程序設置以覆蓋appsettings.json文件中的配置值。我認爲你appsettings.json文件看起來像這樣:

{ 
    "OAuth": { 
    "ApiKey": "ApiKey", 
    "ApiSecret":"ApiSecret" 
    } 
} 

然後,你可以按照下面的腳本來修改您的設置:

$resourceGroupName="<your-resource-group-name>" 
$websitename="<your-web-app-name>" 
$webApp = Get-AzureRmWebApp -ResourceGroupName $resourceGroupName -Name $websitename 
$appsettingList=$webApp.SiteConfig.AppSettings 

#current appsettings 
$appsettingList 

$appsettings = @{} 
ForEach ($k in $appsettingList) { 
    $appsettings[$k.Name] = $k.Value 
} 

#modify the settings 
$appsettings['OAuth:ApiKey'] = "<new-api-key>" 
$appsettings['OAuth:ApiSecret'] = "<new-api-secret>" 

#save appsettings 
set-AzureRmWebApp -resourcegroupname $resourceGroupName -name $websitename -appsettings $appsettings 
+0

感謝您的回覆。不幸的是,SiteConfig.AppSettings似乎只返回通過Azure Portal定義的應用程序設置。在本地開發時,我對appSettings.json所做的任何自定義添加都無法通過上述方法在網站發佈後提供。任何想法如何獲得他們的訪問? – David