如何添加对动态程序集的引用以编译另一个动态程序集?

发布于 2024-09-29 11:21:52 字数 385 浏览 2 评论 0原文

当我尝试时,在我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪 2024-10-06 11:21:52

不进行测试,尝试使用assembly.FullName 而不是assembly.Location 。

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

云柯 2024-10-06 11:21:52

我遇到了类似的问题和这篇博文:
http://geekswithblogs.net/gyoung/archive/2006/04/ 27/76533.aspx
让我确信没有办法做到这一点。
然而,这是一个相对较旧的帖子,如果 .net 4 中存在允许这样做的新内容,那么了解它会很高兴。

编辑:

我可以确认这是不可能的,并且使用 .net 4。由于 CSharpCodeGenerator 类使用 csc.exe 来编译代码,它使用以下代码将引用的程序集作为参数添加到编译器:

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

顺便说一句:还有另一篇文章对于同样的问题,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:

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文