如何调试/在codeDOM突破编译code [英] How to debug/break in codedom compiled code
问题描述
我有一个动态加载了C#源文件并运行它们作为插件应用程序。当我运行在调试模式下的主要应用,它是可以调试到动态组件?显然,设置断点是有问题的,因为源已经不是原来计划的一部分,但我应该能够进入,或打破了code?
例外有没有办法让codeDOM产生PDBS这个东西?
下面是code我使用了动态compliation。
CSHARP codeProvider codeProvider =新CSHARP codeProvider(新字典<字符串,字符串>(){{CompilerVersion,V3.5} });
// codeProvider。
I codeCompiler ICC = codeProvider.CreateCompiler();
CompilerParameters参数=新CompilerParameters();
parameters.GenerateExecutable = FALSE;
parameters.GenerateInMemory = TRUE;
parameters.CompilerOptions =的String.Format(/ lib目录下:\{0} \,Application.StartupPath);
parameters.ReferencedAssemblies.Add(System.dll中);
parameters.ReferencedAssemblies.Add(System.Core.dll的);
CompilerResults结果= icc.CompileAssemblyFromSource(参数来源);
DLL.CreateInstance(t.FullName,假的,BindingFlags.Default,空,新的对象[] {}引擎,NULL,NULL);
请尝试以下选项:
parameters.GenerateInMemory = FALSE; //默认
parameters.TempFiles =新TempFileCollection(Environment.GetEnvironmentVariable(TEMP),真正的);
parameters.IncludeDebugInformation = TRUE;
我不知道,如果这个工程确定你的情况,但如果这样做,就可以围绕这个参数与条件编译指令,以便它转储仅在调试模式下生成的程序集。
I have an application which loads up c# source files dynamically and runs them as plugins. When I am running the main application in debug mode, is it possible to debug into the dynamic assembly? Obviously setting breakpoints is problematic, since the source is not part of the original project, but should I be able to step into, or break on exceptions for the code?
Is there a way to get codedom to generate PDBs for this or something?
Here is the code I am using for dynamic compliation.
CSharpCodeProvider codeProvider = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
//codeProvider.
ICodeCompiler icc = codeProvider.CreateCompiler();
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = false;
parameters.GenerateInMemory = true;
parameters.CompilerOptions = string.Format("/lib:\"{0}\"", Application.StartupPath);
parameters.ReferencedAssemblies.Add("System.dll");
parameters.ReferencedAssemblies.Add("System.Core.dll");
CompilerResults results = icc.CompileAssemblyFromSource(parameters, Source);
DLL.CreateInstance(t.FullName, false, BindingFlags.Default, null, new object[] { engine }, null, null);
Try the following options:
parameters.GenerateInMemory = false; //default
parameters.TempFiles = new TempFileCollection(Environment.GetEnvironmentVariable("TEMP"), true);
parameters.IncludeDebugInformation = true;
I am not sure if this works OK in your case, but if it does, you can surround this parameters with conditional compilation directive, so that it dumps the generated assembly only in debug mode.
这篇关于如何调试/在codeDOM突破编译code的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!