ASP.NET 5 简介(Introducing ASP.NET 5)

编程语言 William 311浏览 0评论

The  first preview release of ASP.NET 1.0 came out almost 15 years ago.   Since then millions of developers have used it to build and run great  web applications, and over the years we have added and evolved many,  many capabilities to it. 

I’m excited today to post about a new  release of ASP.NET that we are working on that we are calling ASP.NET  5.  This new release is one of the most significant architectural  updates we’ve done to ASP.NET.  As part of this release we are making  ASP.NET leaner, more modular, cross-platform, and cloud optimized.  The  ASP.NET 5 preview is now available as a preview release, and you can  start using it today by downloading the latest CTP of Visual Studio 2015 which we just made available.

ASP.NET 1.0 的预览版发布距今大约已经 15 年前了。由于数以百万的开发者使用它构建和运行 web 应用,数年来我们添加并改进了它的无数功能。

非常高兴在今天发布了我们正在研发中的 ASP.NET 的新版本,我们称之为 ASP.NET 5。这次发布是我们为 ASP.NET 所做的最重要的架构升级之一。而且在这次发布中,我们让 ASP.NET 更为精益,更加模块化,更好的跨平台,并对云平台的支持做了进一步优化。ASP.NET 5 已经发布预览版啦 !点击下载 Visual Studio 2015  社区版来体验最新的 ASP.NET 5 吧!

ASP.NET  5 is an open source web framework for building modern web applications  that can be developed and run on Windows, Linux and the Mac. It includes  the MVC 6 framework, which now combines the features of MVC and Web API  into a single web programming framework.  ASP.NET 5 will also be the  basis for SignalR 3 – enabling you to add real time functionality to  cloud connected applications. ASP.NET 5 is built on the .NET Core  runtime, but it can also be run on the full .NET Framework for maximum  compatibility.

With ASP.NET 5 we are making a number of  architectural changes that makes the core web framework much leaner (it  no longer requires System.Web.dll) and more modular (almost all features  are now implemented as NuGet modules – allowing you to optimize your  app to have just what you need).  With ASP.NET 5 you gain the following  foundational improvements:

  • Build and run cross-platform ASP.NET apps on Windows, Mac and Linux

  • Built on .NET Core, which supports true side-by-side app versioning

  • New tooling that simplifies modern Web development

  • Single aligned web stack for Web UI and Web APIs

  • Cloud-ready environment-based configuration

  • Integrated support for creating and using NuGet packages

  • Built-in support for dependency injection

  • Ability to host on IIS or self-host in your own process

The  end result is an ASP.NET that you’ll feel very familiar with, and which  is also now even more tuned for modern web development.

ASP.NET 5 是一个用于构建现代 web 应用的开源 web 框架,它支持 Windows, Linux 和 Mac 平台。它包含 MVC6 框架,此框架将 MVC 和 Web API 整合成为一个单一的 web 编程框架。ASP.NET 5 还将成为 SignalR3 的基础 ,SignalR3 可以让你为“云应用”添加实时功能。ASP.NET 5 是在 .NET Core 运行时(.NET Core runtime)上构建的,但是为了保持最大的兼容性,它也可以运行在完全的 .NET Framework 框架之上。

在 ASP.NET 5 中,我们做了大量的架构调整,使得核心 web 框架更加精简(不再依赖 System.Web.dll)并且更加模块化(几乎所有的功能都被实现为 NuGet 模块 – 你可以通过只选择自己需要的模块来优化你的app)。ASP.NET 5 还包括下列改进:

  • 在 Windows, Mac 和 Linux 上构建和运行跨平台 ASP.NET 应用

  • 构建在 .NET Core 之上,它支持真正的并行应用版本化(side-by-side app versioning)

  • 新的工具用于简化现代 web 开发

  • 为 WebUI 和 Web APIs 提供了单一的技术栈

  • 为云平台准备的基于环境的配置方式

  • 整合了创建和使用 NuGet 包的功能

  • 原生支持依赖注入

  • 支持将应用部署在 iiS 或自己的 Web 服务上

ASP.NET 5 仍是你所熟悉的那个 ASP.NET,并且它更适于现代 web 编程

Flexible, Cross-Platform Runtime

ASP.NET  5 works with two runtime environments to give you greater flexibility  when hosting your app. The two runtime choices are:

.NET Core –  a new, modular, cross-platform runtime with a smaller footprint.  When  you target the .NET Core, you’ll be able to take advantage of some  exciting new benefits:

