是否可以在没有 .NET Core 运行时或 sdk 的情况下托管 ASP.NET MVC 应用程序? [英] Is it possible to host an ASP.NET MVC app without the .NET Core runtime or sdk?

查看:52
本文介绍了是否可以在没有 .NET Core 运行时或 sdk 的情况下托管 ASP.NET MVC 应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力理解所有这些框架如何交互和相互依赖:.NET Core、.NET Framework、ASP.NET Core、MVC 等.

好的,让我们回顾一下.我们使用 C# 和 .NET 创建了一个应用程序.这会产生一个使用 IL 语言的程序.操作系统不理解 IL 语言,因此我们需要 .NET 运行时来读取我们的 IL 应用程序并将其翻译为操作系统.但是我们如何设置它?

我们有两个选择:

  1. 我们在每个需要运行我们的应用程序的系统上安装 .NET 运行时;这样我们的应用就变得可移植了,但它需要运行时才能工作.

  2. 我们在应用程序中包含运行时代码;这样我们的应用就不需要运行时,但它不再是可移植的,因为它携带运行时它会更大.

现在来消除您的一些困惑:

.NET Framework 和.NET Core 有什么区别?

.NET Framework 仅在 Windows 上运行,并且有更多的库可供使用.

.NET Core 是跨平台的,使用的库较少,但速度非常快.现在它的名称是 .NET 5,并且添加了那些额外的仅限 Windows 的库.

.NET SDK 和运行时有什么区别?

SDK 为您提供了构建应用所需的工具(SDK 还包括运行时).

运行时间更轻,只运行您的应用程序.

.NET Core 运行时和 ASP.NET Core 运行时有什么区别?

.NET Core 运行时(现在是 .NET 5 运行时)只能运行您的控制台应用程序并且更轻.

ASP.NET Core 运行时可以运行您的 Web 应用程序.

还有用于运行 WinForms 和 WPF 应用程序(仅限 Windows)的 GUI 应用程序的运行时.

什么是MVC?

模型-视图-控制器是一种设计模式,与特定的语言或框架无关.

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:

  1. 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.

  2. 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.

这篇关于是否可以在没有 .NET Core 运行时或 sdk 的情况下托管 ASP.NET MVC 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