ASP.NET 5 Beta5来了(翻译)

在6月30日微软发布了ASP.NET 5 Beta5,咱们能够从http://nuget.org上获取Beta5 的packages。html

随着VS2015RC发布的ASP.NET 5的版本号是Beta4,因此你必定想在你的项目里使用这个更新。Beta5上不但修正了以前的一些问题并有了不少改进,并且还新增了不少功能。git

很重要一点,咱们应该知道有ASP.NET的运行时(用来运行你的网络应用)和Visual Studio上Web 工具(好比HTML、JavaScript编辑器和新文件对话框)。Beta5是对ASP.NET 5运行时的更新。github

ASP.NET 5 能够运行在全功能的.NET库和核心库。.NET核心库可以运行在Windows,Azure,Linux和Mac上。是时候开始安装beta5并应用到你的ASP.NET 5项目中去。json

下面是Beta 5的一些亮点:windows

.NET执行环境(DNX)api

  • 支持Nuget v3。
    使用Nuget v3的路径能够更快地下载packages。尝试添加https://api.nuget.org/v3/index.json做为package源。
  • 支持全新的.NET目标框架监测器(TFM)。
  • 在project.json中能够设置语言和发布说明的连接
  • 消除了对JSON.NET的固定版本要求:即再也不要求你的应用程序使用和DNX一致的JSON.NET版本,你能够选择新发布的JSON.NET而不须要升级DNX的版本号。
  • 新的IRuntimeEnvironment服务。使用新的Service能够获取到运行时具体信息,像OS,CLR等。

ASP.NET 5服务器

  • HttpContext.Connection
    经过HttpContext的新加Connection属性能够得到链接的信息。
  • 新增本地化的抽象和中间件
    你能够在本地化的Sample里发现这些东西的使用。
  • 统一终止ASP.NET宿主环境的快捷键为Ctrl+C
    以前按任意键便可终止ASP.NET宿主环境的,如今统一终止快捷键为Ctrl+C。
MVC 6
  • 在Razor支持C# 6
    你能够经过MSDN上C# 6 了解C# 6的新特性。
  • 简化了MVC的选项设置,添加了顶级配置
    如今有了应用层的设置,能够用来为HTML helpers配置各类不一样的设置。
  • 在视图中可使用JSON Helper来序列化数据模型
    该功能可让你在Razor view中很是容易地序列化你的.NET对象成JSON格式:
    @Json.Serialize(Model)
  • 在Route标记中可以使用通配替换
    [Route("Products/[action]", Name = "[actions]Products")]
    public class ProductsController
    {
        public void Add() { }
        public void Buy() { }
    }
  • 新的ImageTagHelper
    <img asp-file-version="true" src="~/images/my_cool_image.png" />  
  • Tag Helper支持绑定字典属性
    如今你能够在TagHelpers中绑定服务器端的attributes到字典属性。好比,AnchorTagHelper利用名字格式为asp-route-*的attributes来设置路由值。
    <a asp-action="Edit" asp-route-id="@index">Edit</a>
  • Tag Helper支持基于服务端attributes设置的条件绑定
    你能够利用TargetElementAttribute中Attributes属性来指定当前TagHelper应用到拥有某些attributes的tag上。好比AnchorTagHelper类的定义以下:
        [TargetElement("a", Attributes = ActionAttributeName)]
        [TargetElement("a", Attributes = ControllerAttributeName)]
        [TargetElement("a", Attributes = FragmentAttributeName)]
        [TargetElement("a", Attributes = HostAttributeName)]
        [TargetElement("a", Attributes = ProtocolAttributeName)]
        [TargetElement("a", Attributes = RouteAttributeName)]
        [TargetElement("a", Attributes = RouteValuesDictionaryName)]
        [TargetElement("a", Attributes = RouteValuesPrefix + "*")]
        public class AnchorTagHelper : TagHelper
        {
            private const string ActionAttributeName = "asp-action";
            private const string ControllerAttributeName = "asp-controller";
            private const string FragmentAttributeName = "asp-fragment";
            private const string HostAttributeName = "asp-host";
            private const string ProtocolAttributeName = "asp-protocol";
            private const string RouteAttributeName = "asp-route";
            private const string RouteValuesDictionaryName = "asp-all-route-data";
            private const string RouteValuesPrefix = "asp-route-";
            private const string Href = "href";
    
            ...
        }
    

    从上面能够看出,该TagHelper会应用到A tag上,而且这个tag上须要有asp-action, asp-controller, asp-fragment, asp-host, asp-protocol, asp-route, asp-all-route-data和asp-route-*这些attributes中一个或一个以上,不然该tag就会绑定到该TagHelper。好比网络

    <a href="http://www.cnblogs.com/liontone/">上善若水</a>
    

    就不会被应用上AnchorTagHelper。框架

你们能够在这里看到比较关于Beta5的详细的信息以及关于Beta5已知的问题。后续也会有更多的beta版本发布知道最终正式发布为止。asp.net

Beta5和Visual Studio 2015 RC是兼容的,你能够利用Visual Studio 2015 RC来打开、编译和运行基于Beta5运行库的ASP.NET 5应用。

在Visual Studio 2015RC上升级到Beta5须要作一下几步:

  • 若是以前没有安装,请安装 .NET Version Manager (DNVM)。若是已经安装了Visual Studio,请忽略这一步,直接进入下一步。
  • 设置系统环境变量DNX_FEED值为https://www.nuget.org/api/v2
  • 执行“dnvm upgrade”,升级dnx的版本号到Beta5
  • 更新应用中的global.json文件的sdk版本号到"1.0.0-beta5"(DNX)
  • 更新应用的依赖库的版本号到beta5
  • Restore新版本的依赖库
  • 编译应用并根据beta5的须要作相应的migration.

在beta5还有一些break changes,更详细的信息请参考Beta5 Release Note,但愿你们可以喜欢Beta5。

相关文章
相关标签/搜索