ionide-vscode-fsharp
ionide-vscode-fsharp copied to clipboard
Test explorer should use 'dotnet build' instead of 'msbuild /t:Build' to build the test project for test discovery
Describe the bug
When working on the dotnet/fsharp repository in a dev container, the test explorer test discovery fails with a build error. Reason is
- The test explorer uses
msbuild /t:Build - To build the compiler, you must use their build scripts, or use
dotnet build, or haveBUILDING_USING_DOTNETset. (This is true once https://github.com/dotnet/fsharp/pull/16335 is merged.)
Steps to reproduce
Open the dotnet/fsharp directory in VS Code Dev Containers.
Wait for the (misleading) error message Couldn't build test projects. Make sure you can build projects with 'dotnet build'.
Machine info
- OS: Windows 11 with WSL2/docker and VS Code Dev Containers
- .NET SDK version: 8.0.100-rc.1.23463.5 in dev container
- Ionide version: 7.16.1
Additional context
As dotnet test is used for discovery and running of tests, I assume dotnet build is ok for building. Or is there a specific reason to use 'msbuild' directly? It would be nice to have test discovery work out of the box when opening dotnet/fsharp in a dev container.
In any case, the error message should be changed to say ... Make sure you can build projects with 'msbuild /t:Build'.
cc @farlee2121
The test explorer uses msbuild because
- msbuild returns a signal, so we don't have to parse to tell if the build failed. Dotnet build returns command success even if the build fails.
- consistency with other Ionide commands, which use msbuild
As for the error message, the vast majority of the time dotnet build is going to boil down to the same result as msbuild
but is much more likely to be in the user's path and thus easy for them to double check.
I don't know for sure, but I'd guess dotnet build is a light wrapper around msbuild.
Considering tests were discovered for the fsharp repo in #1946, there might be something else going on here.
dotnet build returns command success even if the build fails
This is surprising to me - we're getting the exit code from MSBuild here and should be flowing that up. Can you log an issue to dotnet/sdk with a repro?
Maybe I need to revisit this and look more closely at the exit code, but I remember stumbling into this during my work. My notes say
Looks like
dotnet builddoesn't consider failed builds to be an error exit code. Nor does it write to stderr.
and I linked to this existing issue https://github.com/dotnet/sdk/issues/8481#issuecomment-314175413