CppCodeProvider,CompileAssemblyFromFile抛出System.NotImplementedException

时间:2010-12-15 08:29:27

标签: c# .net c++-cli codedom

使用框架CodeDom类编译C ++ / CLI的文档有点缺乏。

背景:我正在尝试为我编写的一个软件编写系统测试。该软件生成代码,我想测试代码是否可以编译,以及编译的代码是否按预期工作。

要编译和测试的代码驻留在几个源文件中。我想将源文件编译成程序集,然后动态调用其中的方法。我已经尝试过使用相同的C#源代码,并且我在几分钟内完成了成功的构建和测试。 C ++编译器总是抛出System.NotImplementedException。

这是吹嘘我的代码:

namespace CppCompilerTest {
    class Program {
        static void Main(string[] args) {
            try {
                string strSourceDir = @"D:\Projects\CppCompilerTest\CppSource";

                using (var codeProvider = new CppCodeProvider7()) {
                    var options = new CompilerParameters { GenerateExecutable = false, GenerateInMemory = false };
                    options.ReferencedAssemblies.Add("System.dll");
                    CompilerResults results = codeProvider.CompileAssemblyFromFile(
                        options,
                        new[] {
                            Path.Combine(strSourceDir, "SourceFile1.cpp"),
                            Path.Combine(strSourceDir, "SourceFile2.cpp")                               
                        }
                    );
                }
            } catch(Exception ex) {
                Console.WriteLine(ex);
            }

            Console.WriteLine("Press any key to continue");
            Console.ReadKey();
        }
    }
}

我完全忽视了什么吗?我想知道cl.exe方式是否可能是更快的路径......

0 个答案:

没有答案