2014-04-08 1 views
0

Cloud Services를위한 여러 가지 Cloud Deployment 프로젝트가 있습니다. 예 :Fluent Migrator 용 Powershell을 사용하여 Azure 클라우드 서비스 cscfg 파일 구문 분석

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

등등. 각 cscfg 파일에는 특정 환경에 대한 데이터베이스 연결 문자열이 있습니다.

클라우드 프로젝트를 배포하는 동안 azure cmdlet을 실행하여 &이 클라우드 서비스를 시작하는 powershell 스크립트를 실행합니다.

지금 환경 데이터베이스에 대해 FluentMigrator를 실행하려면 단계를 추가하고 싶습니다. 필자는 이전에 FM을 사용하여 변환 된 Web.Config에서 SQL 연결 문자열을 얻으려고했지만 작동하지는 못했습니다.

CSCFG 파일을 열고 수동으로 ConnectionString을 ps $ var로 구문 분석 한 다음 유창한 마이그레이션 프로그램에 직접 전달할 수있는 powershell 스크립트를 사용하여 올바른 방향으로 나를 안내 할 수 있습니까?

답변

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에 정말 뼈다귀가 필요하다) –

관련 문제