Closed ngoquoctoandev closed 2 years ago
Hello. This is due to https://github.com/PowerShell/MMI/issues/45 - can you target win10-x64
instead? Or one of the other more specific runtimes.
There doesn't seem to be a suitable alternative. And no specific operating system appears in the target runtime list. Of course, if I choose Portable, there is no "Single File" option.
same issue when targeting win-x64. Does not even need to be single file.
same issue when targeting win-x64. Does not even need to be single file.
Confirmed.
Just to say I too have fallen over this. I don't understand the technicalities, but it looks like a long chain of dependency that would be good to cut out the middle man and go directly to the WMI interface. I'll resort to storing a GUID in a file the \Windows directory until then...
This is obviously catching a lot of people out.
For anyone seeing this issue and not wanting to change their runtime identifier, I would recommend just using v5.2.0 for now - it still uses WMI and thus doesn't have any of the issues with the MMI package.
Moving forwards, I think the best option will be to provide both a WMI and a MMI package, so that people can choose which set of tradeoffs they want to make. I'll do this in the next release.
Ahah! It does indeed work fine with 5.2. Thank you for correcting me.
I'm working on a v6 release that will break out the various platform-specific stuff into its own packages. It will allow you to choose between using WMI and MMI on Windows.
For the Windows stuff, you'll have a choice of:
I'm going to go back to recommending the WMI stuff as a default, as the runtime issues with MMI are catching too many users out.
Simple example using the new syntax:
var deviceId = new DeviceIdBuilder()
.AddMachineName()
.AddUserName()
.OnWindows(windows => windows
.AddProcessorId()
.AddSystemSerialDriveNumber())
.OnLinux(linux => linux
.AddCpuInfo()
.AddSystemDriveSerialNumber())
.ToString();
v6 is currently available as an alpha. Alternatively, users who want to stay on v5 can use v5.2.0 for WMI or v5.3.0 for MMI.
This error is not really fixed even though I am using the latest version of DeviceId 6.2.0
It actually is fixed but I can help you out. Are you using WMI or MMI?
The following minimal reproduction confirms that it does work as described above:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DeviceId.Windows.Mmi" Version="6.2.0" />
</ItemGroup>
</Project>
using System;
using DeviceId;
var deviceId = new DeviceIdBuilder()
.AddMachineName()
.AddUserName()
.OnWindows(windows => windows
.AddProcessorId()
.AddSystemDriveSerialNumber())
.ToString();
Console.WriteLine(deviceId);
DeviceId.Windows.Mmi This error occurs when I publish the application as SingleFile
My application runs on two operating systems Windows 7/10
Please refer to the discussion I mentioned earlier: https://github.com/PowerShell/MMI/issues/45
Or use DeviceId.Windows.Wmi
Here is a simple reproduction that confirms you can publish single file on win-x64
using DeviceId.Windows.Wmi
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DeviceId.Windows.Wmi" Version="6.2.0" />
</ItemGroup>
</Project>
using System;
using DeviceId;
var deviceId = new DeviceIdBuilder()
.AddMachineName()
.AddUserName()
.OnWindows(windows => windows
.AddProcessorId()
.AddSystemDriveSerialNumber())
.ToString();
Console.WriteLine(deviceId);
Why can't be compatible with MMI
I've linked to the discussion the MMI repo twice now. Please go read it. Here it is again: https://github.com/PowerShell/MMI/issues/45
You need to include your specific runtime identifiers (example: win7-x64, win10-x64
) rather than just using win-x64
.
This is just how MMI works. It has nothing to do with the DeviceId
library and it's nothing that I can change.
I have a sample WPF project running on .NET 5. Everything works fine for both debug and release environments. However, if I publish the project with target runtime as win-x64 or win-x86 with "Produce Single File" option, the following error occurs.
This error is logged with Serilog