CppCodeProvider、CompileAssemblyFromFile 抛出 System.NotImplementedException
使用框架 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 方式是否是更快的路线......
The documentation for compiling C++/CLI using the frameworks CodeDom classes is somewhat lacking.
The background: I'm trying to write system tests for a piece of software I have written. The software generates code, and I want to test that the code can be compiled, and that the compiled code works as intended.
The code to be compiled and tested resides in a couple of source files. I want to compile the source file into an assembly, and then dynamically invoke the methods in it. I have experimented with doing the same C# sources, and I had a successful build and test in minutes. The C++ compiler always throws System.NotImplementedException.
Here's the code that blows up on me:
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();
}
}
}
Have I totally overlooked something? I'm wondering if maybe the cl.exe way is the faster route...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论