Toggle navigation
首页
技术
骑行
羽毛球
资讯
联络我
登录
ASP.NET Core简介
2017-05-22
.NET Core
# .NET Core .NET Core是由微软官方维护的、开源免费的、跨平台(Windows, Linux, macOS)、跨架构(x86, x64, arm)的开发平台。 这意味着,.NET的开发者开发的应用程序,不用再和 windows server 和 IIS 绑定在一起,同一套应用程序,可以任意部署在windows、linux或者mac上,终于解放了。官方也提供了.NET Core的镜像,这样使得.NET的应用程式可以很方便的集成CI和自动测试与部署。 并且,有人做过简单的对比测试,在同样的硬件下,.NET Core 的性能是 .NET 的2倍,并且性能优于 Node 和 JAVA。 真的很振奋人心。 # .NET Core 包含 ## .NET Runtime (CoreCLR) 提供类型系统、程序集加载、垃圾回收器、本机互操作和其他基本服务。 Github源码: [https://github.com/dotnet/coreclr](https://github.com/dotnet/coreclr) ## Framework libraries (CoreFX) 框架类,包含 System.Collections, System.IO, System.Xml等类库 Github源码: [https://github.com/dotnet/corefx](https://github.com/dotnet/corefx) ## .NET Core SDK 用于构建app或者library,包含Command Line tools(CLI)。 CLI的Github源码: [https://github.com/dotnet/cli](https://github.com/dotnet/cli) # 安装 可以直接安装 vs community 2017,或者 vs code 加上 .NET Core SDK。 可以参照.NET Core首页: [https://www.microsoft.com/net/core](https://www.microsoft.com/net/core) # 使用 ## 查看CLI版本及使用帮助 启动cmd程序,运行如下命令会显示CLI的版本及用法。 dotnet --help 显示类似如下信息: ``` .NET Command Line Tools (1.0.4) Usage: dotnet [host-options] [command] [arguments] [common-options] Arguments: [command] The command to execute [arguments] Arguments to pass to the command [host-options] Options specific to dotnet (host) [common-options] Options common to all commands Common options: -v|--verbose Enable verbose output -h|--help Show help Host options (passed before the command): -d|--diagnostics Enable diagnostic output --version Display .NET CLI Version Number --info Display .NET CLI Info Commands: new Initialize .NET projects. restore Restore dependencies specified in the .NET project. build Builds a .NET project. publish Publishes a .NET project for deployment (including the runtime). run Compiles and immediately executes a .NET project. test Runs unit tests using the test runner specified in the project. pack Creates a NuGet package. migrate Migrates a project.json based project to a msbuild based project . clean Clean build output(s). sln Modify solution (SLN) files. Project modification commands: add Add items to the project remove Remove items from the project list List items in the project Advanced Commands: nuget Provides additional NuGet commands. msbuild Runs Microsoft Build Engine (MSBuild). vstest Runs Microsoft Test Execution Command Line Tool. ``` ## 新建及运行console项目 运行如下命令,会建立console项目,并初始化一些代码: ``` mkdir HelloWorld cd HelloWorld dotnet new console ``` 打开 Program.cs 文件,可以看到已经有初始化代码: ```C# class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); } } ``` 加载依赖包、构建并运行项目: ``` dotnet restore dotnet run ``` 输出: Hello World! # .NET Core 的不足 * .NET Framework 的API并没有全部移植过来,这代表着部分功能需要自己实现或者引入第三方实现。但随着时间的推移,.NET Core API也在不断丰富,比如 System.Net.Mail 已经在2.0版本中加入 * 如果你的应用程序需要集成一些服务商提供的服务,可能会找不到 .NET Core 版本的API,这意味着需要自己实现或者引入第三方实现,加大工作量。比如,阿里云 OSS 相关的 API 只有 .NET Framework 3.5 的版本 * 错误信息不友好,部分问题难以从错误信息中找到直观的信息 * 中文参考内容欠缺,很多问题需要在国外站点才能找到解答,对英文水平要求较高,需要翻墙从Google搜索 # 选择 .NET Core 还是 .NET Framework ? .NET Core 相比 .NET Framework 最大的变化,是支持 Linux 和 Mac,所以如果你并没有打算将 Server 换成 Linux,则完全没有必要绕远路来使用 .NET Core 如果你有如下的兴趣,则可以选择 .NET Core: * 走进开源社区 * 脱离 Windows Server 和 vs studio * 学习和使用Docker,快速打包和部署 * 在项目中集成敏捷开发,CI
×
本文为博主原创,如需转载,请注明出处:
http://www.supperxin.com
返回博客列表