C#CompileAssemblyFromSource,添加需要的引用程序集吗? [英] C# CompileAssemblyFromSource, add referenced assemblies it needs?
问题描述
我让CompileAssemblyFromSource处理仅引用我的程序(对其进行编译)使用的程序集的代码.它工作得很漂亮.
I have the CompileAssemblyFromSource working for code that only references assemblies that my program (that compiles it) uses. It works beautifully.
但是,如果我需要编译具有"using blah"的代码;声明,它将无法找到等等,并说它缺少资源.
However, if I need to compile code that has a "using blah;" statement, it won't be able to find blah and say it is missing a resource.
因此,如果它是"System.Windows.Forms",并且我说"compilerparams.ReferencedAssemblies.Add("System.Windows.Forms.dll")",则它可以工作.
So if it is "System.Windows.Forms", and I say "compilerparams.ReferencedAssemblies.Add("System.Windows.Forms.dll")", it works.
因此,我可以解析代码文件并获取所有使用"参数,但是我怎么知道这些参数应该是添加的"* .dll",或者它们是其他地方的命名空间呢?.NET是否有一种方法可以接收"System.Windows.Forms"并吐出"System.Windows.Forms.dll",因为这是必需的,依此类推?
So I can parse the code file and get all the "using" parameters, but how do I know that those are supposed to be "*.dll" adding, or they are namespaces elsewhere or whatnot? Is there a way for .NET to take in "System.Windows.Forms" and spit back out "System.Windows.Forms.dll" because that's what it needs and so on?
推荐答案
- 阅读文章运行时如何定位程序集
- 在编译代码之前,加载在第1点提到的位置中找到的所有程序集
- 加载所有程序集中的所有类型,并保留一个命名空间字典,键入pair
- 在源代码中遇到using时,请尝试从3中的字典中添加程序集的引用.
这篇关于C#CompileAssemblyFromSource,添加需要的引用程序集吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!