MSBuild 运行单元测试

发布于 2024-09-13 13:55:25 字数 1600 浏览 2 评论 0原文

我正在尝试配置 CruiseControl .net 以定期构建我们的存储库代码并运行解决方案中包含的测试。我已经配置了从 svn 服务器和构建部分检索代码。但我无法对其进行测试。 MSBuild 一直在抱怨这一点。

错误 MSB4057:目标“测试”确实 项目中不存在。

我还尝试通过命令行运行测试,看看是否会出现相同的错误。我使用: MSBuild.exe TestProject.csproj /t:Test

我的配置是这样的:

<tasks>
    <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
        <workingDirectory>C:\WorkingDir\build\MainProject</workingDirectory>                
        <projectFile>MainProject.csproj</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
        <targets>Build</targets>
        <timeout>900</timeout>
        <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
    </msbuild>
    <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
        <workingDirectory>C:\WorkingDir\build\TestProject</workingDirectory>                
        <projectFile>TestProject.csproj</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
        <targets>Test</targets>
        <timeout>900</timeout>
        <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
    </msbuild>  
    </tasks>

我将不胜感激任何正确方向的提示。

I am trying to configure CruiseControl .net to build our repository code periodically and run the tests included in the solution. I have configured the retrieving code from the svn server and building part. But I am unable to run tests on it. MSBuild keeps on complaining that.

error MSB4057: The target "Test" does
not exist in the project.

I also tried running the tests through command line to see if that works with the same error. I used: MSBuild.exe TestProject.csproj /t:Test

My configuration is something like this:

<tasks>
    <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
        <workingDirectory>C:\WorkingDir\build\MainProject</workingDirectory>                
        <projectFile>MainProject.csproj</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
        <targets>Build</targets>
        <timeout>900</timeout>
        <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
    </msbuild>
    <msbuild>
        <executable>C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>
        <workingDirectory>C:\WorkingDir\build\TestProject</workingDirectory>                
        <projectFile>TestProject.csproj</projectFile>
        <buildArgs>/noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
        <targets>Test</targets>
        <timeout>900</timeout>
        <logger>C:\Program Files (x86)\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>
    </msbuild>  
    </tasks>

I would appreciate any hint in the right direction.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纸短情长 2024-09-20 13:55:25

您还没有解释您正在使用什么测试框架,这在这里非常关键。

对于 MSTest,此调用内容是 TFS 的一部分 [因为运行程序内容是 TFS 的一部分Visual Studio 的一部分,这就是为什么运行 MSTest 的任务不能成为 MSBuild 的一部分,而 MSBuild 是 .NET Framework 的一部分——这也是为什么 MSTest 强制 [在 2010 年,是] Visual Studio 的一个子集安装在您的计算机上。构建服务器(关于该主题有很多问题)]

对于 xUnit.net,人们会做这样的事情

对于 NUnit,有一个任务,您可以向其提供文件列表。

底线 - 将测试自定义目标添加到 .csproj 文件中,该文件会触发显着的 MSBuild 包装器任务来调用测试运行程序。

You havent explained what test framework you're using, which is pretty key here.

For MSTest, this invocation stuff is part of TFS [as the runner stuff is part of Visual Studio, which is why a Task to run MSTest can not be part of MSBuild, which is part of the .NET Framework -- this is also why MSTest forces [in 2010, a subset of] Visual Studio to be installed on your build server (there are a good few questions around here on that topic)]

For xUnit.net, people do stuff like this

For NUnit there's a task that you can supply a list of files to.

Bottom line - one adds a Test custom target to a .csproj file which triggers the salient MSBuild wrapper task for invoking your test runner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文