FSharpLint icon indicating copy to clipboard operation
FSharpLint copied to clipboard

`dotnet fsharplint lint ...` fails to run on a machine with only .net X.0 installed, X > 5

Open SteveGilham opened this issue 3 years ago • 5 comments

Description

dotnet fsharplint lint ... fails to run on a machine with only .net 6.0 installed

Repro steps

  1. dotnet tool install dotnet-fsharplint
  2. Remove all .net SDKs prior to current (6.0.400 at time of writing)
  3. Invoke dotnet fsharplint lint on 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

SteveGilham avatar Aug 24 '22 12:08 SteveGilham

Seems to be a duplicate of #536

SteveGilham avatar Aug 24 '22 12:08 SteveGilham

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.

SteveGilham avatar Aug 24 '22 13:08 SteveGilham

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.

baronfel avatar Aug 24 '22 13:08 baronfel

Thinking forwards, the outcome should be resilient to a .net 7.0-only (or 8.0 only) environment without requiring a day 1 update.

SteveGilham avatar Aug 24 '22 13:08 SteveGilham

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.

SteveGilham avatar Oct 22 '23 18:10 SteveGilham