我有一个Powershell脚本,它加载一个.NET程序集(在我的例子中是.EXE),并调用一个公共方法,该方法使用app.config来提取加密的连接字符串。
该脚本动态地将程序集的exe.config作为powershell.exe.config复制到Powershell ($pshome)文件夹中,并且能够很好地从我的开发箱中运行。问题是它不能从标准的Windows Server2003安装运行。
我已验证exe.config是否已正确复制到powershell目录。我已经运行了SysInternals Process Explorer,并验证了该进程是否正在访问配置文件(没有文件未找到消息)。我远程调试了powershell.exe实例,可以看到程序集加载正常,但无法访问ConfigurationManager.AppSettings...值(返回null)。
我没主意了。我读到过我可以使用单独的应用程序域,但我没有看到使用Powershell这样做的例子。
我的代码做了一些影响如下的事情:
$absolute_path = "c:\foo.exe"
$config_path = $absolute_path + ".config"
copy "$config_path" "$pshome\powershell.exe.config" -Force
[Reflection.Assembly]::LoadFrom($absolute_path)
$foo = new-object MyFooAssembly.FooClass
$foo.DoSomething()
在Vista中代码可以工作,在Windows Server2003中代码不能工作。
https://stackoverflow.com/questions/835862
复制相似问题