How to add reference to a dynamic assembly for compiling another dynamic assembly?

ぐ巨炮叔叔 提交于 2019-12-08 00:37:22

问题


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.


回答1:


Not test, try use assembly.FullName instead of assembly.Location.




回答2:


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:

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

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?



来源:https://stackoverflow.com/questions/4040825/how-to-add-reference-to-a-dynamic-assembly-for-compiling-another-dynamic-assembl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!