The library hostpolicy.dll was not found

冷暖自知 提交于 2019-11-27 14:34:36

Update for dotnet core 2.0: the file appname.runtimeconfig.json (for both debug and release configuration) is needed in the same path as appname.dll.

It contains:

{
  "runtimeOptions": {
    "tfm": "netcoreapp2.0",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "2.0.0"
    }
  }
}

then dotnet.exe exec "path/to/appname.dll" [appargs] works.

This error message is unhelpful. The actual problem is a missing emitEntryPoint property:

  "buildOptions": {
    ...
    "emitEntryPoint": true
  },

Once this is added, the compiler will let you know about any other problems (like a missing static void Main() method). Successfully compiling the project will result in an output that dotnet run can execute.

For me with ASP.NET Core 2.0 on Azure, it was the appname.deps.json that did the trick.

For me the issue was with the version mismatch. I had a different ".Net core SDK" version installed and a different version was specified in .json file.

Once I modified the version in my .json file the application started working fine.

In my case it was because I was publishing a self-contained application for the wrong target. My intent was to run on alpine linux, but I was building for libc when I should have been building for musl.

The failing package was built using:

dotnet publish --self-contained true --runtime linux-x64 --framework netcoreapp2.1 --output /app

Changing the RID:

dotnet publish --self-contained true --runtime linux-musl-x64 --framework netcoreapp2.1 --output /app

produced a functional package. Notice the RID changed from linux-x64 to linux-musl-x64. If I had read the .NET Core RID Catalog page this could have been avoided. 😅

For me it was a stupid mistake: I started a wrong file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!