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

Building with a dotnet not on the PATH is broken #69150

Closed
eerhardt opened this issue Jul 21, 2023 · 1 comment · Fixed by #69186
Closed

Building with a dotnet not on the PATH is broken #69150

eerhardt opened this issue Jul 21, 2023 · 1 comment · Fixed by #69186
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@eerhardt
Copy link
Member

eerhardt commented Jul 21, 2023

This is basically a duplicate of #69023, but I can't re-open that issue, so I logging a new one.

The latest builds of .NET 8 Preview7 are now broken if you xcopy/unzip/untar the bits to some dotnet "hive" that is not on the $PATH. This scenario needs to work.

Repro Steps

  1. Have a machine with .NET 7 installed in %PROGRAMFILES%
  2. Download and unzip the latest .NET 8 SDK https://github.com/dotnet/installer#table to somewhere not on the $PATH. Ex. C:\dotnet.
  3. In a new directory issue the following commands:
C:\dotnet\dotnet.exe new console
C:\dotnet\dotnet.exe build

Expected results

The build should succeed

Actual results

C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error : You must install or update .NET to run this application. [C:\Do
tNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :  [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error : App: C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\bincore\csc.dll
[C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error : Architecture: x64 [C:\DotNetTest\Net8Console\Net8Console.csproj
]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error : Framework: 'Microsoft.NETCore.App', version '8.0.0-preview.7.23
368.2' (x64) [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error : .NET location: C:\Program Files\dotnet\ [C:\DotNetTest\Net8Cons
ole\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :  [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error : The following frameworks were found: [C:\DotNetTest\Net8Console
\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :   3.1.32 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.A
pp] [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :   6.0.0-preview.5.21301.5 at [C:\Program Files\dotnet\shared\Mi
crosoft.NETCore.App] [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :   6.0.19 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.A
pp] [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :   6.0.20 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.A
pp] [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :   7.0.8 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.Ap
p] [C:\DotNetTest\Net8Console\Net8Console.csproj]
C:\dotnet\sdk\8.0.100-rc.1.23371.3\Roslyn\Microsoft.CSharp.Core.targets(80,5): error :   7.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.Ap
p] [C:\DotNetTest\Net8Console\Net8Console.csproj]
C

Original issue

          At the moment this behavior is "By Design". The compiler will use the `dotnet` which is available on `$PATH`. 

Various parts of dotnet/sdk seem to set the DOTNET_HOST_PATH environment variable, and this is no longer being used.

That is an implementation detail of our internal architecture that leaked into the shipping product. Very confident our conclusion is going to be that this needs to be removed from the product.

If you feel a better appproach is in order here please put the discussion on dotnet/runtime#88754. That is the design we are following here.

Originally posted by @jaredpar in #69023 (comment)

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 21, 2023
@ericstj
Copy link
Member

ericstj commented Jul 21, 2023

I second what @eerhardt is reporting here. Looks like the CLI was explicitly setting DOTNET_HOST_PATH in the shipping product to communicate which dotnet to use from MSBuild:
https://github.com/dotnet/sdk/blob/996439eb9a1fdd7988a48bdb6f7156e2691c8706/src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs#L44

It looks like this was introduced here: dotnet/cli#7311 #21237
Related: dotnet/sdk#20, dotnet/sdk#8592
It might be that DOTNET_HOST_PATH was always specifically for this scenario 🤔

333fred pushed a commit that referenced this issue Jul 24, 2023
* Enable building with a dotnet not on PATH

In #68918 we removed inspecting DOTNET_HOST_PATH environment variable. This broke the scenario where a specific dotnet "hive" was installed to a location not on the PATH.

When the .NET SDK commands invoke a sub-process (for example MSBuild), it sets the DOTNET_HOST_PATH environment variable to tell the sub-process "this is where the dotnet.exe that invoked this command is located". See #21237 and dotnet/cli#7311 for more info.

This change reverts the behavior back to respect DOTNET_HOST_PATH, and if it isn't set it will just use "dotnet" and let the OS take care of finding the executable on the PATH.

Fix #69150

* Fix tests to workaround MSBuild searching the PATH itself.

* Respond to PR feedback.

Make the change smaller until @jaredpar gets back. Only make the minimal change required, which is to check DOTNET_HOST_PATH.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants