无法在 VSCode 中使用 CodeLens 运行或调试 C# 测试

iam*_*ale 4 .net c# visual-studio-code

我正在尝试使用 Run CodeLens 在 VSCode 中运行 xUnit 测试 CodeLens 的图片

我在 2019 年 MacBook Pro (Intel) 上使用 VSCode 1.65.0 和 .Net 6 (6.0.200),并使用 C# VSCode 扩展 v1.24.1。

dotnet test我已使用命令、.NET Core Test Explore 插件和 VS2022运行它,并且它们按预期工作。

这是我得到的输出日志

----- Running test method "net6TestTest.TestControllerTest.Get_ShouldReturn_String" -----

Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/Users/ssmale/Projects/net6Test/net6Test/bin/Debug/net6.0/ref/net6Test.dll'. [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]

Build FAILED.

/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/Users/ssmale/Projects/net6Test/net6Test/bin/Debug/net6.0/ref/net6Test.dll'. [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
/usr/local/share/dotnet/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/Users/ssmale/Projects/net6Test/net6Test/net6Test.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:01.26


Run Code Online (Sandbox Code Playgroud)

iam*_*ale 10

要使用 .net 6,您需要更新 Omnisharp 设置以使用“现代”方式

您需要切换的设置是omnisharp.useModernNet. 它在 C# 扩展的读取中进行了描述。