System.Environment.OSVersion
似乎不是.net核心5.0(dnxcore50)的一部分。System.Environment.OSVersion .NET Core 5.0 Framework替换?
我试图确定哪个操作系统用户是这样,当他们将文件保存到我知道,而用“/”或“\”
我应该用什么来代替文件系统?
System.Environment.OSVersion
似乎不是.net核心5.0(dnxcore50)的一部分。System.Environment.OSVersion .NET Core 5.0 Framework替换?
我试图确定哪个操作系统用户是这样,当他们将文件保存到我知道,而用“/”或“\”
我应该用什么来代替文件系统?
不要自己做检测。使用System.IO.Path。 DirectorySeparatorChar。另外,如果你总是使用Path来操作路径,那么你应该得到你需要的格式。这也适用于URL。
你可以把它找回来:
using System.Runtime.InteropServices;
namespace System
{
// [ComVisible(true)]
// [Serializable]
public enum PlatformID
{
Win32S = 0,
Win32Windows = 1,
Win32NT = 2,
WinCE = 3,
Unix = 4,
// Since NET 3.5 SP1 or silverlight
Xbox = 5,
MacOSX = 6,
}
public class OperatingSystem
{
private Architecture m_arch;
private bool m_isARM;
private bool m_isX86;
private bool m_isLinux;
private bool m_isOSX;
private bool m_isWindows;
private PlatformID m_platform;
public OperatingSystem()
{
m_arch = RuntimeInformation.ProcessArchitecture;
m_isARM = (m_arch == Architecture.Arm || m_arch == Architecture.Arm64);
m_isX86 = (m_arch == Architecture.X86 || m_arch == Architecture.X64);
m_isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
m_isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
m_isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (m_isLinux || m_isOSX)
m_platform = PlatformID.Unix;
else if (m_isWindows)
{
m_platform = PlatformID.Win32NT;
}
else
throw new System.PlatformNotSupportedException("Operating system not supported.");
}
public PlatformID Platform
{
get
{
return m_platform;
}
}
}
public class OldEnvironment
{
private static OperatingSystem m_OS;
static OldEnvironment()
{
m_OS = new OperatingSystem();
}
public static OperatingSystem OSVersion
{
get
{
return m_OS;
}
}
}
}
显然,这个功能已经[故意漏掉(https://github.com/dotnet/corefx/issues/1017),以防止开发人员使用的版本数字来检查功能的可用性。你想解决的根本问题是什么? – Heinzi
在github上讨论了这个问题:https://github.com/dotnet/corefx/issues/1017。此时此功能不可用 –
我试图确定哪个操作系统是用户所以当他们将文件保存到文件系统我知道宁愿使用'/'或'\' – allencoded