The library hostpolicy.dll was not found
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.
Update for dotnet core 2.0 and beyond: 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.
If I'm not mistaken, one scenario when you can hit the issue is this: You have an integration project that references another application project (not library). In this case, dependentProject.runtimeconfig.json
won't be copied to your integration project's output folder and you won't be able to run dependentProject.exe
binary because it will throw The library hostpolicy.dll was not found.
.
There is a Github issue for this and a workaround.
Edit: Should be fixed in .NET SDK 5.0.200.