[英]Debugger does not launch when debugging xUnit tests in C# with VS Code
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 do.net test
which works fine) and I get this error:我正在尝试在 VS 代码中调试一些 xUnit 测试,但是当我尝试一个接一个地手动调试测试时出现此错误(而不是仅仅运行
do.net test
,它工作正常)并且出现此错误:
----- 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.似乎调试器试图访问一个不存在的目录,但构建和运行项目工作正常。
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.好吧,我似乎找到了一个临时解决方案:调试器在
bin/Debug.net6.0/ref
中查找不存在的参考库。 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.然而,这些库可以在
obj/Debug.net6.0/ref
中找到,简单地将它们复制到 bin 似乎可以解决问题,尽管是暂时的,我想每次重建项目时都必须这样做,但至少调试器现在运行.
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.例如,假设您有一个项目
MyProject.csproj
和另一个MyProject.Tests.csproj
,您的测试就在其中。 You want to add the ProduceReferenceAssemblyInOutDir
element to your MyProject.csproj
file.您想要将
ProduceReferenceAssemblyInOutDir
元素添加到MyProject.csproj
文件中。 This ensures the output dll
is added to the ref
folder and then the built in debugger should work again.这确保 output
dll
被添加到ref
文件夹,然后内置调试器应该再次工作。
Hope that helps!希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.