如何添加对动态程序集的引用以编译另一个动态程序集?
当我尝试时,在我的 AppDomain 中几乎没有动态程序集 codeDom.CompileAssemblyFromSource 要编译另一个新程序集,我无法找到将这些动态程序集添加到 ReferencedAssemblies 的方法。
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { compilerParameters.ReferencedAssemblies.Add(assembly.Location); }
失败,因为动态程序集没有位置。
提前致谢。
PS:我实际上正在尝试在 IronPython 中使用 ASP.Net MVC 3 的新 Razor 模板引擎。
In my AppDomain there are few dynamic assembly, when I try
codeDom.CompileAssemblyFromSource
to Compile another new assembly, I can't figure out a way to add those dynamic assemble to ReferencedAssemblies.
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { compilerParameters.ReferencedAssemblies.Add(assembly.Location); }
Failed, as dynamic assembly doesn't have Location.
Thanks in advance.
PS: I'm actually trying to use ASP.Net MVC 3's new Razor template engine in IronPython.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不进行测试,尝试使用
assembly.FullName 而不是
assembly.Location 。
Not test, try use
assembly.FullName
instead ofassembly.Location
.我遇到了类似的问题和这篇博文:
http://geekswithblogs.net/gyoung/archive/2006/04/ 27/76533.aspx
让我确信没有办法做到这一点。
然而,这是一个相对较旧的帖子,如果 .net 4 中存在允许这样做的新内容,那么了解它会很高兴。
编辑:
我可以确认这是不可能的,并且使用 .net 4。由于 CSharpCodeGenerator 类使用 csc.exe 来编译代码,它使用以下代码将引用的程序集作为参数添加到编译器:
顺便说一句:还有另一篇文章对于同样的问题,SO:
将程序集提供给 CompilerParameters ReferencedAssemblies来自内存而不是磁盘?
在 C# 中,如何引用另一个内存中程序集中的类型?
I was having similar issue and this blog post:
http://geekswithblogs.net/gyoung/archive/2006/04/27/76533.aspx
convinced me that there is no way to do this.
However this is relatively old post and if there is something new in .net 4 which allow this would be great to know about it.
EDIT:
I can confirm that this is not possible and with .net 4. As CSharpCodeGenerator class is using csc.exe to compile your code it uses the following code to add the referenced assemblies as parameters to the compiler:
BTW: There are another posts in SO for the same problem:
Supply Assembly to CompilerParameters ReferencedAssemblies from memory and not disk?
In C#, how do you reference types from one in-memory assembly inside another?