Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On WSL, Fake.DotNet uses dotnet.exe instead of dotnet in wsl #2573

Closed
olivercoad opened this issue Mar 11, 2021 · 1 comment · Fixed by #2584
Closed

On WSL, Fake.DotNet uses dotnet.exe instead of dotnet in wsl #2573

olivercoad opened this issue Mar 11, 2021 · 1 comment · Fixed by #2584

Comments

@olivercoad
Copy link

Description

When using Fake.DotNet.DotNet.exec without overriding Options.DotNetCliPath,
it "tries to take current global.json into account and tries to find the correct installation".

If global.json specifies a version of dotnet that is installed on windows, it will use the windows exe. Even if that version is also installed in wsl.

Repro steps

  1. make a global.json file with a version of dotnet specified which is installed on windows
  2. run dotnet fsi from WSL
  3. run
#r "nuget: Fake.DotNet.Cli"
open Fake.DotNet
DotNet.exec id "--info" "";;

Expected behavior

Output should be the same as running dotnet --info from WSL. Runtime Environment similar is

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  20.04
 OS Platform: Linux
 RID:         ubuntu.20.04-x64
 Base Path:   /usr/share/dotnet/sdk/5.0.201/

Actual behavior

Output is the same as running dotnet --info from windows. Runtime Environment is

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19041
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.101\

Known workarounds

  • change version in global.json to a version which isn't installed on windows, or
  • override DotNetCliPath in the exec options

Related information

  • Windows 10 with Ubuntu 20.04 on WSL2
  • .NET 5
  • Version of FAKE (4.X, 5.X)

Cause and fix

The default DotNetCliPath is found by taking a sequence of possible paths and then finding the first one that has the correct version (from global.json) available. This sequence of paths includes ProcessUtils.findFilesOnPath "dotnet" and so includes both /usr/bin/dotnet and /mnt/c/Program Files/dotnet/dotnet.exe. If none of them have the correct version it will just fallback to "dotnet".

From here there are two problems. Firstly, the way it checks for installed versions does not work when the path /usr/bin/dotnet is a symlink to /usr/share/dotnet/dotnet. Secondly, it should NEVER use dotnet.exe regardless because doing so can lead to a myriad of problems when you are expecting everything to be running in linux.

The suggested fix is to exclude .exe files from findPossibleDotnetCliPaths and make it follow symlinks while checking installed versions (is that possible?) or check versions some other way,

https://github.com/fsharp/FAKE/blob/5cda218b2a0aa89053a02229fac78d610e4efe67/src/app/Fake.DotNet.Cli/DotNet.fs#L539-L551

@github-actions
Copy link
Contributor

Welcome to the FAKE community! Thank you so much for creating your first issue and therefore improving the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant