【问题标题】:Parsing a Azure cloud services cscfg file using Powershell for Fluent Migrator使用 Powershell for Fluent Migrator 解析 Azure 云服务 cscfg 文件
【发布时间】:2014-04-08 09:20:25
【问题描述】:

我们的云服务有许多云部署项目。例如

\-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,然后将其直接传递给 fluent 迁移器。

【问题讨论】:

    标签: powershell azure configparser fluent-migrator cscfg


    【解决方案1】:

    我假设您将连接字符串存储在 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
        } 
    } 
    

    【讨论】:

    • 非常感谢迈克。那应该让我继续前进。 (真的需要加强我的 powershell-fu)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 2014-11-23
    • 2016-06-12
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多