Your First ASP.NET 5 Application on a Mac

By Daniel RothSteve SmithRick Anderson

ASP.NET 5 is cross-platform; you can develop and run web apps on Mac OS X, Linux and Windows. This article will show you how to write your first ASP.NET 5 application on a Mac.

Setting Up Your Development Environment

Scaffolding Applications Using Yeoman

Follow the instruction in Building Projects with Yeoman to create an MVC 6 project.

Developing ASP.NET Applications on a Mac With Visual Studio Code

  • Start Visual Studio Code

Note

If Visual Studio Code is not installed, see Install ASP.NET on your Mac with OS X.

  • Tap File > Open and navigate to your ASP.NET app

From a Terminal / bash prompt, run dnu restore to restore the project’s dependencies. Alternately, you can enter command shift p and then type >d as shown:

This will allow you to run commands directly from within Visual Studio Code, including dnx restoreand any commands defined in the project.json file.

At this point, you should be able to host and browse to this simple ASP.NET web application, which we’ll see in a moment.

This empty project template simply displays “Hello World!”. Open Startup.cs in Visual Studio Code to see how this is configured:

If this is your first time using Visual Studio Code (or just Code for short), note that it provides a very streamlined, fast, clean interface for quickly working with files, while still providing tooling to make writing code extremely productive.

In the left navigation bar, there are four icons, representing four viewlets:

  • Explore
  • Search
  • Git
  • Debug

The Explore viewlet allows you to quickly navigate within the folder system, as well as easily see the files you are currently working with. It displays a badge to indicate whether any files have unsaved changes, and new folders and files can easily be created (without having to open a separate dialog window). You can easily Save All from a menu option that appears on mouse over, as well.

The Search viewlet allows you to quickly search within the folder structure, searching filenames as well as contents.

Code will integrate with Git if it is installed on your system. You can easily initialize a new repository, make commits, and push changes from the Git viewlet.

The Debug viewlet supports interactive debugging of applications. Currently only node.js and mono applications are supported by the interactive debugger.

Finally, Code’s editor has a ton of great features. You should note right away that several using statements are underlined, because Code has determined they are not necessary. Note that classes and methods also display how many references there are in the project to them. If you’re coming from Visual Studio, Code includes many of the keyboard shortcuts you’re used to, such ascommand k c to comment a block of code, and command k u to uncomment.

Running Locally Using Kestrel

The sample is configured to use Kestrel for the web server. You can see it configured in theproject.json file, where it is specified as a dependency and as a command.

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 {
"version": "1.0.0-*",
"userSecretsId": "aspnet5-MyWebApp-a1b07c55-6f20-4aaf-9852-9c964160a00c",
"compilationOptions": {
"emitEntryPoint": true
},
"tooling": {
"defaultNamespace": "MyWebApp"
}, "dependencies": {
"EntityFramework.Commands": "7.0.0-rc1-final",
// Dependencies deleted for brevity.
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
}, "commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
}, // Markup deleted for brevity. "scripts": {
"prepublish": [
"npm install",
"bower install",
"gulp clean",
"gulp min"
]
}
}
  • Run the dnx web command to launch the app
  • Navigate to localhost:5000:

  • To stop the web server enter Ctrl+C.

Publishing to Azure

Once you’ve developed your application, you can easily use the Git integration built into Visual Studio Code to push updates to production, hosted on Microsoft Azure.

Initialize Git

Initialize Git in the folder you’re working in. Tap on the Git viewlet and click theInitialize Git repository button.

Add a commit message and tap enter or tap the checkmark icon to commit the staged files.

Git is tracking changes, so if you make an update to a file, the Git viewlet will display the files that have changed since your last commit.

Initialize Azure Website

You can deploy to Azure Web Apps directly using Git.

Record the Git URL for the Web App from the Azure portal:

  • In a Terminal window, add a remote named azure with the Git URL you noted previously.

    • git remote add azure https://Rick-Anderson@rickmac.scm.azurewebsites.net:443/rickmac.git
  • Push to master.

    • git push azure master to deploy.

  • Browse to the newly deployed web app.