1) You can deploy the .NET Core runtime  with your app which means your app will run with this deployed version  of the runtime rather than the version of the runtime that is installed  on the host operating system. Your version of the runtime runs  side-by-side with versions for other apps. You can update that runtime,  if needed, without affecting other apps, or you can continue running on  the same version even though other apps on the system have been  updated.  This makes app deployment and framework updates much easier  and less impactful to other apps running on a system.

2) Your app  is only dependent on features it really needs. Therefore, you are never  prompted to update/service the runtime for features that are not  relevant to your app. You will spend less time testing and deploying  updates that are perhaps unrelated to the functionality of your app.

3)  Your app can now be run cross-platform. We will provide a  cross-platform version of .NET Core for Windows, Linux and Mac OS X  systems.  Regardless of which operating system you use for development  or which operating system you target for deployment, you will be able to  use .NET. The cross-platform version of the runtime has not been  released yet, but we are working on it on GitHub and plan to have an official preview of it out soon.

.NET Framework –  The API for .NET Core is currently more limited than the full .NET  Framework, so you may need to modify existing apps to target .NET Core.  If you don’t want to have to update your app you can instead run ASP.NET  5 applications on the full .NET Framework (version 4.5.2 and above).   When doing this you have access to the complete set of .NET Framework  APIs. Your existing applications and libraries will work without  modification on this runtime.

灵活的,跨平台的运行时环境

可以在两种运行时环境下使用ASP.NET 5,这让你在托管你的应用时有了更好的灵活性。这两种运行时环境分别为:

.NET Core –  一个新的,模块化的,可跨平台的而且更加精简的运行时。如果你决定使用 .NET Core,你将能够体验到以下它所带来的激动人心的功能:

1) 你可以将运行时环境连同你的应用一同部署,这意味着你的应用不再依赖你的托管环境的操作系统中所安装的运行时版本。你的应用可以使用与其他应用不同的运行时版本。你可以随时升级你的应用所需的运行时版本,这不会影响到其他的应用。同时,其他应用升级的时候,你仍可以使用旧版本的运行时。这让应用开发和框架升级变得更加容易,并且能够减少在同一个操作系统中运行的应用之间的相互影响。

2) 你的应用仅仅依赖那些你需要的功能。因此你不必为那些与你的应用无关的功能而升级运行时或打补丁。 这也可以让你节省一些测试和部署升级的时间,因为你不用花费精力在那些无关的功能上。

3)  你的应用可以跨平台运行啦。我们为 .NET Core 提供了跨平台支持,支持 Windows, Linux 和 Mac OS X 系统。无论你用哪个操作系统开发或者你想将应用部署到那个操作系统上,你都可以使用 .NET。不过跨平台版本的运行时目前还没有发布,我们正在 GitHub 上维护它,并计划在不久的将来发布它的官方预览版。

.NET Framework –  .NET Core 的API 相对于完整的 .NET Framework 来说有一些限制。 所以你需要修改你现有的应用去适应 .NET Core。如果你不想升级你的应用,ASP.NET 5 也支持部署到完整的 .NET Framework (需要 4.2 或更高版本)上。这样,你就可以使用完整的 .NET Framework API 了。你可以在不做修改的情况下,将已经存在的应用或类库运行在这个运行时上。

MVC 6 – a unified programming model

MVC,  Web API and Web Pages provide complementary functionality and are  frequently used together when developing a solution. However, in past  ASP.NET releases, these programming frameworks were implemented  separately and therefore contained some duplication and inconsistencies.  With MVC 6, we are merging those models into a single programming  model. Now, you can create a single web application that handles the Web  UI and data services without needing to reconcile differences in these  programming frameworks. You will also be able to seamlessly transition a  simple site first developed with Web Pages into a more robust MVC  application.

You can now return Razor views and content-negotiated data from the same controller and using the same MVC filter pipeline.

MVC 6-一个统一的编程模型

MVC,Web,API 和 Web 网页提供了互补的功能,当开发一个解决方案时,它们经常会一起被使用。然而,在以往的 asp.net 版本中,我们会分别来实现这些编程框架。因此它们包含有一些重复与不一致的地方。使用 mvc 6,我们可以把那些模型合并成一个简单的编程模型。现在,你可以创建一个处理web ui 和无需在这些编程框架里调和差异的数据业务的简单 web 应用程序。首先,你也可以无缝地转换一个在更强大的mvc应用程序里开发web页面的简单的网站。

