.net core net core能否在WSL执行时检测操作系统?
我在这里找到的以下代码是为了在运行时检测Windows,但它认为WSL Ubuntu就是Windows。还有更好的办法吗?还是.net core net core能否在WSL执行时检测操作系统?,.net-core,cross-platform,windows-subsystem-for-linux,.net Core,Cross Platform,Windows Subsystem For Linux,我在这里找到的以下代码是为了在运行时检测Windows,但它认为WSL Ubuntu就是Windows。还有更好的办法吗?还是 public static bool IsWindows { get { var osver = Environment.OSVersion; return osver.Platform == PlatformID.Win32NT; } } 啊!我运行的是VisualStudio生成的EXE,WSL检测到了这一点
public static bool IsWindows
{
get
{
var osver = Environment.OSVersion;
return osver.Platform == PlatformID.Win32NT;
}
}
啊!我运行的是VisualStudio生成的EXE,WSL检测到了这一点,并像在Windows控制台中一样运行它。构建在Ubuntu上,它创建了一个linux可执行文件 DOH!我运行的是VisualStudio生成的EXE,WSL检测到了这一点,并像在Windows控制台中一样运行它。构建在Ubuntu上,它创建了一个linux可执行文件 仅供参考,您可以使用命令行参数构建跨平台。还可以将build to package作为单个EXE进行编译,这对docker尤其好。仅供参考,您可以使用命令行参数跨平台编译。也可以构建到包作为一个单一的EXE,这是很好的,特别是对docker。