Right now there doesn't seem to be any simple cross-platform way of getting the current home directory. This would seem to be a common-enough need, especially as .NET Core begins to be used outside of web apps.
One complication as to why this is non-trivial is that the environment variable to this location is different on different OS's. Developers should not need to be aware of this just to get a home directory.
It seems like there is some code to do this internally and it's even more complicated than I initially thought:
https://github.com/dotnet/corefx/blob/d8508b20caa5fe523f1552cde174cb9ba5c31730/src/Common/src/System/IO/PersistedFiles.Unix.cs#L100
I wouldn't expect anyone to get that right if they had to do that on their own.
I don't have any specific proposals but something might fit into the Environment class to return that.
It might make sense to bring back some subset of the SpecialFolder shortcuts. I'm not sure that I really like putting them on Environment, though, and we definitely don't want all of the values in that enum. Actually, most of the things on that enum are either not useful or not applicable x-plat. It might be nice to have things like SpecialFolder.MyDocuments as well as Home, though.
Bringing back a subset of SpecialFolder would work. While putting them on Environment is ugly, it might be easier to ensure compat with the Desktop FX as it already has the full superset.
+1 to providing a way of getting the home directory.
-1 on bringing back SpecialFolder. Almost nothing of it applies xplat in a meaningful way and it caused us a bunch of issues in Mono (the latest being when Apple introduced Integrity Protection in El Cap and broke the path Mono uses for SpecialFolder.CommonApplicationData, or the fact that SpecialFolder.Personal has the same enum value as SpecialFolder.MyDocuments which is just confusing). Better to start from a clean slate and make it clear that this API is not the way forward.
All of the Environment APIs are now available in dev/api branch, which are included in netstandard1.7.. Environment.SpecialFolder.UserProfile should be having the home directory.
@Priya91 Can you send a github link to the source where the algo for Evironment.SpecialFolder.UserProfile is? I'd like to have a look at that.
@SeanSnyders Environment.SpecialFolder is an enum, and it's defined here in coreclr repo.
Most helpful comment
+1 to providing a way of getting the home directory.
-1 on bringing back SpecialFolder. Almost nothing of it applies xplat in a meaningful way and it caused us a bunch of issues in Mono (the latest being when Apple introduced Integrity Protection in El Cap and broke the path Mono uses for
SpecialFolder.CommonApplicationData, or the fact thatSpecialFolder.Personalhas the same enum value asSpecialFolder.MyDocumentswhich is just confusing). Better to start from a clean slate and make it clear that this API is not the way forward.