Closed Booksbaum closed 3 years ago
I'm fine looking at these environment variables in this case, it would just need to be in conjunction with the current logic I think. I believe I copied at least most of the current implementation from the .net SDK binaries themselves and/or the MSBuild launcher in the SDK, so I'm a bit topsy-turvy trying to remember the logic for each choice I made.
(copy&paste from #117 because more longterm/complex strategy)
I just looked at Omnisharp. It's looking at DOTNET_ROOT
, and otherwise falls back to dotnet
from PATH
Looking at usages of Paths.dotnetRoot
, it's currently used in two ways:
dotnet
executable (to get version and to set DOTNET_HOST_PATH
)I think these two can be split apart and made independent of dotnet dir and just rely on dotnet
executable (which is most likely in PATH
):
dotnet --list-sdks
DOTNET_ROOT_PATH
, DOTNET_HOME
, DOTNET_ROOT
(, maybe DOTNET_ROOT(x68)
?), maybe default dotnet install dirs?, just dotnet
(-> from PATH
)For sdks dotnet
currently needs a full path because sdks need its directory -> just dotnet
from PATH
currently doesn't work. With dotnet --list-sdks
that wouldn't matter any more
I was hoping to not parse CLI output, but it's probably the correct way forward.
That's already the case with --version
. But the output of --version
is just the version number, --list-sdks
is a bit more complex.
One downside: old dotnet versions don't support --list-sdks
(not sure when it was introduced, but the first dotnets definitely didn't)
I can take care of implementing it (probably tomorrow -- lots of football (played with a round ball and feet) and football (played with egg and hands) and I usually do something on the side while watching)
Fixed in #117
Describe the bug
A project using
Ionide.ProjInfo
and callingIonide.ProjInfo.Init.init
starts itself -- with just--version
as argument.If
....exe --version
just returns its own version an exception is thrown:(
Ionide.ProjInfo.Tool, v....
is what is returned byIonide.ProjInfo.Tool.exe --version
)But worse when the program doesn't handle
--version
and instead calls again theinit
function. Now this process again starts itself with--version
. And this child starts again another child, which starts another child, which starts another child, ...:To Reproduce
NOTE: requires
DOTNET_HOST_PATH
to be NOT set! (-> is reason why this is happening. Explained further below.) (Remove-Item Env:\DOTNET_HOST_PATH
in powershell)Exception:
In current master branch of
ionide/proj-info
:dotnet run --framework net5.0 --project .\src\Ionide.ProjInfo.Tool\ -- --project .\src\Ionide.ProjInfo.Tool\Ionide.ProjInfo.Tool.fsproj
(starts
Ionide.ProjInfo.Tool
with itself as project to analyze)Output:
(
Ionide.ProjInfo.Tool, v....
is what is returned byIonide.ProjInfo.Tool.exe --version
)Child bomb:
https://github.com/Booksbaum/ProjInfoTest.git
and checkoutdotnet-version
branchdotnet run
dotnet run -- --sleep-on-version
-> only starts one--version
child which is kept aliveTask Manager
in Details tab shows lots ofProjInfoTest
processes. Probably better to use Process Explorer (from sysinternals) which shows the processes as tree (see windows image above).Expected behaviour
It should neither throw an error nor spawn children, but instead initialize ProjInfo correctly.
Reason
ProjInfo fails to get the current dotnet version.
Exception when there's a return value which it cannot parse, recursively children when the process reaches the same location and looks for the dotnet version again.
It wants to call
dotnet --version
. For this it needs the currentdotnet
path. Which it tries to get here: https://github.com/ionide/proj-info/blob/29950f00da845efe13a9163c296000cf28abbdcf/src/Ionide.ProjInfo/Utils.fs#L6-L16If there's
DOTNET_HOST_PATH
it uses that value. But otherwise it returns the current process path. Which isn't the path todotnet
, but to the current exe.The Tests handle this case:
https://github.com/ionide/proj-info/blob/29950f00da845efe13a9163c296000cf28abbdcf/test/Ionide.ProjInfo.Tests/Program.fs#L14-L23
Based on the comment I think old dotnet versions didn't spawn the executable. But that's not the case anymore (as seen in the screenshot above:
dotnet.exe
spawnsProjInfoTest.exe
)Like the tests
Ionide.ProjInfo.Paths.dotnetRoot
should look forDOTNET_ROOT
(andDOTNET_ROOT (x64)
. This should be set when dotnet isn't installed in default location. (Though for me it's even set for default location)Environment:
0.54.0
6.0.100-rc.2.21505.57
&5.0.303
5.0.301
5.0.303
Additional context
Isolated from fsharp/FsAutoComplete#837
But at least now the new processes are proper children and get killed when the root process (the one without
--version
) is finished (or killed). I think because of newer ProjInfo version.