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 run' fails for self-contained applications #791

Closed
eerhardt opened this issue Feb 2, 2017 · 6 comments
Closed

'dotnet run' fails for self-contained applications #791

eerhardt opened this issue Feb 2, 2017 · 6 comments
Assignees
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Feb 2, 2017

Using this project on a windows machine:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeFrameworkVersion>2.0.0-beta-001482-00</RuntimeFrameworkVersion>
    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
  </PropertyGroup>

</Project>
$ dotnet restore
$ dotnet run

Raises an error:

A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'F:\DotNetTest\DependencyTest\bin\Debug\netcoreapp2.0\'.

Notes

When initially designing .NET Core for MSBuild, we wanted the experience that "framework-dependent vs. self-contained was a publish time decision". That mean that you can take the same .csproj and without modifying it, publish as a "framework-dependent (a.k.a. portable/shared framework)" or a "self-contained" app. In order to support that, a decision was made that dotnet build and dotnet run were always framework-dependent.

However, this turns out to not be a great decision because there are scenarios where you want to target a .NET Core runtime that you haven't installed on the machine. In this case, you explicitly choose that you are a self-contained app, and you target the framework version (like a nightly build of Microsoft.NETCore.App) that you want. You still should be able to dotnet run your application. The only thing that works today is to dotnet publish and then execute the app, which IDEs don't typically do.

To enable this, I think the things that need to be done are:

  1. Copy the hostfxr and hostpolicy assemblies to the output folder
  2. (Optional) Copy the dotnet executable to the output folder and rename it to $(TargetName)[.exe]
    • If we do this, we also need to change the "Run Information" to point to this executable instead of the dotnet on the path.
  3. Set the output folder to have the RID in it.
    • This might not be required, but that's how project.json based projects did it.
      the dotnet muxer.

See https://github.com/dotnet/cli/blob/rel/1.0.0-preview2.1/src/Microsoft.DotNet.Compiler.Common/Executable.cs#L96-L108 for how this worked on project.json based projects. Specifically the CoreHost.CopyTo(_runtimeOutputPath, _compilerOptions.OutputName + Constants.ExeSuffix); part, which does the first two steps above.

@srivatsn
Copy link
Contributor

srivatsn commented Feb 3, 2017

This is the same as #527? @nguerrera

@Petermarcu
Copy link
Member

Does this mean F5 doesn't work on self contained apps?

@nguerrera
Copy link
Contributor

I think so. And what Eric describes is the fix I'm thinking about. I'll leave them both open for now.

@nguerrera nguerrera self-assigned this Feb 3, 2017
@nguerrera nguerrera added this to the 1.0 RTM milestone Feb 3, 2017
@nguerrera
Copy link
Contributor

I'm looking at making this change today.

@Petermarcu
Copy link
Member

@dougmsft is hitting this as he tries to use .NET Core.

@eerhardt
Copy link
Member Author

eerhardt commented Feb 3, 2017

This is the same as #527?

Yes, I believe so. dotnet run not working for self-contained apps is a consequence of not having the write build output for self-contained apps.

Closing this and adding dotnet run to the scenario on #527.

@eerhardt eerhardt closed this as completed Feb 3, 2017
mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
…0190717.11 (dotnet#791)

- Microsoft.AspNetCore.Mvc.Analyzers - 3.0.0-preview8.19367.11
- Microsoft.AspNetCore.Mvc.Api.Analyzers - 3.0.0-preview8.19367.11
- Microsoft.AspNetCore.Analyzers - 3.0.0-preview8.19367.11
- Microsoft.AspNetCore.Components.Analyzers - 3.0.0-preview8.19367.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants