Visual studio 2010 使用Visual Studio 2010以编程方式生成.coverage文件
我需要以编程方式生成.coverage文件。按如下方式解释执行此操作的C#代码Visual studio 2010 使用Visual Studio 2010以编程方式生成.coverage文件,visual-studio-2010,code-coverage,profiler,Visual Studio 2010,Code Coverage,Profiler,我需要以编程方式生成.coverage文件。按如下方式解释执行此操作的C#代码 using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using Microsoft.VisualStudio.Coverage; using Microsoft.VisualStudio.Coverage.Analysis; // You must add a reference t
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Microsoft.VisualStudio.Coverage;
using Microsoft.VisualStudio.Coverage.Analysis;
// You must add a reference to Microsoft.VisualStudio.Coverage.Monitor.dll
namespace Microsoft.VisualStudio
{
class DumpProgram
{
static void Main(string[] args)
{
Process p = new Process();
StringBuilder sb = new StringBuilder("/COVERAGE ");
sb.Append("hello.exe");
p.StartInfo.FileName = "vsinstr.exe";
p.StartInfo.Arguments = sb.ToString();
p.Start();
p.WaitForExit();
// TODO: Look at return code – 0 for success
// A guid is used to keep track of the run
Guid myrunguid = Guid.NewGuid();
Monitor m = new Monitor();
m.StartRunCoverage(myrunguid, "hello.coverage");
// Complete the run
m.FinishRunCoverage(myrunguid);
不幸的是,当我编译这段代码时,我得到了以下错误
bin2xml.cs(26,22): error CS0246: The type or namespace name 'Monitor' could not be found (are you
missing a using directive or an assembly reference?)
bin2xml.cs(26,38): error CS0246: The type or namespace name 'Monitor' could not be found (are you
missing a using directive or an assembly reference?)
如上所述,VS2008和VS2010之间有一些变化,我认为Monitor类位于不同的名称空间中
可能有什么问题?如何使用Visual Studio 2010以编程方式生成.coverage文件
解决了的
源代码中的code>
它应该是
System.Threading
命名空间的一部分,但在您的情况下不是
更新:这说明了一切覆盖率监视器DLL(Microsoft.VisualStudio.coverage.monitor.DLL
)实际上只是围绕vsperfmon.exe的美化包装。从字面上说,您传入的参数只是成为流程的命令行参数
最简单的解决方案是只使用该类自己运行vsperfmon.exe(类似于您对vsinstr.exe所做的操作)
如果要使用覆盖率监视器DLL,则需要添加对它的引用。有一个32位和64位的vsperfmon.exe(分别用于收集32位和64位进程的代码覆盖率),因此还有一个32位和64位版本的覆盖率监视器DLL
对于VS2010,32位覆盖率监视器DLL位于Microsoft Visual Studio 10.0\Common7\IDE\PrivateSassemblies\DataCollectors\x86
中。64位覆盖率监视器DLL位于Microsoft Visual Studio 10.0\Common7\IDE\PrivateSassemblies\DataCollectors\x64中
如果希望在32位和64位进程上都支持收集,那么如果还希望使用覆盖率监视器DLL(因为覆盖率监视器DLL不是系统无关MSIL),则需要32位和64位版本的收集程序。如果您只是自己创建vsperfmon.exe进程,您只需要一个版本的收集程序即可支持32位和64位进程。看看这些信息是否有帮助@K Ivanov:他指的是代码覆盖率监视器,不是
锁
监视器。是否已将ref添加到Microsoft.VisualStudio.Coverage.monitor。dll@Klvanov:我在C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PrivateSassemblies目录(VS2010终极版)中找不到dll。@克里斯:听起来对于获取.coverage文件来说,编程方法没有那么吸引人,因为人们可以很容易地使用批量方法@克里斯:使用Microsoft.VisualStudio.Coverage.Monitor添加代码>给出了“bin2xml.cs(7,39):错误CS0234:命名空间“Microsoft.VisualStudio.Coverage”中不存在类型或命名空间名称“Monitor”(是否缺少程序集引用?)错误。可能有什么问题?@proseek:您不能对类型使用,您只需要使用命名空间:使用Microsoft.VisualStudio.Coverage代码>然后,监视器
类型应可用。您将希望避免使用System.Threading
因为该名称空间还包含一个监视器
类型。@克里斯:我尝试使用..Coverage
而不使用,但出现了错误。我更新了原来的帖子。您能检查一下吗?@prosseek:对不起,我在这里的评论中弄错了,正确的命名空间用法是使用Microsoft.VisualStudio.CodeOverage代码>。如果在解决方案资源管理器中的程序集引用上单击鼠标右键,则可以选择“在对象浏览器中查看”以查看程序集中定义的名称空间和类型。