gpt4 book ai didi

powershell - 如何使用 xWebConfigKeyValue 设置多个 AppSettings 值?

转载 作者:行者123 更新时间:2023-12-02 23:28:19 25 4
gpt4 key购买 nike

我正在尝试使用 xWebConfigKeyValue DSC 模块资源 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 : The key properties combination 'C:\Company\ManagementPortal::AppSettings' is duplicated for keys 'WebsitePath,ConfigSection' of resource 'xWebConfigKeyValue' in node 'myNode'. Please make sure key properties are unique for each resource in a node. At 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 block 但具有不同的 appSetting 键。那么如何配置多个 appSetting 键呢?

最佳答案

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

我认为您的直接选择是:

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

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

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

    关于powershell - 如何使用 xWebConfigKeyValue 设置多个 AppSettings 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26715911/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com