如何添加引用到动态组件编译另一个动态组件? [英] How to add reference to a dynamic assembly for compiling another dynamic assembly?

查看:211
本文介绍了如何添加引用到动态组件编译另一个动态组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的AppDomain中很少有动态组装,当我尝试
codeDom.CompileAssemblyFromSource
编译另一个新的组装,我不能想出一个办法来增加这些动态组装到ReferencedAssemblies。

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.

先谢谢了。

PS:我实际上是试图使用IronPython的ASP.Net MVC 3的新剃刀模板引擎

PS: I'm actually trying to use ASP.Net MVC 3's new Razor template engine in IronPython.

推荐答案

我有类似的问题,这篇博客文章:
http://geekswithblogs.net/gyoung/archive/2006/04/27 /76533.aspx
使我相信,有没有办法做到这一点。
然而,这是比较老的职位,如果有东西在.NET 4中允许新的,这将是巨大的,了解它。

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.

编辑:

我可以证实,这是不可能的,并与.NET 4. CSHARP codeGenerator类使用CSC.EXE来编译code它使用以下code以添加引用的程序集作为参数给编译器:

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:

foreach (string current in options.ReferencedAssemblies)
{
    stringBuilder.Append("/R:");
    stringBuilder.Append("\"");
    stringBuilder.Append(current);
    stringBuilder.Append("\"");
    stringBuilder.Append(" ");
}

BTW:有在SO另一个职位对同样的问题:

BTW: There are another posts in SO for the same problem:

<一个href=\"http://stackoverflow.com/questions/5640942/supply-assembly-to-compilerparameters-referencedassemblies-from-memory-and-not-d\">Supply从内存和磁盘不大会CompilerParameters ReferencedAssemblies?

<一个href=\"http://stackoverflow.com/questions/454561/in-c-how-do-you-reference-types-from-one-in-memory-assembly-inside-another\">In C#中,你如何从一个引用类型在另一个内存组装?

这篇关于如何添加引用到动态组件编译另一个动态组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