CSharpCodeProvider:为什么调试时会出现断章取义的编译结果
我有以下代码片段,用于在运行时编译类。
//now compile the runner
var codeProvider = new CSharpCodeProvider(
new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
string[] references = new string[]
{
"System.dll", "System.Core.dll", "System.Core.dll"
};
CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.AddRange(references);
parameters.OutputAssembly = "CGRunner";
parameters.GenerateInMemory = true;
parameters.TreatWarningsAsErrors = true;
CompilerResults result = codeProvider.CompileAssemblyFromSource(parameters, template);
每当我单步执行代码来调试单元测试,并尝试查看“结果”的值是什么时,我都会收到一条错误,指出当前上下文中不存在名称“结果”。为什么?
I have following code snippet that i use to compile class at the run time.
//now compile the runner
var codeProvider = new CSharpCodeProvider(
new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
string[] references = new string[]
{
"System.dll", "System.Core.dll", "System.Core.dll"
};
CompilerParameters parameters = new CompilerParameters();
parameters.ReferencedAssemblies.AddRange(references);
parameters.OutputAssembly = "CGRunner";
parameters.GenerateInMemory = true;
parameters.TreatWarningsAsErrors = true;
CompilerResults result = codeProvider.CompileAssemblyFromSource(parameters, template);
Whenever I step through the code to debug the unit test, and I try to see what is the value of "result" I get an error that name "result" does not exist in current context. Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是在发布模式下调试吗?这可能发生在未使用变量的优化上。
例如:
在发布模式下运行时,或者在项目属性中(在构建选项卡下)设置“优化代码”时,会发生代码优化
Are you debugging in release mode? This may happen to optimizations of unused variable.
For example:
Code optimization happens when running in release mode, or when setting "Optimize code" in project properties (under build tab)