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

一直希望可以在mac上直接编写webapp (用C#)现在终于伴随着 core 世界美好了,不需要用pd windows了 nice。

Visual studio code 更新1.1版本了

怀着激动的心情尝试一下在mac上运行asp.net5 core application

首先你要下载 visual studio code

https://www.visualstudio.com/zh-cn/products/code-vs.aspx

安装ASP.NET 5 DNX(.NET执行环境)

dnx asp.net5 core的核心

github:https://github.com/aspnet/home#os-x

官网:https://www.microsoft.com/net

osx:https://www.microsoft.com/net/core#macosx

  1. Install pre-requisites

为了使用.NET的核心,你需要安装OpenSSL版本的更新

http://brew.sh/index_zh-cn.html

安装完成以后进入下一步:

        brew update

        brew install openssl

        brew link --force openssl

  1. Install .NET Core SDK

在你开始之前删除所有以前的版本,从你的系统中的网络核心,使用这个脚本。

https://raw.githubusercontent.com/dotnet/cli/rel/1.0.0/scripts/obtain/uninstall/dotnet-uninstall-pkgs.sh

官方安装包安装的最好方式。在OS X核心是利用官方PKG包。这个安装程序将安装这些工具并将它们放在你的路径上。

https://go.microsoft.com/fwlink/?LinkID=798400

  1. Initialize some code

现在可以写一个hello word 了。

mkdir hwapp :创建文件夹

cd hwapp :跳转路径

dotnet new :创建一个C#项目到hwapp文件夹

  1. Run the app

dotnet restore:恢复在project.json文件指定的包

dotnet run:执行应用

  1. and you're set!

你现在可以去github上看源代码了(不管你看不看 我反正没看)

What's Yeoman?

如果你来从Visual Studio .NET IDE 走过来的人,你会想,"是否有文件>新建> ASP.NET项目模板?"。 Visual Studio Code是基于文件的代码编辑器,它使你可以只打开一个文件,并开始编辑。 因此,我们将需要一些外部的帮助,让我们的ASP.NET项目模板加载。

Yeoman是一个流行的命令行工具,还提供了一个基本的ASP.NET模板开始。 Yeoman可使用NPM安装,这意味着你将需要安装Node.js(https://nodejs.org/en/download/)。

除了Yeoman,我们还需要一些其他的辅助工具,如ASP.NET GeneratorGrunt task runner and Bower。 您可以在一个命令执行此操作。 在命令提示符处键入以下命令,然后按Enter键:

npm install –g yo grunt-cli generator-aspnet bower(报错)

看到这个就正常了!不要用node.js 4.4.4用最新的6.2.0

总结如下:

创建Web应用程序

让我们通过scaffold创建一个新的ASP.NET 5 Web应用程序。

  1. 打开命令提示符,并要在其中创建新的Web应用程序导航到该位置

    cd hwapp

2.在命令提示符下输入以下命令 


yo aspnet

控制台应用程序

Web应用程序

网络应用基础(没有会员/验证)

网页API应用程序

nancy ASP.NET应用程序

类库

单元测试项目

我们选择(网络应用基础(没有会员/验证))

继续选择bootstrap 3.3.6

输入项目名称(hwapp)

完成后会有如下提示:

 

Your project is now created, you can use the following commands to get going

cd "hwapp"

dotnet restore

dotnet build (optional, build will also happen when it's run)

dotnet run

如果创建项目报上图错误

通常yeoman错误重新安装what's yeoman 步骤。

正常后如下图:

原文地址:https://www.cnblogs.com/sephiroth-wzc/p/5512467.html