asp.netdotnet coredotNET

使用vscode开发ASP.NET Core 1.0 - 开发基

2016-09-09  本文已影响1619人  taosilly

从新开始在Visual Studio Code 上开发程序.Net Core程序。

准备开发环境:

To setup your development machine download and install .NET Core and Visual Studio Code with the C# extension. Node.js and npm is also required. If not already installed visit nodejs.org.

.Net Core、Visual Studio Code 这两个是必须要安装了,C# extension就是在vscode中为.cs的文件提供语法高亮、智能感知、查找引用等。安装node.js因为里面使用了基于node.js的包管理和构建等组件。

vscode操作介绍

通过 dotnet new -t web 创建一个项目,使用vscode打开。

当打开vscode时提示还原项目依赖及添加生成和调试文件。
点击restore和yes,如果在提示关闭的情况下可通过Ctrl+Shift+P打开命令行去还原及生成。

主命令框
最重要的功能就是F1
或Ctrl+Shift+P
打开的命令面板了,在这个命令框里可以执行VSCode的任何一条命令,甚至关闭这个编辑器。按一下Backspace
会进入到Ctrl+P
模式里在Ctrl+P
下输入>
又可以回到Ctrl+Shift+P
模式。在Ctrl+P
窗口下还可以
直接输入文件名,跳转到文件?
列出当前可执行的动作!
显示Errors或Warnings,也可以`Ctrl+Shift+M:
跳转到行数,也可以Ctrl+G
直接进入@
跳转到symbol(搜索变量或者函数),也可以Ctrl+Shift+O
直接进入@:
根据分类跳转symbol,查找属性或函数,也可以Ctrl+Shift+O
后输入:
进入#
根据名字查找symbol,也可以Ctrl+T

如果你不了解vscode,请注意它提供了一个非常精简,快速,干净的界面,快速工作的文件,同时还提供工具,使编写代码非常有成效。

在左边的工具中有五项,分别是:

The Explorer 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.

而这个插件功能很好玩,你可以多装一些插件,来让你的vscode更强大。

使用脚手架 yoeman

在vscode中开发都变的很灵活,对于项目模板的创建,相应文件的生成我们使用角手架来操作。

使用npm安装

npm install -g yo generator-aspnet bower

运行 the ASP.NET Core generator

yo aspnet

完成后脚后架会指示下面操作

Paste_Image.png

当然这只是一个使用脚手架的实例,我更喜欢使用dotnet new -t web来创建web项目。

启动运行

转到调试界面,点击绿色小三角启动项目按F5。浏览器将启动并访问 http://localhost:5000/
如果你打开的网页中没有样式,那就是你的bower包没有下载。在插件中安装Bower重启,Ctrl+Shift+P 输入bower install ,稍等片刻就安装好了。

添加控制器和视图

使用vscode添加控制器和视图,环境要安装 yo 和 generator-aspnet 。VS Code 安装yo 插件 ext install yo

打命令面板(F1)输入 yo ,再选择aspnet,

这里应该显示子生成器才对,我这不知道怎么回事...

只能找开命令行操作了
详细使用参考 https://www.npmjs.com/package/generator-aspnet**

使用Git同步

打开Git窗口,点击“初始化Git”存储库。

添加一个消息提交到本地库,这时如果你没有配置用户名和邮件会提示你,然后你去配置你的Git。点击...弹出的菜单中有你常用的命令,另外可以去安装一个插件来增强使用。

上一篇下一篇

猜你喜欢

热点阅读