谁能帮我弄清楚如何在ubuntu中使用“ dotnet”设置单元测试?现在dnx和dnu被dotnet取代了,我遇到了问题。

我有一个具有以下内容的project.json文件:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": false
  },

  "dependencies": {
    "Microsoft.NETCore.Runtime": "1.0.1-beta-*",
    "xunit": "2.1.0-*",
    "xunit.runner.dnx": "2.1.0-*"
  },

  "commands": {
    "test": "xunit.runner.dnx"
  },

  "frameworks": {
    "dnxcore50": { }
  }
}


运行此命令时遇到问题:

dotnet test


并吐出以下内容:

dotnet-test Error: 0 : System.DllNotFoundException: Unable to load DLL 'api-ms-win-core-localization-l1-2-0.dll': The specified module could not be found.
 (Exception from HRESULT: 0x8007007E)
   at Interop.mincore.FormatMessage(Int32 dwFlags, IntPtr lpSource_mustBeNull, UInt32 dwMessageId, Int32 dwLanguageId, StringBuilder lpBuffer, Int32 nSize, IntPtr[] arguments)
   at Interop.mincore.TryGetErrorMessage(Int32 errorCode, StringBuilder sb, String& errorMsg)
   at Interop.mincore.GetMessage(Int32 errorCode)
   at System.Diagnostics.Process.ResolvePath(String filename)
   at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
   at Microsoft.DotNet.Cli.Utils.Command.Execute()
   at Microsoft.DotNet.Tools.Test.Program.RunConsole(ProjectContext projectContext, CommandLineApplication app, String testRunner)
   at Microsoft.DotNet.Tools.Test.Program.<>c__DisplayClass0_0.<Main>b__0()


任何帮助将不胜感激。

最佳答案

可悲的是,经过一些Google-fu并深入研究了dotnet代码(以及通过github发布的问题)后,我找到了原因。

底线:该功能尚未实现,并且存在另一个错误(显然已修复,但当前发行版中尚未修复),该错误每当尝试从找不到的路径运行程序时,都会尝试将其调用到Windows DLL中。

在这里亲自查看:https://github.com/dotnet/cli/issues/407(阅读@piotrpMSFT的最后几条内容)

最后证明:

dotnet test


如果未在project.json中指定“ testRunner”,将尝试运行命令“ dotnet-test-”。但是,如果project.json包含如下所示的testRunner:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": false
  },

  "testRunner": "xunit",

  "dependencies": {
    "Microsoft.NETCore.Runtime": "1.0.1-beta-*",
  },

  "frameworks": {
    "dnxcore50": { }
  }
}


然后它将尝试运行程序dotnet-test-xunit(因为“ testRunner”设置为“ xunit”),并将项目DLL作为参数传递。

来吧,微软帅哥,帮帮我,让我可以开始用测试编写C#NuGet软件包。

关于.net - 为什么“dotnet测试”在ubuntu LTS 14.04上失败?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34737821/

10-13 09:32