通过Powershell修改.Net Applications.exe.config文件设置值
我有一个.Net控制台应用程序,它有一个App.Config/myapplicationsole.exe.Config文件。这一个包含通过VS属性管理器设置的设置,基本上如下所示:通过Powershell修改.Net Applications.exe.config文件设置值,powershell,app-config,Powershell,App Config,我有一个.Net控制台应用程序,它有一个App.Config/myapplicationsole.exe.Config文件。这一个包含通过VS属性管理器设置的设置,基本上如下所示: <?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="applicationSettings" type="System.Configuration.Applicati
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="My.Applications.Namespace.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<My.Applications.Namespace.Properties.Settings>
<setting name="SettingsKeyABC" serializeAs="String">
<value>SomeOtherValue</value>
</setting>
<setting name="SettingsKeyXYZ" serializeAs="String">
<value>True</value>
</setting>
</Siemens.Med.CTE.PMP.Applications.JobExecutor.Properties.Settings>
</applicationSettings>
<system.diagnostics>
<trace>
<listeners>
<add name="Gibraltar" type="Gibraltar.Agent.LogListener, Gibraltar.Agent" />
</listeners>
</trace>
</system.diagnostics>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>
其他价值
真的
现在我想要/需要做的是修改“setingskeyxyz”设置的(“True”)值,最好是通过powershell(如我同事所设置的)。有人知道怎么做吗?我发现的只是Web.Configs的示例,它似乎与VS创建的示例略有不同。首先,xml文本无效。第10行标记(My.Applications.Namespace.Properties.Settings)的结束标记在哪里。我更改了第10行以匹配结束标记 加载文件(作为xml),必须将“My.Applications.Namespace.Properties.Settings”标记放在引号中,否则powershell将尝试将点之间的每个值作为标记进行解析),将该值更新为False,然后保存该文件
[xml]$xml = Get-Content c:\App.Config
$xml.configuration.applicationSettings.'My.Applications.Namespace.Properties.Settings'.setting.value='False'
$xml.Save('c:\App.Config')
xml文本无效。第10行标记(My.Applications.Namespace.Properties.Settings)的结束标记在哪里Shay,感谢您调整我的问题文本。关于您的答案:我不知道您是如何访问“setingskeyxyz”设置的(因为可能会有更多)。我该怎么做?您想将“SettingsKeyXYZ”更改为其他内容吗?哦,不,我已经更新了上面的示例-我可能有几个节点,它们由name='SomeKey'属性标识&我只想更新一个特定节点的-Node,在本例中,具有name='SettingsKeyXYZ'属性的对象。$xyz=$xml.configuration.applicationSettings.My.Applications.Namespace.Properties.Settings.Settings.Settings | Where Object{$\ uu.name-eq'SettingsKeyXYZ'};现在,您可以通过$xyz变量访问其属性