我有一个演示项目,它创建一个程序集并使用它。我也可以调试注入的代码。但是,如果我运行覆盖,分析或分析,它会被计算,但我想测量它。动态生成代码的代码覆盖率,分析和性能分析
代码:
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(如上所述),那么生成的程序集就会错过,而且覆盖范围内没有FILE(甚至不包括主程序集)。
当我运行分析时,我只能看到调用(反射),但没有关于生成的代码。当我进行分析时(我在注入的代码中有一些错误,例如没有使用过的本地代码,以及对所有东西都进行了分析),注入的代码没有报告任何问题。注入的代码:
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;
}
}
}
我想对生成的代码(主要是覆盖率)使用coverage,分析和分析。
也跳过了(这是我跳过代码覆盖后的第一次尝试)。此外jetbrains封面和其他工具错过。现在我正在更深入地讨论这个话题,希望下周会有结果,所以我会寄到这里。请评价我的问题,不管你认为它是否有用。 – cseppento