.net core 读取dotnet core上的用户配置文件相关文件

.net core 读取dotnet core上的用户配置文件相关文件,.net-core,.net Core,如何以平台无关的方式正确处理使用dotnet core的文件路径?i、 e.我正在使用Mac电脑,试图打开与我的用户配置文件相关的文件时 var file="~/Downloads/example.zip"; var fullPath = Path.GetFullPath(file); 返回 /Users/Me/Projects/Test/Test/~/Downloads/example.zip 选择1 使用Environment.ExpandEnvironmentVariables(“%H

如何以平台无关的方式正确处理使用dotnet core的文件路径?i、 e.我正在使用Mac电脑,试图打开与我的用户配置文件相关的文件时

var file="~/Downloads/example.zip";
var fullPath = Path.GetFullPath(file);
返回

/Users/Me/Projects/Test/Test/~/Downloads/example.zip
选择1 使用
Environment.ExpandEnvironmentVariables(“%HOME%”)来获得与
~
等价的值。大概是

var file = Environment.ExpandEnvironmentVariables("%HOME%/Downloads/example.zip");
选择2 使用
Environment.GetEnvironmentVariable(“HOME”)

备选案文3: 使用
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

选择1 使用
Environment.ExpandEnvironmentVariables(“%HOME%”)来获得与
~
等价的值。大概是

var file = Environment.ExpandEnvironmentVariables("%HOME%/Downloads/example.zip");
选择2 使用
Environment.GetEnvironmentVariable(“HOME”)

备选案文3: 使用
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)

var file = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ....