2014-04-08 29 views
0

我們爲我們的雲服務部署了多個雲部署項目。例如使用PowerShell for Fluent Migrator解析Azure雲服務cscfg文件

\-Project.Cloud.UAT 
    \-ServiceConfiguration.Cloud.cscfg 
    \-ServiceDefinition.csdef 
\-Project.Cloud.Production 
    \-ServiceConfiguration.Cloud.cscfg 
    \-ServiceDefinition.csdef 

等等。每個cscfg文件都具有該特定環境的數據庫連接字符串。

在部署雲項目期間,我們運行一個powershell腳本,它啓動Azure cmdlet以部署&啓動該雲服務。

我想現在添加一個步驟,同時針對該環境數據庫運行FluentMigrator。我以前使用FM,並將其指向轉換的Web.Config以獲取SQL連接字符串,但似乎無法使其工作。

有人可以用PowerShell腳本指向正確的方向打開CSCFG文件,手動將ConnectionString解析成ps $ var,然後直接將它傳遞給流利的遷移器。

回答

3

我假設你在ConfigurationSettings部分中存儲連接字符串。下面是PowerShell的一個示例,它將拉入文件併爲每個角色提取switch語句中指定的特定設置。如果你有一個連接字符串,你可能不需要switch語句。處理設置本身也可能有更好的方式,但這確實給了你一個從cscfg文件中手動提取特定設置的例子。

$deploymentCloudConfigPath = "somePathToTheFile\ServiceConfiguration.Cloud.cscfg" 

# Update the cscfg file to include the correct settings. 
[Xml]$cscfgXml = Get-Content $deploymentCloudConfigPath 
Foreach ($role in $cscfgXml.ServiceConfiguration.Role) 
{ 
    Foreach ($setting in $role.ConfigurationSettings.Setting) 
    { 
     Switch ($setting.name) 
     { 
      "CustomSettingsName.StorageAccount" {$connString = $setting.value} #Storage 
      "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" {$connString = $setting.value} #Diagnostics 
     } 

     #Here you can do whatever with the value. 
     $connString 
    } 
} 
+0

非常感謝邁克。這應該讓我去。 (真的需要對我的powershell-fu進行調整) –