码迷,mamicode.com
首页 > Web开发 > 详细

Mac OS 环境下 安装 Asp.Net及使用Yeoman 创建Asp.Net 项目

时间:2015-07-21 15:05:12      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:macos   yeoman   asp.net 安装   

本文是按照英文原文:Installing ASP.NET 5 On Mac OS安装时遇到的问题的总结Blog。

原文提示如下:

Installing ASP.NET 5 On Mac OS X
By Steve Smith

ASP.NET 5 runs on the .NET Execution Environment (DNX), which is available on multiple platforms, including OS X. This article describes how to install DNX, and therefore ASP.NET 5, on OS X, using Homebrew.

In this article:
Install ASP.NET 5 on OS X
Install ASP.NET 5 on OS X
ASP.NET 5 requires DNX, which is installed and managed by the .NET Version Manager (DNVM). The DNVM is easily installed using a tool called Homebrew, which will also install the correct version of Mono for OS X.

Install Homebrew
The first step is to install Homebrew if it‘s not already installed. This can be done from a Terminal prompt using this script:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

The installer will inform you of the steps it is taking and pause before proceeding. You can learn more about Homebrew here.

he installer will inform you of the steps it is taking and pause before proceeding. You can learn more about Homebrew here.

到这一步,可能会出现 brew 已经安装了。
技术分享
可以执行:

brew -v

技术分享

Install the .NET Version Manager (DNVM)
Once Homebrew is installed, install the DNVM by running brew tap aspnet/dnx from a Terminal window. If you need to update your version of DNVM, first run brew untap aspnet/dnx to delete the old commands, and then run the brew tap aspnet/dnx command again to get the updated scripts.
技术分享

If you had an older version of our Homebrew "tap" configured, you might get the following error: Could not create link for aspnet/dnx/kvm, as it conflicts with aspnet/k/kvm. In that case, simply run brew uninstall kvm to ensure any old versions of kvm are removed, then brew untap aspnet/k to remove the old tap. After that, the brew tap aspnet/dnx command should succeed.

Next, run the command brew install dnvm to install the .NET Version Manager. This will also automatically install the latest DNX package from the https://www.nuget.org/api/v2 feed.

这一步可能出现没有权限的问题:
技术分享

执行

chown root:wheel /usr/local/bin/brew

然后执行

brew link mono

技术分享
完成安装。 一切正常了。

Next, run dnvm to verify that your terminal understands this command. If it does not, run the command source dnvm.sh to link it, then try running dnvm again. You should see something like this:

技术分享

 

使用Yemoman 创建Asp.net 项目

Mac 上 Asp.net 环境搭建好了以后,自己手动去开始一个 Asp.net 项目,是比较繁琐的。 Yeoman 上已经有 Asp.net 的 generator.

如果没有 Yeoman 先安装 Yeoman, Yeoman 的介绍: http://yeoman.io/ Yeoman下面有各种项目基础框架的generator

> npm install -g yo

安装 Asp.net generator

> npm install -g generator-aspnet

使用 yeoman 开启一个 Asp.Net 项目

> yo aspnet

这里使用 Nacy 框架, Nacy的介绍: http://nancyfx.org/ 一个轻量级的 .Net Web Framework

选择 Nacy ASP.Net Application
技术分享

同时给一个项目名字,这里用了 NacyApp
技术分享

项目基础文件框架就生产了。

进入 NacyApp 目录

执行

dnu restore 

加载 依赖
技术分享

如果 dnu 命令执行失败, commond not found.

执行命令:

source dnvm.sh

如果执行 dnu restore 出现 http://nuget.org/api/v2/ 取依赖包找不到的问题,切换一下源再试试,有两个可用的源:

1. https://www.myget.org/F/aspnetmaster/api/v2/
2. https://www.myget.org/F/aspnetvnext/api/v2/ 

例如:

dnu restore -s "https://www.myget.org/F/aspnetmaster/api/v2"

可以使用 core visual studio 打开工程,开始写程序。
技术分享

然后 dnx . kestrel 开始你的 NacyApp 就可以了
技术分享

技术分享

这里有个有意思的事情,在terminal 里执行了 dnx . kestrel 后,如果想退出, 执行 ctrl+c 了以后,看到 terminal 没有反应,在浏览器里刷新一下页面, terminal 会出一个错误, 就退出了。
技术分享

 

原博客地址:http://zhangsichu.com/blogview.asp?Content_Id=151

                  http://zhangsichu.com/blogview.asp?Content_Id=153


本文出自 “葡萄城控件技术团队博客” 博客,请务必保留此出处http://powertoolsteam.blog.51cto.com/2369428/1676657

Mac OS 环境下 安装 Asp.Net及使用Yeoman 创建Asp.Net 项目

标签:macos   yeoman   asp.net 安装   

原文地址:http://powertoolsteam.blog.51cto.com/2369428/1676657

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!