Do .NET Core apps require the .NET runtime installed on the target machine? - asp.net

In this video, Scott Hanselman interviews a guy from the ASP.NET team. He says that one of the goals of ASP.NET 5, on top of .NET Core, is that the apps won't depend on the .NET Framework and GAC assemblies on the hosting server. Instead, .NET Core libraries will be released via NuGet packages and apps will be deployed with their dependencies.
One of the reasons for this is so Microsoft can quickly release a bug fix or new feature, and we don't have to wait until the new version (of the full framework) is installed on our hosting environment.
My question is:
Are the apps built on .NET Core really independent of the version of .NET installed on the target machine, and can they run even without the .NET Framework installed?

Yes, the framework you use in your application is completely independent of the .NET Framework installed on the target server, because the Core .NET Framework is referenced via NuGet packages and can be bundled up for deployment via the DNX Utility, specifically of interest to you will be the dnu publish command.
Here is an excerpt, describing what dnu publish does:
Publish (dnu publish)
The publish command will package your application into a self-contained directory that can be launched. It will create the following directory structure:
output/
output/packages
output/appName
output/commandName.cmd
The packages directory contains all the packages your application needs to run.
The appName directory will contain all of your applications code, if you have project references they will appear as their own directory with code at this level as well.
So the .NET Core will exist in the output/packages directory and will not need to be installed on the target server.

A normal .net core app requires that you install .net core on the machine you wish to run the application on. There is a way to avoid this however, by publishing a self contained app. You can publish your app with the requisite version of .net core included. This will make your app larger, but if you only need one application on a machine to run .net, you need a specific version of .net, or you want to make a portable application, this is a good choice.

Related

Is it possible to host an ASP.NET MVC app without the .NET Core runtime or sdk?

