dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

[Feature Request]: Expand $(~) to $(HOME) or $(USERPROFILE) depending on OS #10160

Open kzu opened 3 months ago

kzu commented 3 months ago

Summary

Currently, you need to do something like the following to consistently get the ~ home directory in a cross-platform way:

<PropertyGroup>
    <UserProfileHome Condition="'$([MSBuild]::IsOSUnixLike())' == 'true'">$(HOME)</UserProfileHome>
    <UserProfileHome Condition="'$([MSBuild]::IsOSUnixLike())' != 'true'">$(USERPROFILE)</UserProfileHome>
</PropertyGroup>

It would be awesome if the well-known shorthand ~ (even PowerShell Core knows it) could be used directly in MSBuild as a built-in envvar alias for either $(HOME) or $(USERPROFILE) depending on the current OS, just like pwsh does it.

Background and Motivation

No particular problem, just a desire for more consistency across developer tooling in the ecosystem (following the lead from pwsh).

Proposed Feature

Summary contains the proposal, which would be to consider ~ as an alias to either Home or UserProfile envvar names in Unix-like vs Windows.

Alternative Designs

No response

danmoseley commented 3 months ago

Or MsbuildHomeDir ?

AR-May commented 3 months ago

Team triage: @baronfel what do you think of this suggestion?

baronfel commented 3 months ago

It seems reasonable to me, but we should check for consistency with the Runtime's SpecialFolders enum in addition to various popular shells like bash, zsh, fish, and pwsh.

kzu commented 3 months ago

@danmoseley that would be confusing, since it might mean the MSBuild home dir (i.e. where msbuild.exe lives).