Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet exec with fx project got error The library 'hostpolicy.dll' required to execute the application was not found #3681

Closed
WeihanLi opened this issue Jul 10, 2019 · 5 comments

Comments

@WeihanLi
Copy link
Contributor

Steps to reproduce

I've upload a demo here https://github.com/WeihanLi/FxProjectDotNetExecBug

Expected behavior

should work like dotnet core project

Actual behavior

can not exec and get an error like

A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\projects\test\WebApplication1\WebApplication1\bin\Debug\net471\'.
Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\projects\test\WebApplication1\WebApplication1\bin\Debug\net471\WebApplication1.runtimeconfig.json file specifying the appropriate framework.

error

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview5-011568
Commit: b487ff10aa

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\

Host (useful for support):
Version: 3.0.0-preview5-27626-15
Commit: 61f30f5a23

.NET Core SDKs installed:
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.505 [C:\Program Files\dotnet\sdk]
2.1.507 [C:\Program Files\dotnet\sdk]
2.1.600 [C:\Program Files\dotnet\sdk]
2.1.601 [C:\Program Files\dotnet\sdk]
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.604 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.1.701 [C:\Program Files\dotnet\sdk]
2.2.102 [C:\Program Files\dotnet\sdk]
2.2.105 [C:\Program Files\dotnet\sdk]
2.2.200 [C:\Program Files\dotnet\sdk]
2.2.201 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]
2.2.301 [C:\Program Files\dotnet\sdk]
3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]
3.0.100-preview5-011568 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

@livarcocc
Copy link
Contributor

It seems like you are asking for dotnet to be able to activate full framework apps, given that your exe is a net472 app. I don't believe this is supported, but in any case, I am going to move this issue to dotnet/core-setup where they can confirm and close this issue or continue the conversation.

@livarcocc livarcocc transferred this issue from dotnet/cli Jul 10, 2019
@vitek-karas
Copy link
Member

I think the main confusion is the fact that .NET Core SDK can build .NET Framework apps, but .NET Core runtime can't run them. Unfortunately the dotnet.exe tool handles both cases.

  • dotnet build - is an SDK command, and it will be able to build .NET Framework apps - like the one in your repro. The app has TargetFramework=net471 which is .NET Framework target (.NET Core target would be something like netcoreapp2.2)
  • dotnet run is really just dotnet build and then start the executable produced by the build. So in this case it builds the app as .NET Framework and then it simply launches the .exe, which will launch using .NET Framework.
  • dotnet app.dll or dotrnet exec app.dll (or in your case dotnet app.exe) is a command to launch a .NET Core app. Since the app is built as .NET Framework it's missing some required files to run on .NET Core. Namely it would need a .runtimeconfig.json to run using preinstalled .NET Core runtime.

In a way this is not ideal design as it can be confusing, but it's been like this for several releases, we're unlikely to make changes here (too many things rely on this by now).

Not sure what is the scenario you're trying to solve:

  • If you want to run the app as .NET Core only - just build it for .NET Core
  • If you need an app which runs in both .NET Core and .NET Framework that is currently not supported (as in the exact same binaries can't run on both runtimes). The best option I know of is to multitarget. You can specify <TargetFrameworks>net471;netcoreapp2.2</TargetFrameworks> and dotnet build will produce two versions of the app, one for .NET Framework and one for .NET Core. So you can have one project and have it built for the two targets at the same time.

@WeihanLi
Copy link
Contributor Author

Hi @vitek-karas , I'm running a dot net framework project that use aspnetcore, I wanna host it with windows container, happen to find can not dotnet exec, from the information you supply above, a .rumtimeconfig.json is required, and I try to add a .runtimeconfig.json like follow:

{
    "runtimeOptions": {
      "tfm": "net471"
    }
  }

but it seemed not work either, is there a runtimeconfig.json document or sample for dot net framework project, I googled and searched on docs.microsoft.com, but nothing helps with dot net framework project, all about dot net core project

@vitek-karas
Copy link
Member

As mentioned above, the dotnet exec doesn't support running .NET Framework. It is only gonna run code on .NET Core.

The .runtimeconfig.json is an artifact only used by .NET Core.

If you want to run it on .NET Framework, why do you need to use dotnet exec, just start the .exe itself, it will run on .NET Framework automatically.

@WeihanLi
Copy link
Contributor Author

Got it, thanks @vitek-karas

@msftgits msftgits transferred this issue from dotnet/core-setup Jan 30, 2020
@msftgits msftgits added this to the Future milestone Jan 30, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants