Force NCover 1.5.8 to use v4 framework like testdriven.net does?

流过昼夜 提交于 2019-12-18 10:37:15

问题


I want to run coverage from the command line, but can't seem to get NCover 1.5.8 to instrument the code. It must be possible as when I run coverage tests with TestDriven.net it works. the difference seems to be that TD.NET is able to get NCover to use framework 4.0 (you get this in the log when it runs : MESSAGE: v4.0.30319) but from the command line I can't make it (I get this in the log : MESSAGE: v2.0.50727)

So how can I make NCover play nice with nunit from the commandline, like it does with TD.NET?


回答1:


after more searching I found this:

If you have found this thread because you are trying to get NCover 1.5.8 to work with .NET 4 then the following should fix this error:

Open a command prompt and type the following set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler

This instructs the .NET 4 CLR to load the .NET Framework 2.0 Profiler.

For more information see: http://msdn.microsoft.com/en-us/library/dd778910.aspx

at the end of the thread here

which seems to solve my problem

EDIT:

it doesn't solve my problem really. Now it just allows the coverage.xml to be generated, but it only contains the v2.0 framework assemblies, so only the .net 2.0 assemblies are profiled....

Grrr. back to the drawing board...

EDIT 2

Hallelujah! I have figured this out by a process of random googling and changing. anyway, due to some pointers found here I was able to figure out that what I needed to do was to alter the exe.config of the application running the code (nunit.console-x86.exe in this case) file to not only force a specific version of the .net framework to be loaded but also to allow the legacy activation policy to be used. To cut a long story short I was able to solve this by:

  • Adding to the nunit-console-x86.exe.config the following section:
<configuration>  
    <startup useLegacyV2RuntimeActivationPolicy="true">  
        <supportedRuntime version="v4.0.30319"/>  
    </startup>  
</configuration>
  • setting these in the environment that the command is launched from:

    set ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
    set COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
    (not sure both are necessary, but that's what I did)

I also added a similar setting to the NCover.Console.Exe.config, but it turns out that is unnecessary.

EDIT 3

this is the command line I am using (note that I copied all of ncover and nunit and my test assemblies into one directory to simplify things)

NCover.Console.exe nunit-console-x86.exe /framework=4.0.30319 Your.Test.Assembly.dll //x coverage.xml //reg




回答2:


I may have misunderstood your problem, but if you're trying to force NCover to run in the .NET 4.0 runtime you can try to place the supportedRuntime element in its configuration file.

<configuration>
  <startup>
    <supportedRuntime version="v4.0.30319"></supportedRuntime>
  </startup>
</configuration>

This will force .NET 4.0 upon the executable without the need to rebuild it.



来源:https://stackoverflow.com/questions/4921443/force-ncover-1-5-8-to-use-v4-framework-like-testdriven-net-does

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!