调试器在使用VS代码的C#中调试Xunit测试时不会启动

发布于 2025-01-24 02:13:02 字数 2739 浏览 4 评论 0原文

我正在尝试在VS代码中调试一些XUNIT测试,但是当我尝试一个一个一个一个一个一个逐一调试测试时,我会遇到此错误:

----- Debugging test method TournamentTests.OrganizeIntoPairsIncludesAllElements -----

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

/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/bin/Debug/net6.0/ref/best-song.dll'. [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/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/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]

Build FAILED.

看来,调试器试图访问不存在的目录,但是构建和运行该项目的工作正常。

I am trying to debug some xUnit tests in VS code but I get this error when I try to manually debug the tests one by one (instead of just running dotnet test which works fine) and I get this error:

----- Debugging test method TournamentTests.OrganizeIntoPairsIncludesAllElements -----

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

/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error MSB3883: Unexpected exception:  [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error : DirectoryNotFoundException: Could not find a part of the path '/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/bin/Debug/net6.0/ref/best-song.dll'. [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func`2 errorRewriter) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/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/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite) [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :    at Microsoft.CodeAnalysis.BuildTasks.CopyRefAssembly.Copy() [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]
/usr/local/share/dotnet/x64/sdk/6.0.200/Microsoft.Common.CurrentVersion.targets(4650,5): error :  [/Users/janneschyffert/Documents/Kurser/INDA/best-song/src/best-song.csproj]

Build FAILED.

It appears that the debugger tries to access a directory that doesn't exist, but building and running the project works just fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烛影斜 2025-01-31 02:13:03

There is also a situation where if you are working with .NET daily builds, such as when working on the runtime itself, or the libraries, you will need to configure Visual Studio to skip validating signatures of referenced assemblies before debugging.

See, https://github.com/dotnet/runtime/blob/main/docs/workflow/debugging/coreclr/debugging-runtime.md#resolving-signature-validation-errors-in-visual-studio

执手闯天涯 2025-01-31 02:13:02

将以下内容添加到您的测试目标:

  <PropertyGroup>
    <ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>
  </PropertyGroup>

例如,假设您有一个项目myProject.csproj和另一个myproject.test.tests.csproj测试所在的地方。您需要将pardyereferenceSemblyInoutDir元素添加到myproject.csproj文件。这样可以确保输出dll被添加到ref文件夹中,然后内置的调试器应再次工作。

希望有帮助!

Add the following to the project your tests are targeting:

  <PropertyGroup>
    <ProduceReferenceAssemblyInOutDir>true</ProduceReferenceAssemblyInOutDir>
  </PropertyGroup>

For example, say you have a project MyProject.csproj and another MyProject.Tests.csproj where your tests reside. You want to add the ProduceReferenceAssemblyInOutDir element to your MyProject.csproj file. This ensures the output dll is added to the ref folder and then the built in debugger should work again.

Hope that helps!

偏爱自由 2025-01-31 02:13:02

好吧,我似乎找到了一个临时解决方案:调试器在bin/debug/net6.0/ref中寻找参考库,而不存在。但是,可以在obj/debug/net6.0/ref 中找到这些库,并且简单地将它们复制到bin似乎可以解决问题,但我想每次您重建项目时都必须这样做但是至少调试器现在运行。

Alright, I appear to have found a temporary solution: The debugger looks for reference libraries in bin/Debug/net6.0/ref which doesn't exist. The libraries can however be found in obj/Debug/net6.0/ref and simply copying them over to bin seems to solve the problem albeit temporarily, I guess this must be done every time you rebuild the project but at least the debugger runs now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文