你可以使用相同的 MVC 过滤器管道从同一个控制器恢复 Razor 视图和内容协商的数据。

 

 

In  addition to unifying the existing frameworks we are also adding new  features to make server-side Web development easier, like the new tag  helpers feature. Tag helpers let you use HTML helpers in your views by  simply extending the semantics of tags in your markup.

So instead of writing this:

@Html.ValidationSummary(true, “”, new { @class = “text-danger” })

<div class=”form-group”>

    @Html.LabelFor(m => m.UserName, new { @class = “col-md-2 control-label” })

    <div class=”col-md-10″>

        @Html.TextBoxFor(m => m.UserName, new { @class = “form-control” })

        @Html.ValidationMessageFor(m => m.UserName, “”, new { @class = “text-danger” })

    </div>

</div>

You can instead write this:

<div asp-validation-summary=”ModelOnly” class=”text-danger”></div>

<div class=”form-group”>

    <label asp-for=”UserName” class=”col-md-2 control-label”></label>

    <div class=”col-md-10″>

        <input asp-for=”UserName” class=”form-control” />

        <span asp-validation-for=”UserName” class=”text-danger”></span>

    </div>

</div>

Tag  helpers make authoring your views more natural and readable. They also  simplify customizing the output of HTML helpers with additional markup  while letting you take full advantage of the HTML editor.

For more examples of creating MVC 6 apps, see these tutorials.

为了统一现有框架我们增加了新特性来使服务端开发更加轻松,比如新的帮助标签特性。 帮助Tag 可以让你在视图中通过简单扩展标记语义来使用HTML辅助。

因此你不应该这样写:

@Html.ValidationSummary(true, “”, new { @class = “text-danger” })

<div class=”form-group”>

    @Html.LabelFor(m => m.UserName, new { @class = “col-md-2 control-label” })

    <div class=”col-md-10″>

        @Html.TextBoxFor(m => m.UserName, new { @class = “form-control” })

        @Html.ValidationMessageFor(m => m.UserName, “”, new { @class = “text-danger” })

    </div>

</div>

而应该这样写:

<div asp-validation-summary=”ModelOnly” class=”text-danger”></div>

<div class=”form-group”>

    <label asp-for=”UserName” class=”col-md-2 control-label”></label>

    <div class=”col-md-10″>

        <input asp-for=”UserName” class=”form-control” />

        <span asp-validation-for=”UserName” class=”text-danger”></span>

    </div>

</div>

辅助Tag使你的视图开发更加自然且提高可读性。他们也使得通过添加标记来简化HTML辅助输出的自定制,因此你会充分利用 HTML 编辑器。

如果需要更多创建MVC 6应用的例子,请看教程

Modern web development

This  week’s ASP.NET 5 preview also includes a number of other great  development features that enable you to build even better web  applications:

Dynamic Development

In  Visual Studio 2015, we take advantage of dynamic compilation to provide  a streamlined developer experience. You no longer have to compile your  application every time you want to see a change. Instead, just (1) edit  the code, (2) save your changes, (3) refresh the browser, and then (4)  see your change automatically appear.

image  

You  enjoy a development experience that is similar to working with an  interpreted language without sacrificing the benefits of a compiled  language.

You can also optionally use other code editors to work  on your ASP.NET 5 projects. Every function within the Visual Studio  user interface is matched with cross-platform command-line operations.

与流行的Web开发工具的集成(Bower, Grunt 和 Gulp)

在 Visual Studio 2015中另一个令人兴奋的特点是内置支持 Bower,GruntGulp —— 这些我们认为应该在每一个网页开发者工具集中放着的流行开源工具。

  • Bower 是一个客户端库包管理器,包括 JavaScript 和 CSS 库。

  • Grunt 和 Gulp 用于任务管理,帮您自动化Web开发工作流。您可以使用Grunt或Gulp像编译LESS,coffeescript,或TypeScript文件一样,运行JSLint,或压缩JavaScript文件。

Bower:如果要添加一个JavaScript库到您的ASP.NET项目,直接添加在bower.json配置文件:

image

注意,Visual Studio 将给你一个可用的软件包的 IntelliSense 提示。下一次打开解决方案时,Visual Studio 自动恢复任何丢失的包,所以你不需要检查包的源代码控制。

对于服务器端的软件包,您仍然可以使用 NuGet 包管理器。

