2

我正在尝试使用xWebConfigKeyValueDSC 模块的资源xWebAdministration在我们的应用程序的 web.config 文件上设置多个值。这是我们配置的摘录,其中包含围绕 web.config 更改的主要活动:

Configuration C4M
{
    Param(
        [Parameter(Mandatory)]
        [string] $BuildDropLocation
    )

    Import-DscResource -Module xWebAdministration  

    Node $AllNodes.NodeName
    {
        $managementPortalInstallPath = 'c:\Company\ManagementPortal'
        File ManagementPortalContents
        {
            DestinationPath = $managementPortalInstallPath
            SourcePath = "$BuildDropLocation\ManagementPortal"
            Type = 'Directory'
            Recurse = $True
        }

        xWebConfigKeyValue RecaptchaPublicKey
        {
            WebsitePath = $managementPortalInstallPath
            ConfigSection = 'AppSettings'
            Key = 'recaptchaPublicKey'
            Value = $Node.RecaptchaPublicKey
            DependsOn = '[File]ManagementPortalContents'
        }

        xWebConfigKeyValue RecaptchaPrivateKey
        {
            WebsitePath = $managementPortalInstallPath
            ConfigSection = 'AppSettings'
            Key = 'recaptchaPrivateKey'
            Value = $Node.RecaptchaPrivateKey
            DependsOn = '[File]ManagementPortalContents'
        }
    }
}

但是当我尝试运行配置时,出现以下错误:

Add-NodeKeys:键属性组合“C:\Company\ManagementPortal::AppSettings”与节点“myNode”中资源“xWebConfigKeyValue”的键“WebsitePath,ConfigSection”重复。请确保节点中每个资源的关键属性都是唯一的。在 line:160 char:9 + Add-NodeKeys $keyValues $keyNames $keywordName + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Write-Error], InvalidOperationException + FullyQualifiedErrorId : DuplicateKeyInNode,Add-NodeKeys

看到错误后,我查看了模块 schema.mof 文件,并注意到 appSettings 键不是配置的键C:\Program Files\WindowsPowerShell\Modules\xWebAdministration\DSCResources\MSFT_xWebConfigKeyValue\MSFT_xWebConfigKeyValue.schema.mof

[ClassVersion("1.0.0.0"), FriendlyName("xWebConfigKeyValue")]
class MSFT_xWebConfigKeyValue : OMI_BaseResource
{
    [Key, Description("Path to website location(IIS or WebAdministration format)")] String WebsitePath;
    [Key, Description("Config Section to be update"), ValueMap{"AppSettings"}, Values{"AppSettings"}] String ConfigSection;
    [Write, ValueMap{"Present","Absent"}, Values{"Present","Absent"}] String Ensure;
    [Required, Description("Key for AppSettings")] String Key;
    [Write, Description("Value for AppSettings")] String Value;
    [Write, Description("If the given key value pair is for attribute, default is element")] Boolean IsAttribute;
};

由于只有站点路径和配置部分是键,因此我不能有多个资源实例指向同一个 appSettings 块但具有不同的 appSetting 键。那么如何配置多个 appSetting 键呢?

4

1 回答 1

3

您不能在同一配置中配置两个 xWebConfigKeyValue 资源,因为正如您所发现的,资源键仅包含 WebsitePath 和 ConfigSection 属性,并且不区分 Key 属性。

我认为您的直接选择是:

  • 基于xWebConfigKeyValue新建一个cWebConfigKeyValue资源模块,在“cWebConfigKeyValue.schema.mof”中的“Key”属性中添加“Key”属性自行修复。

或者

  • 在单独的配置块中定义冲突资源。我不得不在使用 xService 资源的项目中执行此操作。

这些都不是一个特别好的解决方案,但它可能会解除您的障碍,直到出现更好的解决方案。

于 2014-11-03T14:38:10.743 回答