`dotnet fsharplint lint ...` fails to run on a machine with only .net X.0 installed, X > 5
Description
dotnet fsharplint lint ... fails to run on a machine with only .net 6.0 installed
Repro steps
- dotnet tool install dotnet-fsharplint
- Remove all .net SDKs prior to current (6.0.400 at time of writing)
- Invoke
dotnet fsharplint linton any .fsproj file
Expected behavior
Tool runs to analyze project
Actual behavior
Unhandled exception. System.TypeInitializationException: The type initializer for 'FSharpLint.Console.Program' threw an exception.
---> System.TypeInitializationException: The type initializer for '<StartupCode$dotnet-fsharplint>.$FSharpLint.Console.Program' threw an exception.
---> System.InvalidOperationException: No instances of MSBuild could be detected.
Try calling RegisterInstance or RegisterMSBuildPath to manually register one.
at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()
at Ionide.ProjInfo.Init.init() in D:\a\proj-info\proj-info\src\Ionide.ProjInfo\Library.fs:line 17
at <StartupCode$dotnet-fsharplint>.$FSharpLint.Console.Program..cctor() in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Console\Program.fs:line 134
--- End of inner exception stack trace ---
at FSharpLint.Console.Program..cctor()
--- End of inner exception stack trace ---
at FSharpLint.Console.Program.main(String[] argv) in D:\a\FSharpLint\FSharpLint\src\FSharpLint.Console\Program.fs:line 138
Known workarounds
Install out-of-support .net 5.0.408 SDK
Related information
- Operating system : Windows
- Branch : nuget package dotnet-fsharplint version 0.21.2
- .NET Runtime, CoreCLR or Mono Version : .net SDK 6.0.400
Seems to be a duplicate of #536
Probably the simplest fix would be to detect (or specify via command line) the SDK in use & feed that into a manual resolution process if the default doesn't work.
It would probably be easiest to update the proj-info dependencies, which I believe would also require updating FSharp.Compiler.Service as well. Newer proj-info dependency versions bring better resolution logic here, and better error messages.
Thinking forwards, the outcome should be resilient to a .net 7.0-only (or 8.0 only) environment without requiring a day 1 update.
Hit this again, on the eve of the net8.0 release, with a new dev machine that only has SDK v7.0.402 installed (from Visual Studio 17.7), and dotnet-fsharplint 0.21.3 this time.
A truly simple fix could be to have a command-line option that takes a path-to-MSBuild and registers it with RegisterMSBuildPath, if present.
FWIW, it seems that some time after version 0.53.1, Ionide.ProjInfo has been extended to read the environment for, amongst others, a DOTNET_ROOT variable for the location to search to find an MSBuild.dll, which feature could be useful to have access to.