供应大会从内存CompilerParameters ReferencedAssemblies,而不是磁盘?磁盘、而不是、内存、大会

2023-09-03 02:34:04 作者:孤离

我有,我用它来养活 Microsoft.CSharp.CSharp codeProvider 对象 CompilerParameters 对象和 I codeCompiler 对象,源于这一点。

一切工作正常,我可以飞编译code。我的问题是与引用的程序集。现在,我刚刚从 System.Reflection.Assembly.GetExecutingAssembly()添加所有组件。GetReferencedAssemblies()到编译器参数的 ReferencedAssemblies 。这适用于在硬盘上的文件。不过,我有一个组件,它在内存中,而不是在磁盘上。当我尝试引用它,我得到一个 FileNotFoundException异常这是我期待,因为它是尝试添加不存在的路径。

那么,如何通过在实际组装对象 CompilerParameters.ReferencedAssemblies

我看到几个帖子在网上从2006年和之前说,这是根本不可能的。我希望在.NET 3.5和.NET 4.0这样的事情的支持已被添加,但我不确定。

仅供参考,我使用.NET 4.0

另外,现在我创造的程序空间中的byte []的一个临时文件,然后加载该文件为一个程序集。我知道的编译器这个背景,但毕竟它本身也清理我相信。这将是巨大的,如果我可以这样做:

  CompilerParameters.ReferencedAssemblies.Add(议会一)
 

解决方案

所以,你必须要添加为引用的内存组件?

我不知道,这样的做法是由 CSHARP codeProvider 支持。

I have a CompilerParameters object that I use to feed a Microsoft.CSharp.CSharpCodeProvider object and an ICodeCompiler object that derives from that.

荣耀全场景 计划 打通人货场,连接新宇宙

Everything works OK, and I can compile code on the fly. My problem is with the referenced assemblies. Right now, I just add all assemblies from System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies() into the compiler parameter's ReferencedAssemblies. This works for files on the hard disk. However I have one assembly that is in memory and not on the disk. When I try to reference it, I get a FileNotFoundException which I expect since it is trying to add a path that doesn't exist.

So how do I pass in an actual Assembly object to CompilerParameters.ReferencedAssemblies?

I have seen a few posts online from 2006 and before that say it is simply not possible. I am hoping with .net 3.5 and .net 4.0 the support for this sort of thing has been added, but I am unsure.

FYI, I am using .NET 4.0

Also, right now I am creating a temporary file from the byte[] in program space, then loading that file into an assembly. I know the compiler does this in the background, but it also cleans up after itself I believe. It would be great if I could do:

CompilerParameters.ReferencedAssemblies.Add(Assembly a)

解决方案

So you have in-memory assembly that you want to add as reference?

I'm not sure that such approach is supported by CSharpCodeProvider.