FSharpLint icon indicating copy to clipboard operation
FSharpLint copied to clipboard

Can not start the cli tool: "No instances of MSBuild could be detected"

Open Shuenhoy opened this issue 3 years ago • 4 comments

Description

I cannot start the cli tool from the beginning.

Repro steps

Please provide the steps required to reproduce the problem

  1. dotnet tool install --global dotnet-fsharplint

  2. dotnet fsharplint --help

Expected behavior

It should start.

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

Please provide a description of any known workarounds.

No

Related information

  • Operating system: Windows 11 21H2 (22000.434)
  • Branch v0.21.0
  • .NET Runtime, CoreCLR or Mono Version .NET 6.0.101
  • Performance information, links to performance testing scripts

Shuenhoy avatar Feb 03 '22 13:02 Shuenhoy

I'm facing the same problem with .NET 6.0.201. Initially I faced another error because .NET Core 3.1 sdk was used by linter (although project was targeting net6.0), so incompatible target framework exception happend. After uninstalling 3.1 sdk I'm getting No instances of MSBuild could be detected

Lanayx avatar Apr 08 '22 14:04 Lanayx

Possibly related - https://github.com/microsoft/MSBuildLocator/issues/153

MatthewSteeples avatar Sep 05 '22 10:09 MatthewSteeples

I just hit this. I got both .NET 6 and 7 installed, and was targeting .net 6. After upgrading the project to .net 7 (as hinted at in above linked issue) the problem went away

dotMorten avatar Feb 09 '23 21:02 dotMorten

@sangkilc hey, I see from other comment in other github issue that you have reproduced this bug.

I was looking at it lately and I see the culprit is the Ionide.ProjInfo.Init.init() call, which is actually mentioned in our changelog:

<snip>
[0.19.0] - 2021-06-12
Update to FCS 39 [@baronfel]
Consumers of the API will now need to call Ionide.ProjInfo.Init.init(), see the FSharpLint.Console project within this repo for an example.
</snip>

So I suspect that this might be a regression introduced in 0.19.0. To prove this, can anyone here run v0.18.1 to see if it goes away?

knocte avatar Dec 30 '23 04:12 knocte