简体   繁体   English

通过恢复NuGet包在控制台上运行Nunit

[英]Running Nunit on console through restoring NuGet Package

I am currently working on a project in C#, and trying to get NUnit to run on my project in a Jenkins Build through restoring the package in NuGet. 我目前正在使用C#开发一个项目,并尝试通过在NuGet中恢复包来让NUnit在Jenkins Build中运行我的项目。 We do not want to install NUnit on all of our Jenkins machines so installing it directly on the box is not an option. 我们不想在所有Jenkins机器上安装NUnit,因此不能直接在盒子上安装它。

We've investigated the use of NUniter Runners as suggested in this link: https://peteris.rocks/blog/running-nunit-with-msbuild-on-windows-and-mono/ 我们已经按照以下链接的建议调查了NUniter Runners的使用: https ://peteris.rocks/blog/running-nunit-with-msbuild-on-windows-and-mono/

But, we receive an error that the tools do not exist "C:\\Users\\Name\\NewBranch\\project\\project.Tests\\project.Tests.csproj(121,3): error MSB6003 : The specified task executable "cmd.exe" could not be run. The working directory "C:\\Users\\Name\\NewBranch\\project\\ packages\\NUnit.Runners.3.4.1\\tools" does not exist." 但是,我们收到一个错误,工具不存在“C:\\ Users \\ Name \\ NewBranch \\ project \\ project.Tests \\ project.Tests.csproj(121,3):错误MSB6003:指定的任务可执行文件”cmd.exe “无法运行。工作目录”C:\\ Users \\ Name \\ NewBranch \\ project \\ packages \\ NUnit.Runners.3.4.1 \\ tools“不存在。”

How do I execute NUnit tests from the command line without having NUnit installed directly on the machine? 如何在命令行中执行NUnit测试而不直接在机器上安装NUnit?

the easiest way is to dump there 2 lines in the packages.config which should be in the same folder as your project.Tests.csproj 最简单的方法是在packages.config中转储2行,这些行应与project.Tests.csproj位于同一文件夹中

<package id="NUnit" version="2.6.4" targetFramework="net45" />
<package id="NUnit.Runners" version="2.6.4" />

Assuming you have a target in your .csproj which is like this: 假设你的.csproj中有一个目标是这样的:

<Target Name="NugetRestore">    
    <Exec Command="nuget.exe restore" />
</Target>

if you use a solution level build.config, then add this instead 如果您使用解决方案级别build.config,则添加此项

<Target Name="NugetRestore">    
    <Exec Command="nuget.exe restore $(YourSolution).sln" />
</Target>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM