调试器在使用VS代码的C#中调试Xunit测试时不会启动
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在某些情况下,如果您正在使用.NET日常构建(例如在运行时或库上工作时),则需要配置Visual Studio来跳过验证引用的组件的签名,然后再调试。
请参阅, https://github.com/dotnet/runtime/blob/main/main/docs/workflow/debugging/coreclr/coreclr/coreclr/debugging-runtime.md#resolving-resolving-resolving-signature-validature-validation-validation-validation-validation-validation-rors-rors-in-visual--visual--visual--visual--visual--visual--visual--visual--visual--visual--visual--visual--n-in-rors-in-r.工作室
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
将以下内容添加到您的测试目标:
例如,假设您有一个项目
myProject.csproj
和另一个myproject.test.tests.csproj
测试所在的地方。您需要将pardyereferenceSemblyInoutDir
元素添加到myproject.csproj
文件。这样可以确保输出dll
被添加到ref
文件夹中,然后内置的调试器应再次工作。希望有帮助!
Add the following to the project your tests are targeting:
For example, say you have a project
MyProject.csproj
and anotherMyProject.Tests.csproj
where your tests reside. You want to add theProduceReferenceAssemblyInOutDir
element to yourMyProject.csproj
file. This ensures the outputdll
is added to theref
folder and then the built in debugger should work again.Hope that helps!
好吧,我似乎找到了一个临时解决方案:调试器在
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 inobj/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.