1

我正在开发一个 .NET Core 应用程序。我的要求是我必须获得主板的 UUID。代码是:

static void Main(string[] args)
{
    string uuid = string.Empty;

    ManagementClass mc = new ManagementClass("Win32_ComputerSystemProduct");
    ManagementObjectCollection moc = mc.GetInstances();

    foreach (ManagementObject mo in moc)
    {
        uuid = mo.Properties["UUID"].Value.ToString();
        break;
    }

    Console.WriteLine("UUID : " + uuid);

    Console.ReadKey();
}

这段代码在 Windows 机器上运行良好,但是当我移动到 linux 机器时,我收到以下错误:

Unhandled exception. System.PlatformNotSupportedException: System.Management currently is only supported for Windows desktop applications.                                                                             
at System.Management.ManagementBaseObject..ctor(SerializationInfo info, StreamingContext context)
at System.Management.ManagementObject..ctor()
at System.Management.ManagementClass..ctor(String path)
at uniqueSystemId.Program.Main(String[] args)

linux 不支持System.Management吗?如果没有,我如何在 linux 和 windows 机器上获取主板的 UUID

4

0 回答 0