I am struggling to understand how all these frameworks interact and depend on each other: .NET Core, .NET Framework, ASP.NET Core, MVC, etc.
This discussion leads me to believe that my MVC app uses ASP.NET Core and .NET Framework, but not .NET Core. If that's true, can I run the MVC app without the .NET Core runtime? If not, why is this app still dependent on the .NET Core runtime?
What I tried
I created a new project in Visual Studio 2017 as follows:
ASP.NET Core Web Application
MVC
.NET Framework
ASP.NET Core 2.1
I published the app as follows:
dotnet publish --self-contained false (to prevent the runtime from being included)
Deploy new ec2 instance with windows server 2019
Install minimal set of dependencies (IIS, .NET Framework, Rewrite Module)
Deploy the published app to IIS
The app did not work at this point. I got a 500.19 with error code 0x8007000d. I got it working by installing the Hosting Bundle. I manually removed a few things that were installed with the hosting bundle, and found that "Microsoft .NET Core 2.1.28 - Windows Server Hosting" is required. I don't know exactly what that is, but it smells to me like the .NET Core runtime is somehow involved here.
Update
When I install the Hosting Bundle, I see a few important things get installed:
C:\Program Files\dotnet\dotnet.exe
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All\
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\
C:\Program Files\dotnet\shared\Microsoft.NETCore.App\
When I uninstall the .NET Core Runtime, I am left with just the following:
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All\
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\
The app still works at this point. I assume what remains is the ASP.NET Core Runtime, which is different than the .NET Core Runtime. I am just looking to confirm that this app is only dependent on the ASP.NET Core Runtime and .NET Framework, and not at all dependent on .NET Core.
We have a system that has CPU, memory, disk, network card, IO devices, etc. We need a software to manage these resources for us and let us use this system. That software is the kernel. (say Linux)
Now that we can control the hardware we need abstraction on top of it for daily usage for users. We need shell, windowing system, different kind of services and daemons. We call this whole package the Operating System. (say Ubuntu)
Now that we can happily use our computer, we want to write our own applications for our problems or maybe for other's problems. The OS provides us with a programming language and a library of functions and system calls that we can use to create software, just like the OS itself is using them. (say C and glibc)
Suddenly we realize that our software is not portable to other Operating Systems and it has a lot of complex boilerplate codes. So we create a new programming language and provide a new set of library functions but this time way easier to read and understand. (say C# and .NET 5 SDK)
But we have a problem. Our OS does not understand this new language. So we need a layer between our language and the OS. This piece of software must read our program and somehow translate it for the OS. This program is the Runtime. (say .NET 5 Runtime)
OK, let's review. We create an app with C# and .NET. this results in a program that is in the IL language. OS does not understand IL language, therefore we need the .NET runtime to read our IL app and translate it for the OS. But how do we set this up?
We have two options:
We install the .NET runtime on every system that needs to run our app; this way our app becomes portable but it needs the runtime to work.
We include the runtime code inside our app; this way our app does not need the runtime but it won't be portable anymore and since it carries the runtime it will be larger.
Now to clear a few of your confusions:
What is the difference between .NET Framework and .NET Core?
.NET Framework only runs on Windows and has more libraries to use.
.NET Core is cross-platform and has fewer libraries to use but is very fast. It now goes with the name .NET 5 and those extra Windows-only libraries have been added to it.
What is the difference between .NET SDK and Runtime?
SDK provides you with the tools you need to build an app with (SDK includes the Runtime as well).
Runtime is lighter and just runs your app.
What is the difference between .NET Core Runtime and ASP.NET Core Runtime?
.NET Core runtime (.NET 5 runtime now) can only run your console apps and is lighter.
ASP.NET Core runtime can run your web apps.
There are also runtimes for GUI apps capable of running WinForms and WPF apps (Windows-only).
What is MVC?
Model-View-Controller is a design pattern and it is not related to a specific language or framework.

How to run ASP.NET Core Web application on Linux?

I have an ASP.NET Web application that was successfully running on Linux with the help of dnx-mono NuGet package. I used to publish it by using dnx publish tool and run it with the command:
/opt/dnx-mono.1.0.0-rc1-update1/bin/dnx --appbase /path/to/json Microsoft.Dnx.ApplicationHost kestrel
Since dnx is obsolete, I want to get rid of it and migrate to .NET Core, but it does not work anymore on Linux.
Important: I cannot make my application .NET Core app because it uses some libraries (like MySQL.Data) that are still not available for .NET Core. Therefore, I create ASP.NET Core Web Application (notice .NET Framework):
I migrated the whole application and run it successfully on Windows, but my target is Linux. No more dnx publish, no problem - there is dotnet publish which works well and produces binaries. What now? Dnx-mono package does not have a "dotnet-something" successor, and using dotnet command with published binaries produced errors that I was not able to resolve (The library 'libhostpolicy.so' required to execute the application was not found), but I don't think that I should even use dotnet command with standalone binaries. Googling didn't help as most tutorials are focused around ASP.NET Web applications for .NET Core, not for .NET Framework. Version of Linux is Debian 8, dotnet command was obtained by following this guide. Any clue?
You cannot run an application on Linux that targets the full .Net Framework, it has to be Core only.

ASP.NET Core publish produces lots of DLLs in the published folder, why?

I created a simple Web API project in Visual Studio 2015 using the .NET Core Framework. When I publish this project using the default settings, it creates the following:
In total there are 155 DLLs, 77 in the PublishOutput root and 78 in the refs folder.
Why put all the DLLs in the publish folder? Couldn't it just
reference the DLLs where they were installed from a single shared
location ?
Dotnet core tend to be very minimal as opposed to the previous versions of .net framework.
In dotnet core, the main purpose was making the core framework as small as possible and if you need more stuff, bring it in through NuGet packages.
So, many dependencies that used to be available in the framework are now moved to the NuGet packages and as you know there is a chain of dependencies in NuGet packages, so we will end up with so many libraries in our publish output, which is fine.
Another point being, most of the time, we're using project templates with too many dependencies that might not be needed whatsoever. So we can either start with a very minimal template and add needed stuff in it, or remove useless stuff from a more chuncky template.
I had a similar issue. When my local computer was upgraded from Net Core 2.0 to 2.1, my Core We Application which references a NetStandard application started publishing all DLL's in all referenced projects. I migrated my Core 2.0 application to 2.1 to match the highest version of SDK installed on my local and I could see my issue is now resolved. Publishing from the migrated(upgraded) application produced only the required DLL's. Hope this helps.

Was the ability to run a .NET Core app from source code removed?

In previous versions of what is now .NET Core, using the dnx toolchain, it was possible to run an application straight from source code, without compiling to a DLL on disk. This capability was also present on Azure, allowing you to edit code on the server and have those changes reflected in the live site.
The new dotnet CLI run command seems to automatically create the familiar bin and obj folders with compiled DLLs in them, and the publish process from Visual Studio to Azure now no longer includes the C# source, just the DLL.
Is it no longer possible with the new CLI and other tools to run .NET Core code without creating a DLL on disk?
Short David Fowler response:
Dynamic compilation is gone in RC2. It only exists for views now. There are no plans to bring it back.
Why?
Architectural challenges and changes require to implement it on both .NET Framework and .NET Core. We did it with dnx and there were some problems (like some things being completely broken with in memory assemblies) that we chose to just avoid.

What do I need to install to compile Silverlight 2.0 applications on my build server

What's the minimum that I need to have installed on my Build Server (in addition to the standard .Net 3.5 stuff) to allow it to compile Silverlight 2.0 applications?
I have a Silverlight application that seems to be building correctly, but is not playing nicely with a related Web Application project - see this related question that I asked earlier: Silverlight xap file not being copied to ClientBin on Build Server
AFAIK you need Microsoft Silverlight 2 SDK to install on the build server.
HTH
Your build server should be pretty much an exact replication of your development machine as far as plug-ins, assemblies, run-times, SDK's etc.
You build server will be building your app via MSBuild.
In your particular case I suspect that you need to install the Silverlight Toolkit. This will give you the SL development runtime and the appropriate project build requisites for your XAP files to build and be deployed properly.

Resources