Grunt: In  modern web development, you can find yourself managing a lot of tasks,  just to build your app: Compiling LESS, TypeScript, or CoffeeScript  files, linting, JavaScript minification, running JS unit tests, and so  on. Every team will have its own set of requirements, depending on the  particular tools that you use. Task runners make it easier to manage and  coordinate these tasks. Visual Studio 2015 will support two popular  task runners, Grunt and Gulp.

For example, let’s say you want to use Grunt to compile LESS files. Just go into package.json and add the grunt-contrib-less package, which is a third-party Grunt plugin.

image

Use  the new Task Runner Explorer in Visual Studio 2015 to bind the task to a  build step (pre-build, post-build, clean, or when the solution is  opened).

image

This  makes it incredibly easy to automate common tasks within your projects –  and have them work both for you, as well as across a team wide project.

Grunt:在现代网络的发展,你会发现你需要管理大量的任务,仅仅是建立你的应用程序而言:编译LESS,TypeScript,或 CoffeeScript 文件,linting,JavaScript 压缩,运行 JS 的单元测试,等等。每个团队都有自己的一套要求,取决于所使用的特定工具。任务管理器更容易管理和协调这些任务。Visual Studio 2015 将支持最流行的两种任务管理器,Grunt 和 Gulp。

例如,如果你要用 Grunt 编译 LESS。就去加入 grunt-contrib-less 包,这是一个第三方 Grunt 插件。

image

使用Visual Studio 2015中的新任务管理浏览器来绑定任务生成步骤(预生成,生成,清理,或解决方案打开时)。

image

这使得它非常易于实现在您的项目自动化常见任务,并让其配合你工作,甚至是整个团队项目。

Simplified dependency management

In  ASP.NET 5 you manage dependencies by adding NuGet packages. You can use  the NuGet Package Manager or simply edit the JSON file (project.json)  that lists the NuGet packages and versions used in your project. The  project.json file is easy to work with and you can edit it with any text  editor, which enables you to update dependencies even when the app has  been deployed to the cloud.

The project.json file looks like:

image

In Visual Studio 2015, IntelliSense assists you with finding the available NuGet packages that you can add as dependencies.

image

And, Intellisense can even help you with the available versions:

image

Simplified dependency management(简化的依赖关系管理)

在ASP.NET 5你可以添加NuGet包来管理依赖关系。您可以使用NuGet包管理器或简单地编辑JSON文件(project.json),其用于列出在你的项目中使用的NuGet包和版本。project.json的文件很容易使用,你可以用任何文本编辑器编辑它,甚至当应用程序被部署到云上也可以更新依赖关系。

project.json 文件看上去是这样子的:

image

在Visual Studio 2015,IntelliSense帮助您找到可用的可以添加依赖关系的NuGet包,。

image

而且,IntelliSense甚至可以帮助列出可用版本:

image

Cloud-ready configuration

In  ASP.NET 5, we eliminated the need to use Web.config file for  configuration values. We wanted to make it easier for you to deploy your  app to the cloud and have the app automatically read the correct  configuration values for that environment. The new system enables you to  request named values from a variety of sources (such as JSON, XML, or  environment variables). You can decide which formats work best in your  situation.

In the Startup.cs file, you can now add or remove the sources for configuration values.

image

The  above code snippet shows a project that is set up to retrieve  configuration values from a JSON file and environmental variables. You  can change this code if you need to specify other sources. In the  specified config.json file, you could provide the values.

image

In  your host environment, such as Azure, you can set the environmental  variables and those values are automatically used instead of local  configuration values after the application is deployed. You can deploy  your application without worrying about publishing test values.

Cloud-ready configuration(配置云准备)

在ASP.NET 5,我们不再需要使用Web.config文件来配置值。我们想让它为你部署你的应用程序到云更容易并让程序自动读取所处环境的正确配置值。新的系统允许您从各种源(如XML,JSON,或环境变量)请求命名值。你可以决定哪些格式以更好地配合工作。

在startup.cs文件中,你可以添加或删除配置值的源.

image

上面的代码段显示了一个项目中,建立JSON文件检索环境变量和配置值。如果你需要可以修改代码指定其他源。在这个json文件中你可以提供这些值。

image

你所在的环境,比如Azure,可以设置环境变量的值,在应用部署之后将自动代替本地配置值。部署应用程序时可以不必担心会发布测试值。


via:oschina

转载请注明:AspxHtml学习分享网 » ASP.NET 5 简介(Introducing ASP.NET 5)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址