1

I want my ASP.NET Core Web API to run as a self-contained exe within the .NET framework and not .NET Core Framework. Is that possible? Thanks!

EDIT:

If I add "net451": {} to my frameworks section in project.json, I get the following exception:

Failed to make the following project runnable: myProject (.NETCoreApp,Version=v1.0) reason: Expected coreclr library not found in package graph. Please try running dotnet restore again.
12
  • 3
    The answer is yes. I presume the "how" is implicit: use OWIN and use net45 as target framework. Those are technically two questions and you can easily find the answer if you search. codeproject.com/articles/869223/… Commented Jan 7, 2017 at 23:13
  • 1
    If you use ASP.NET Core and target net46 in your project.json, you have nothing to do. Just run a dotnet publish. That will generate an .exe file in the publish folder. Commented Jan 7, 2017 at 23:30
  • @Stefanod'Antonio: I think you are confusing self-hosting with self-contained Commented Jan 8, 2017 at 15:12
  • @Kalten: Same for you. The question is about self-containing, not self-executing/self-hosting learn.microsoft.com/en-us/dotnet/articles/core/deploying/…. Self-containing means there is no additional installation required (i.e. of a runtime) because the runtime is shipped with the application. This is not true for .NET 4.x and only possible with .NET Core (since its modular) Commented Jan 8, 2017 at 15:14
  • @Tseng a self-contained exe must be self-hosting and vice versa. How do you would you use an exe with IIS? If marrschine wrote self contained only I would have agreed. Commented Jan 8, 2017 at 15:15

1 Answer 1

2

You can't create a self-contained app which targets .NET Framework >=4.5, because the full .NET Framework isn't modular and its not possible to have more than one version of it installed. Newer versions basically always replace the previous one.

Self-contained apps were one main motivation for .NET Core (together with portability)

You ALWAYS have to install .NET >=4.5 before your app can run. self-contained apps only work with .NET Core because .NET core libraries can be pulled through nuget package.

For .NET 4.6 you can only create portable apps, which is the default mode.

Sign up to request clarification or add additional context in comments.

6 Comments

I think you might have meant .NET <= 4.5.
@GlennSills: I meant what I said ;) ASP.NET Core is based on System.Runtime which is only available with .NET 4.5. So ASP.NET Core can't run on any .NET Framework older than 4.5 because of this. .NET 4.5 is still one monolithic framework and can not be run side-by-side because its not modular. You always have to install it before you can run a .NET application on it. .NET Core is different. You can package everything together (Framework and application), so that merely unzipping the application will make it work w/o installing the specific runtime
Basically: Portable Apps = require runtime to be installed, smaller deployment. Self-contained apps = require no run time installation, but size of the deployment grows (because it the framework libraries need to be deployed with the app)
So, if I've understood correctly the .exe is not really self-contained, it is the directory containing the .exe that is self contained. There is no way to create a single .exe with everything statically bound into one file.
@GGleGrand: Self-contained in context of .NET Core refers to the ability to run without .NET Core runtime being installed on the system, because in this case the required .NET Core system libraries will be packaged with the application. In a portable .NET Core app this is different. The runtime packages won't be shipped with the application and require .NET Core to be installed before you can run the application on another system. As far as I know there is no way to create a single exe containing it all, except maybe ILMerge (google it), but not sure this still works with .NET Core
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.