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.
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!