The library hostpolicy.dll was not found

2019-01-11 21:39发布

I have a simple .NET Core project (console app) that I'm trying to compile and run. dotnet build succeeds, but I get the following error when I do dotnet run:

λ dotnet run
Project RazorPrecompiler (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in [path].

My project.json looks like this:

{
  "buildOptions": {
    "warningsAsErrors": true
  },
  "dependencies": {
    "Microsoft.AspNetCore.Razor": "1.0.0",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    }
  },
  "description": "Precompiles Razor views.",
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [ ]
    }
  },
  "version": "1.2.0"
}

What is hostpolicy.dll, and why is it missing?

4条回答
狗以群分
2楼-- · 2019-01-11 22:05

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.

查看更多
手持菜刀,她持情操
3楼-- · 2019-01-11 22:19

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.

查看更多
地球回转人心会变
4楼-- · 2019-01-11 22:20

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.

查看更多
贪生不怕死
5楼-- · 2019-01-11 22:23

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

查看更多
登录 后发表回答