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

win32: add fallback to environment vars for system folder #109673

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kasperk81
Copy link
Contributor

Implement fallback to environment variables for system folders in NanoServer, ensuring correct paths when SHGetKnownFolderPath fails.

in base nanoserver image, all values are returning empty

foreach (Environment.SpecialFolder folder in Enum.GetValues(typeof(Environment.SpecialFolder)))
{
    Console.WriteLine($"{folder}: {Environment.GetFolderPath(folder)}")
}

both SHGetFolderPathW and SHGetKnownFolderPath fail with error -2147467259.

environment variables in the base image:
docker run --rm mcr.microsoft.com/windows/nanoserver:ltsc2022 cmd /c "set"

ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\ContainerUser\AppData\Roaming
CommonProgramFiles=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=594228B8A3DC
ComSpec=C:\Windows\system32\cmd.exe
DriverData=C:\Windows\System32\Drivers\DriverData
LOCALAPPDATA=C:\Users\ContainerUser\AppData\Local
NUMBER_OF_PROCESSORS=4
OS=Windows_NT
Path=C:\Windows\system32;C:\Windows;
PATHEXT=.COM;.EXE;.BAT;.CMD
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=AMD64 Family 25 Model 1 Stepping 1, AuthenticAMD
PROCESSOR_LEVEL=25
PROCESSOR_REVISION=0101
ProgramData=C:\ProgramData
ProgramFiles=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=$P$G
PUBLIC=C:\Users\Public
SystemDrive=C:
SystemRoot=C:\Windows
TEMP=C:\Windows\TEMP
TMP=C:\Windows\TEMP
USERDOMAIN=User Manager
USERNAME=ContainerUser
USERPROFILE=C:\Users\ContainerUser
windir=C:\Windows

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 9, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 9, 2024
@jkotas jkotas added area-System.Runtime os-windows-nano Nano Windows SKU and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Nov 10, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Implement fallback to environment variables for system folders in NanoServer, ensuring correct paths when SHGetKnownFolderPath fails.
@@ -28,7 +27,7 @@ public void ShouldUseEnvironmentVariableToGetDefaultLocation()
result.Should().Contain(PackagesPath);
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // https://github.com/dotnet/runtime/issues/21430
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorHofer @akoeplinger I removed this condition, and it's now passing where it was failing before: link to comment. I didn’t update other environment tests since they compare values against win32 SHGetFolderPathW, which returns a general error (-2147467259) on nano server

@kasperk81
Copy link
Contributor Author

@jkotas analysis shows same error as #108210 but it's not a tracking issue
(this is win32 only change)

@jkotas
Copy link
Member

jkotas commented Nov 18, 2024

I am leaving it to @dotnet/area-system-runtime owners to do the final signoff and merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime community-contribution Indicates that the PR has been added by a community member os-windows-nano Nano Windows SKU
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants