我正在尝试配置 CruiseControl .net 以定期构建我们的存储库代码并运行解决方案中包含的测试。我已经配置了从 svn 服务器和构建部分检索代码。但我无法对其进行测试。 MSBuild 一直在提示这一点。
error MSB4057: The target "Test" does not exist in the project.
我还尝试通过命令行运行测试,看看是否会出现相同的错误。我使用: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>
如果有任何正确方向的提示,我将不胜感激。
最佳答案
您还没有解释您正在使用的测试框架,这在这里非常关键。
对于 MSTest,这个调用内容是 part of TFS [由于运行程序是 Visual Studio 的一部分,这就是为什么运行 MSTest 的任务不能成为 MSBuild 的一部分,而 MSBuild 是 .NET Framework 的一部分——这也是 MSTest 强制[在 2010 年的子集]的原因Visual Studio 将安装在您的构建服务器上(这里有一些关于该主题的问题)]
For xUnit.net, people do stuff like this
对于 NUnit,您可以向一个任务提供文件列表。
底线 - 将测试自定义目标添加到 .csproj 文件,该文件会触发显着的 MSBuild 包装器任务来调用测试运行程序。
关于MSBuild 运行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3463570/