应用程序配置文件(file.exe.config)怎么设定程序集位置

CsToD 2009-11-27 09:52:29
在网上查了一下,操作如下:


首先向项目中添加一个配置文件App.config,其内容如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity Name="ClassLibrary1" Culture="neutral" PublicKeyToken="null" />
<codeBase version="1.0.0.0" href="FILE://D:/ClassLibrary1.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
或者换成其它程序集也行,把系统的System.Windows.Forms.dll拷贝出来,然后在配置文件中配置也可以






假如程序的名字为demo.exe(WinForm程序),编译后,会在输出目录产生demo.exe.config文件

但是我通过AppDomain.GetAssemblies发现加载的程序集并非我配置文件中指定的程序集,而是exe所在目录的程序集(或者GAC中的程序集),而且如果我把当前目录的程序集删除,而该程序集又不是GAC的,就会报错;也就是说,配置文件没起到任何作用。

请问到底该怎么弄
...全文
301 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tan124 2009-12-09
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="url:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity Name="ClassLibrary1" Culture="neutral" PublicKeyToken="null" />
<codeBase version="1.0.0.0" href="FILE://D:/ClassLibrary1.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
tan124 2009-12-08
  • 打赏
  • 举报
回复
删掉已有的App.config,在添加App.config
tan124 2009-12-08
  • 打赏
  • 举报
回复
重新配置文件


在用"AppDomain.GetAssemblies() 返回在AppDomain中加载的程序集
exe.config项目实际使用的配置文件
修改app.config反映到exe.config上"这个试试
l171147904 2009-12-07
  • 打赏
  • 举报
回复
UP
悔说话的哑巴 2009-12-01
  • 打赏
  • 举报
回复
?????????、
CsToD 2009-11-30
  • 打赏
  • 举报
回复
up
CsToD 2009-11-29
  • 打赏
  • 举报
回复
up
CsToD 2009-11-28
  • 打赏
  • 举报
回复
up
jnyds 2009-11-27
  • 打赏
  • 举报
回复
关注中……
wuyq11 2009-11-27
  • 打赏
  • 举报
回复
AppDomain.GetAssemblies() 返回在AppDomain中加载的程序集
exe.config项目实际使用的配置文件
修改app.config反映到exe.config上

110,574

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