Your First ASP.NET 5 Application on a Mac的更多相关文章

  1. First ASP.NET Core Application on a Mac Using Visual Studio Code

    一直希望可以在mac上直接编写webapp (用C#)现在终于伴随着 core 世界美好了,不需要用pd windows了 nice. Visual studio code 更新1.1版本了 怀着激动 ...

  2. You may receive an exception when you browse a .NET Framework 2.0 ASP.NET Web application

    SYMPTOMS When you browse a Microsoft .NET Framework 2.0 ASP.NET Web application, you may receive one ...

  3. ASP.NET中application对象

    ASP.NET中application对象的使用. Application对象的应用  1.使用Application对象保存信息  (1).使用Application对象保存信息  Applicat ...

  4. ASP.NET 使用application和session对象写的简单聊天室程序

    ASP.Net中有两个重要的对象,一个是application对象,一个是session对象. Application:记录应用程序参数的对象,该对象用于共享应用程序级信息. Session:记录浏览 ...

  5. [转]剖析ASP.Net MVC Application

    http://www.cnblogs.com/errorif/archive/2009/02/13/1389927.html 为了完全了解Asp.net MVC是怎样工作的,我将从零开始创建一个MVC ...

  6. asp.net中application,cookies,stateview,session的使用

    Cookie Cookie的用法也和ASP中差不多.比如我们建立一个名为aspcn,值为飞刀的cookie HttpCookie cookie = new HttpCookie["aspcn ...

  7. 源码学习之ASP.NET MVC Application Using Entity Framework

    源码学习的重要性,再一次让人信服. ASP.NET MVC Application Using Entity Framework Code First 做MVC已经有段时间了,但看了一些CodePle ...

  8. ASP.NET之Application、Session和Cookie的差别

    在Asp.net中Application.Session和Cookie都能够保存信息,那么它们有什么不同呢? 一.首先Application是在server端建立一个状态变量,存储于server的全局 ...

  9. ASP.NET中application对象的用法(面试题)

    ASP.NET中application对象的用法 本文导读:Application对象是HttpApplicationState类的一个实例,Application状态是整个应用程序全局的.Appli ...

随机推荐

  1. java 中byte[] 数组的合并

    因工作的需要,在从事 .Net 的开发中接触到了 Java, 虽然在大学的时候学过一段Java 编程,但并没有在实际的工作中使用过, Java 和 .Net的C#语法很相似,都是面向对象的,感觉在语法 ...

  2. android Camera使用(一)

    现在的App不可避免的要使用到手机的相机功能 首先我们先来介绍下最简单的一个实现方式,启动系统自带的Activity 上代码: public void openCamera() { Intent i= ...

  3. angular 页面加载时可以调用 函数处理

    转载于 作者:海底苍鹰地址:http://blog.51yip.com/jsjquery/1599.html 我希望页面加载的时候,我能马上处理页面的数据,如请求API .... 所以这样设置 在某个 ...

  4. WP8——页面跳转方法

      1.页面传值: this.NavigationService.Navigate(new Uri("/SecondPage.xaml?CustomerId=1234&Product ...

  5. A planning attack on a commuter train carriage in Taipei

    Last night an explosion on a commuter train carriage in Taipei Songshan railway station wounded at l ...

  6. leetcode 14

    14. Longest Common Prefix Write a function to find the longest common prefix string amongst an array ...

  7. Chrome不能登录和同步的解决方法

    打开 C:\Windows\System32\drivers\etc 下的 hosts文件 #SmartHosts START #Google Services START .docs.google. ...

  8. 说一个Sublime Text 2插件、emmet(原名:zen Coding)

    工具/原料 sublime Text 2 安装emmet插件 方法/步骤 生成html文档初始结构: !<tab> <!doctype html> <html lang= ...

  9. Mysql启停以及恢复备份恢复数据库

    1.mysql启停 进入cmd 输入如下命令 net stop mysql(自己起的mysql名称) -------停 net strat mysql   ---------------------- ...

  10. [原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛

    本文出自:http://blog.csdn.net/svitter 原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&am ...