dotnet nbench
失败并显示以下日志。
❯ dotnet nbench
Building for framework netcoreapp2.1...
Benchmark.SimepleOneway.Local -> /SolutionDir/ProjectDir/bin/Release/netcoreapp2.1/Benchmark.SimepleOneway.Local.dll
Running .NET Core 2.1 tests for framework netcoreapp2.1...
OutputDir /SolutionDir/ProjectDir/PerfResults
The specified framework version '2.1' could not be parsed
The specified framework 'Microsoft.NETCore.App', version '2.1' was not found.
- Check application dependencies and target a framework version installed at:
/usr/local/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
- The following versions are installed:
2.0.9 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
2.1.3 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
2.1.5 at [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
@HIPERCUBE这可能是您的环境问题 - 但让我仔细检查一下。
您的项目中是否有global.json
或任何指定运行时版本的内容?
可以确认使用 dotnet core 2.1 运行 NBench 的问题
The specified framework version '2.1' could not be parsed
The specified framework 'Microsoft.NETCore.App', version '2.1' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
- The following versions are installed:
2.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.1 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.3-servicing-26724-03 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
2.1.5 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
我没有gloabl.json
文件,其他 2.1 项目运行良好。 我还安装了 2.1 运行时来仔细检查是否存在版本不匹配,但它仍然无法正常工作。
如果有任何帮助,我发现在我的 .csproj 中添加<RuntimeFrameworkVersion>2.1.5</RuntimeFrameworkVersion>
解决了这个问题(他们在这里列出的解决方案归功于@Rene-Sackers:https://github.com/dotnet/cli/issues/ 10111#issuecomment-429014700)。
据我所知,这似乎是dotnet
CLI 的一个问题 - 查看一些相关的问题等。 此处写出的错误不是来自 NBench - 它们来自dotnet
进程,该进程由dotnet-nbench
生成以执行测试运行程序。
我觉得问题的根本原因可能是我们调用dotnet
进程的方式,使用我们从 ASP.NET Core 导入的这个DotNetMuxer
类:
我创建了一个复制项目: https :
当我在那里的示例项目上调用dotnet build
然后dotnet nbench
时,我得到以下输出:
λ dotnet nbench
Building for framework netcoreapp2.1...
NBenchRepro -> C:\Repositories\NBenchNetCore2.1Repro\NBenchRepro\bin\Release\netcoreapp2.1\NBenchRepro.dll
Running .NET Core 2.1.0 tests for framework netcoreapp2.1...
OutputDir C:\Repositories\NBenchNetCore2.1Repro\NBenchRepro\PerfResults
Executing Benchmarks in C:\Repositories\NBenchNetCore2.1Repro\NBenchRepro\bin\Release\netcoreapp2.1\NBenchRepro.dll
------------ STARTING NBenchRepro.CounterPerfSpecs+Benchmark ----------
--------------- BEGIN WARMUP ---------------
Elapsed: 00:00:00.1657419
[Counter] TestCounter - operations: 25,439,744.00 ,operations: /s 153,490,119.28 , ns / operations: 6.52
--------------- END WARMUP ---------------
--------------- BEGIN WARMUP ---------------
Elapsed: 00:00:00.1663968
[Counter] TestCounter - operations: 25,439,744.00 ,operations: /s 152,886,017.04 , ns / operations: 6.54
--------------- END WARMUP ---------------
--------------- BEGIN WARMUP ---------------
Elapsed: 00:00:00.1670527
[Counter] TestCounter - operations: 25,439,744.00 ,operations: /s 152,285,739.77 , ns / operations: 6.57
--------------- END WARMUP ---------------
--------------- BEGIN RUN ---------------
Elapsed: 00:00:00.1659459
[Counter] TestCounter - operations: 25,439,744.00 ,operations: /s 153,301,431.37 , ns / operations: 6.52
--------------- END RUN ---------------
--------------- BEGIN RUN ---------------
Elapsed: 00:00:00.1654938
[Counter] TestCounter - operations: 25,439,744.00 ,operations: /s 153,720,223.96 , ns / operations: 6.51
--------------- END RUN ---------------
--------------- BEGIN RUN ---------------
Elapsed: 00:00:00.1651669
[Counter] TestCounter - operations: 25,439,744.00 ,operations: /s 154,024,468.58 , ns / operations: 6.49
--------------- END RUN ---------------
--------------- RESULTS: NBenchRepro.CounterPerfSpecs+Benchmark ---------------
Test to ensure that a minimal throughput test can be rapidly executed.
--------------- DATA ---------------
[Counter] TestCounter: Max: 25,439,744.00 operations, Average: 25,439,744.00 operations, Min: 25,439,744.00 operations, StdDev: 0.00 operations
[Counter] TestCounter: Max / s: 154,024,468.58 operations, Average / s: 153,682,041.30 operations, Min / s: 153,301,431.37 operations, StdDev / s: 363,027.74 operations
--------------- ASSERTIONS ---------------
[PASS] Expected [Counter] TestCounter to must be greater than 10,000,000.00 operations; actual value was 153,682,041.30 operations.
------------ FINISHED NBenchRepro.CounterPerfSpecs+Benchmark ----------
在这种情况下使用 NBench 1.2.2 和dotnet --version
2.1.300。
所以这看起来很像一个环境问题,因为过去dotnet xunit
类似问题经常出现。 如果您可以向我们提供有关您的环境外观或复制规范的更多信息,我将重新打开此问题并继续对其进行处理。
同时,您可以通过根据@C-Babbage 的建议指定显式运行时版本来尝试解决方法。
跟进这个问题 - 在处理https://github.com/petabridge/Petabridge.Tracing.Zipkin/pull/68时能够自己重现这个问题
我得出了与实体框架和 XUnit 团队相同的结论:这是 CLI 本身的问题,解决方法似乎是在您的测试项目中指定RuntimeFrameworkVersion
。 这为 CLI 提供了正确解析 .NET Core 运行时所需的必要信息。
希望这在未来得到改进,但是在dotnet-nbench
启动一个新的dotnet
进程来运行规范之后会发生这个错误 - 这是一个 CLI 问题。