.net-4.0 – 使用CurrentDomain.SetData(“APP_CONFIG_FILE”)在
发布时间:2020-12-13 20:44:52 所属栏目:Windows 来源:网络整理
导读:我试图在PowerShell ISE中使用.NET 4.0程序集,并尝试更改通过以下方式使用的配置文件: [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$PathToConfig); [Configuration.ConfigurationManager] :: ConnectionStrings.Count始终返回“1”,“[C
我试图在PowerShell ISE中使用.NET 4.0程序集,并尝试更改通过以下方式使用的配置文件:
[System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$PathToConfig); [Configuration.ConfigurationManager] :: ConnectionStrings.Count始终返回“1”,“[Configuration.ConfigurationManager] :: ConnectionStrings [0] .Name”始终返回“LocalSqlServer”,并且该ConnectionString名称不在我的“.config”中文件. 请注意,从PowerShell命令提示符执行PowerShell脚本将按预期运行.就在我从PowerShell ISE中执行它时,它无法按预期工作.
这是因为PowerShell ISE的app.config路径已经加载并缓存,因此之后更改app.config路径不会产生任何影响:
stackoverflow.com/q/6150644/222748 这是一个示例脚本,它将清除缓存路径,以便它在PowerShell ISE下工作: [System.AppDomain]::CurrentDomain.SetData("APP_CONFIG_FILE",$PathToConfig) Add-Type -AssemblyName System.Configuration [Configuration.ConfigurationManager].GetField("s_initState","NonPublic,Static").SetValue($null,0) [Configuration.ConfigurationManager].GetField("s_configSystem",$null) ([Configuration.ConfigurationManager].Assembly.GetTypes() | where {$_.FullName -eq "System.Configuration.ClientConfigPaths"})[0].GetField("s_current",$null) [Configuration.ConfigurationManager]::ConnectionStrings[0].Name (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
推荐文章
站长推荐
- Windows Server 2012 Standard – Windows应用商
- windows-server-2008 – 将AD从2003 32bit迁移到
- 热部署.net程序集
- YAPI windows 二次开发 树形结构 多层级结构 拖拽
- 如何在Windows 10通用应用程序中获取C#中的本地主
- windows7下安装php的imagick和imagemagick扩展教
- VBox共享文件夹中的符号链接的Windows问题
- 记录 – Windows中的Nginx $request_time和$upst
- windows-xp – 找到瓶颈:Windows XP上的磁盘I /
- 安装程序 – 我需要一个安装我的软件和先决条件的
热点阅读