How should I gather Hardware Info if System.Management.dll
is not compatible with Dot Net Core.
How do I get the Machine info like Processor Id, Disk Volume number etc.
How should I gather Hardware Info if System.Management.dll
is not compatible with Dot Net Core.
How do I get the Machine info like Processor Id, Disk Volume number etc.
I am currently porting a Net Framework project that uses
System.Management
to get some hardware info, and I also got to a dead end becauseSystem.Management
is not compatible with Net Core.The workaround I found was to use
Process.Start
fromSystem.Diagnostics
to execute powershell commands to get that information, for instance, to get the motherboard serial number you can use the commandGet-WmiObject Win32_BaseBoard | select SerialNumber
, you can then change the command to process the output and only have the serial number, or even process the output programatically.You can also add some
ifs
, that depending on the current OS you can provide to theProcess.Start
specific OS commands, for instance, for linux you would need to process a dmidecode related command.The only negative side in this approach is that its A LOT SLOWER whem compared with
System.Management
..NET Core 3 now supports System.Management. As of this time, .NET Core 3 is in preview mode with preview 4 as the most current.
You will have to select the Manage NuGet packages... menu item under the Project menu in Visual Studio to install the latest version of System.Management. Make sure that the include previews checkbox is selected so that you will install the latest version.
The previous version of System.Management throws an error:
See this link for more info about the error.
I found this issue while upgrading from .NetFramework to .NetCore 3.0
At this point the latest available version is 4.6.0 https://www.nuget.org/packages/System.Management/4.6.0 and latest preview is 4.7.0-preview3.19551.4
You need to install
Microsoft.Windows.Compatibility
in your .Net core project to be able to referenceSystem.Management.dll
.