积极答复者
winform程序.exe和dll分开

问题
-
用c# 写的winform 工具,如果将.exe和dll分开.也就是说,这个工具可以把所有文件放在同一目录里可以正常运行,还要保证.将引用的dll放在bin目录里也可以运行.查了资料
在app.config 设置
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<publisherPolicy apply="yes"/>
<probing privatePath="bin"/>
</assemblyBinding>
</runtime>
</configuration>不给力啊,当把引用dll放在bin目录里,运行无法加载XX程序集
啥叫乐观-得瑟的最高境界
答案
-
方法是正确的,您设置好了 app.config 后重新编译了吗?默认情况下 CLR 会从当前目录,本地化资源目录、FirstAssemblies 等三个地方顺序搜索引用的 dll,如果没有找到,才会抛出 FileNotFoundException 的。请确认编译好后的 *.exe.config 文件中的内容和 app.config 中的内容一致。
Mark Zhou
是的编译了.最后在Program Main函数自己解决AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "bin;");
var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "bin" });
啥叫乐观-得瑟的最高境界- 已标记为答案 极度 2011年2月17日 1:24
全部回复
-
方法是正确的,您设置好了 app.config 后重新编译了吗?默认情况下 CLR 会从当前目录,本地化资源目录、FirstAssemblies 等三个地方顺序搜索引用的 dll,如果没有找到,才会抛出 FileNotFoundException 的。请确认编译好后的 *.exe.config 文件中的内容和 app.config 中的内容一致。
Mark Zhou
是的编译了.最后在Program Main函数自己解决AppDomain.CurrentDomain.SetData("PRIVATE_BINPATH", "bin;");
var m = typeof(AppDomainSetup).GetMethod("UpdateContextProperty", BindingFlags.NonPublic | BindingFlags.Static);var funsion = typeof(AppDomain).GetMethod("GetFusionContext", BindingFlags.NonPublic | BindingFlags.Instance);
m.Invoke(null, new object[] { funsion.Invoke(AppDomain.CurrentDomain, null), "PRIVATE_BINPATH", "bin" });
啥叫乐观-得瑟的最高境界- 已标记为答案 极度 2011年2月17日 1:24
-
您好,极度:
感谢您分享您的解决方案。
如果您有任何问题,请随时向我们提出。MSDN团队感谢您的参与。
Neddy Ren [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.