Your First ASP.NET 5 Application on a Mac
Your First ASP.NET 5 Application on a Mac
By Daniel Roth, Steve Smith, Rick 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
- Install ASP.NET on your Mac with OS X
- Check which DNX version you have active by running
dnvm list
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 restore
and 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 |
{ |
- 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.
- Create a new Web App in Azure. If you don’t have an Azure account, you can create a free trial.
- Configure the Web App in Azure to support continuous deployment 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的更多相关文章
- First ASP.NET Core Application on a Mac Using Visual Studio Code
一直希望可以在mac上直接编写webapp (用C#)现在终于伴随着 core 世界美好了,不需要用pd windows了 nice. Visual studio code 更新1.1版本了 怀着激动 ...
- 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 ...
- ASP.NET中application对象
ASP.NET中application对象的使用. Application对象的应用 1.使用Application对象保存信息 (1).使用Application对象保存信息 Applicat ...
- ASP.NET 使用application和session对象写的简单聊天室程序
ASP.Net中有两个重要的对象,一个是application对象,一个是session对象. Application:记录应用程序参数的对象,该对象用于共享应用程序级信息. Session:记录浏览 ...
- [转]剖析ASP.Net MVC Application
http://www.cnblogs.com/errorif/archive/2009/02/13/1389927.html 为了完全了解Asp.net MVC是怎样工作的,我将从零开始创建一个MVC ...
- asp.net中application,cookies,stateview,session的使用
Cookie Cookie的用法也和ASP中差不多.比如我们建立一个名为aspcn,值为飞刀的cookie HttpCookie cookie = new HttpCookie["aspcn ...
- 源码学习之ASP.NET MVC Application Using Entity Framework
源码学习的重要性,再一次让人信服. ASP.NET MVC Application Using Entity Framework Code First 做MVC已经有段时间了,但看了一些CodePle ...
- ASP.NET之Application、Session和Cookie的差别
在Asp.net中Application.Session和Cookie都能够保存信息,那么它们有什么不同呢? 一.首先Application是在server端建立一个状态变量,存储于server的全局 ...
- ASP.NET中application对象的用法(面试题)
ASP.NET中application对象的用法 本文导读:Application对象是HttpApplicationState类的一个实例,Application状态是整个应用程序全局的.Appli ...
随机推荐
- 关于MPEG2中的图像序列和图像组头GOP
图像序列 图像序列是由图像组构成的,是随机存取段落. sequence_header_code – The sequence_header_code is the bit string ‘000001 ...
- .Net字符串驻留池
在.Net中,对于相同的字符串,.Net会将它们指向同一个地址,它们是相同的实例..Net中的字符串并不会更新,当更改一个字符串变量时,由于字符串的不可变性,.Net实际上是新创建一个字符串,而将变量 ...
- pig中变量
pig中的变量都是找到$变量然后替换,有点像宏,完全就是替换,看如下例子 %default m 'you';b = load 'a' as (a:chararray);c = foreach b ge ...
- 查找Safari相关迹证
日前有取证的同好提及Safari,想了解详细步骤,因而在此再补充说明相关. 除了Winodws外,Mac OS X也有为数不少的使用者,以下便以OS X自带的Safari浏览器为例,来查看有哪些重要迹 ...
- iPhone 6 (iOS 9.2) extractiion failed by XRY
My colleague extracted an iPhone 6 with XRY and it is iOS 9.2 . Unfortunately the Wizard crashed and ...
- leetcode 107
107. Binary Tree Level Order Traversal II Given a binary tree, return the bottom-up level order trav ...
- poj3122 pie
方法:二分. 题目意思:要过生日了,我请大家吃pie,然后人数一共是f+1(我自己).每个人的pie不能是拼接的,而且每个人的面积是一样的,这样就用二分枚举. 范围是0-最大的那块pie. 然后用每一 ...
- 实现IHttpModule接口,给每个页面输出一段脚本
在App_Code文件中添加TGModule.cs using System; using System.Data; using System.Configuration; using System. ...
- java编程思想第四版中 net.mindview.util包
操作系统: win8.1 编译环境 JDK1.6 编辑器 notepad++ 第48页练习8 1 下载相应程序包 Thinking in Java 4ed - CODE 2 设置相应的CLASSPAT ...
- Dev的DocumentManager添加窗体
1.DocumentManager要设置自己的MdiParent属性 2.主窗体设置IsMidContainer为True 3.要生成的窗体设置MdiParent为主窗体 4.正常创建窗体,然后就可以 ...