'Deploying .NET Core Application with Windows Compatibility Pack

I'm busy deploying a .NET Core 2.1 application into our testing environment, but I'm getting the following error.

Error:
  An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
    package: 'System.Diagnostics.EventLog', version: '4.5.0'
    path: 'runtimes/win/lib/netcoreapp2.1/System.Diagnostics.EventLog.dll'

We are using the Windows Compatibility Pack to access the Event Log.

I have the following item in the dependency Json file:

"System.Diagnostics.EventLog/4.5.0": {
  "dependencies": {
    "Microsoft.Win32.Registry": "4.5.0",
    "System.Security.Permissions": "4.5.0",
    "System.Security.Principal.Windows": "4.5.0",
    "System.Threading.AccessControl": "4.5.0"
  },
  "runtime": {
    "lib/netstandard2.0/System.Diagnostics.EventLog.dll": {
      "assemblyVersion": "4.0.0.0",
      "fileVersion": "4.6.26515.6"
    }
  },
  "runtimeTargets": {
    "runtimes/win/lib/netcoreapp2.0/System.Diagnostics.EventLog.dll": {
      "rid": "win",
      "assetType": "runtime",
      "assemblyVersion": "4.0.0.0",
      "fileVersion": "4.6.26515.6"
    }
  }
}

Please advise how one should deploy these dependencies. Also, what is the root folder to this relative path runtimes/win/lib/netcoreapp2.0?



Solution 1:[1]

After a lot of testing, the key issue seems to be the "RuntimeIdentifiers". There is a visible option for this when you publish, but in order to use it when just building you need to add a couple of tags to your .csproj file.

The first is:

<RuntimeIdentifier>win-x86</RuntimeIdentifier>

This will cause NuGet to retrieve the correct dlls (change the value depending on your needs). For me I was compiling to platform x86. I don't know what NuGet was getting by default, but whatever it was had different file sizes for the same files.

You also should then add this tag:

<SelfContained>false</SelfContained>

or else your build will default to copying the entire framework.

Also note that using the RuntimeIdentifier tag will cause your default output folder to include the value you specified. For example my subfolder became:

Project\bin\x86\Debug\netcoreapp3.1\win-86\

For publishing you should be able to do something similar; the problem will be to match your RuntimeIdentifier to your platform. You shouldn't need to specify SelfContained unless you specifically need to.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dave Cousineau