Your First ASP.NET 5 Application on a Mac

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.

Sections:

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://[email protected]:443/rickmac.git
  • Push to master.
    • git push azure master to deploy.

  • Browse to the newly deployed web app.

Additional Resources

时间: 2024-10-12 17:15:37

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

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

ASP.Net中有两个重要的对象,一个是application对象,一个是session对象. Application:记录应用程序参数的对象,该对象用于共享应用程序级信息. Session:记录浏览器端的变量对象,用来存储跨网页程序程序的变量或者对象. 说实话,写了快一年的asp.net,application对象还真没怎么用过.看了看书,根据这两个对象的特性写了一个简单的聊天室程序.真的是非常的简陋. 我的思路是,有两个页面Default页和ChatRoom页,页面布局如图: Default

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 of the following exceptions: Exception 1 Exception type: FileNotFoundException Exception message: Could not load file or assembly 'App_Web_-e9dbmaj,

Asp.net Web Application 打开 SharePoint 2010 Site 错误 The Web application at could not be found

解决办法如下: 1. 修改项目的.net framework 为3.5 2. Application Pool 选用 Sharepoint App pool 3. 修改 web.config如下: <?xml version="1.0"?> <configuration> <configSections> <sectionGroup name="system.web.extensions" type="System

ASP.NET Web Application中使用链接文件

最近重构一个内部的平台系统,作为一个平台,其下有几个子系统,每个子系统有自己的网站系统.而每个网站使用的是统一的风格,统一的验证机制,反馈系统,等等.所以,为了避免几个子系统中重复出现相同的资源或文件,我打算将以前的ASP.NET Web Site全部转换为ASP.NET Web Application,然后通过链接外部公共文件的方式解决这个问题.同时: 1. Web Application是Web Site的升级产品.2. Web Application允许添加链接方式,把其他目录的文件作为链

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

ASP.NET中application对象的用法 本文导读:Application对象是HttpApplicationState类的一个实例,Application状态是整个应用程序全局的.Application对象在服务器内存中存储数量较少又独立于用户请求的数据.由于它的访问速度非常快而且只要应用程序不停止,数据一直存在,我们通常在Application_Start的时候去初始化一些数据,在以后的访问中可以迅速访问和检索. 一.Application对象的理解 Application对象在实际

[转]Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)

本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10) By      

ASP.NET之Application、Session和Cookie的区别

在Asp.net中Application.Session和Cookie都可以保存信息,那么它们有什么不同呢? 一.首先Application是在服务器端建立一个状态变量,存储于服务器的全局变量来存储所需信息.它是建立在内存中的,这个变量可以被网站的所有页面访问. 访问Application对象变量方法: Application["变量名"]=变量值        变量=Application["变量名"] 实例:可以用在网站统计用户的访问量,便于管理员对网站访问情况

[转]剖析ASP.Net MVC Application

http://www.cnblogs.com/errorif/archive/2009/02/13/1389927.html 为了完全了解Asp.net MVC是怎样工作的,我将从零开始创建一个MVC应用程序. 1.创建一个新的ASP.Net Web Application.它包括有一个Default.aspx页面,一个标准的web.config文件和添加一些初始的引用. 2.添加对“System.Web.Abstractions.dll”.“System.Web.Routing.dll” 和“

ASP.NET:Application,Session,Cookie,ViewState和Cache之间的区别(转)

在ASP.NET中,有很多种保存信息的对象.例如:Application,Session,Cookie,ViewState和Cache等,那么它们有什么区别呢?每一种对象应用的环境是什么? 为了更清楚的了解,我们总结出每一种对象应用的具体环境,如下表所示: 方法 信息量大小 保存时间 应用范围 保存位置 Application 任意大小 整个应用程序的生命期 所有用户 服务器端 Session 小量.简单的数据 用户活动时间+一段延迟时间(一般为20分钟) 单个用户 服务器端 Cookie 小量