> For the complete documentation index, see [llms.txt](https://til.cazzulino.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://til.cazzulino.com/msbuild/how-to-get-user-home-dir-cross-platform.md).

# How to get user home dir \~ cross-platform

It would be great if you could just use `$(~)`, say, but that would be too good to be true :).

Here's how you can get the user profile directory in both Unix-like OS (Linux/Mac) and Windows:

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