【发布时间】:2013-05-31 05:07:59
【问题描述】:
我有一个演示项目,它创建一个程序集并使用它。我也可以调试注入的代码。但如果我运行覆盖、分析或剖析,它会被计算在内,但我想测量它。
代码:
CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = false;
parameters.GenerateInMemory = false; // debug enabled
parameters.OutputAssembly = "DynamicCode.dll"; // if specified creates the DLL
parameters.IncludeDebugInformation = true;
CompilerResults results = icc.CompileAssemblyFromFile(parameters, "InjectedCode.cs.txt");
我创建 DLL 来检查生成的 IL 代码。我可以在 VS 中调试代码。但是当我运行覆盖时,如果我使用 TEMP 目录,或者如果我输出 DLL(如上) NO FILE 包含在覆盖中(所以甚至不包括主程序集),生成的程序集就会丢失。
当我运行分析时,我只能看到调用(反射),但看不到生成的代码。当我进行分析时(我在注入的代码中有一些错误,例如没有使用本地变量,并且对所有内容进行了 ofc 分析),注入的代码没有报告任何问题。注入代码:
namespace CodeInjection
{
public static class DynConcatenateString
{
public static string Concatenate(string s1, string s2){
// System.Diagnostics.Debugger.Break(); // break here for debugger and also test comment output
int a = 1+2+3+4+5; // complicated math
int b = a+2;
int c = 0;
return s1 + " !"+b+"! " + s2;
}
}
}
我想对生成的代码使用覆盖、分析和分析(主要是覆盖)。
【问题讨论】:
标签: c# .net visual-studio-2012 code-injection dynamic-language-runtime