PowerShell App.Config [英] PowerShell App.Config
问题描述
有人解决过如何使PowerShell使用 app.config
文件吗?我想在一个脚本中使用几个.NET DLL,但他们希望在 app.config
/ <$ c中出现自己的配置节。 $ c> web.config 。
Has anyone worked out how to get PowerShell to use app.config
files? I have a couple of .NET DLL's I'd like to use in one of my scripts but they expect their own config sections to be present in app.config
/web.config
.
推荐答案
该线程的交叉引用对我有帮助相同的问题:
通过Powershell脚本中引用的DLL对App.Config连接字符串进行亚音速访问
Cross-referencing with this thread, which helped me with the same question: Subsonic Access To App.Config Connection Strings From Referenced DLL in Powershell Script
在调用需要配置设置的DLL之前,我在脚本中添加了以下内容, $ configpath是我要加载的文件的位置:
I added the following to my script, before invoking the DLL that needs config settings, where $configpath is the location of the file I want to load:
[appdomain]::CurrentDomain.SetData("APP_CONFIG_FILE", $configpath)
Add-Type -AssemblyName System.Configuration
请参见此帖子确保将指定的配置文件应用于正在运行的上下文。
See this post to ensure the configuration file specified is applied to the running context.
这篇关于PowerShell App.Config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!