Setting Up Your Development Environment

设置你的开发环境

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#扩展插件。Node.js和npm也是必须的,如果你的机器上没有,可以从Nodejs.org下载安装。

Scaffolding Applications Using Yeoman

使用Yeoman搭建应用

We will be using [yo aspnet] to generate the Web Application Basic template, you may follow the full instructions in Building Projects with Yeoman to create an ASP.NET Core project which show an Empty Web for reference.

我们将使用[yo aspnet]去生成Web应用程序的基础模板,你也可以按照Building Projects with Yeoman的步骤创建一个空的Asp.Net Core Web应用程序。

Install the necessary yeoman generators and bower using npm.

使用npm安装必要的yeoman生成器和bower

npm install -g yo generator-aspnet bower

Run the ASP.NET Core generator

运行Asp.Net Core生成器

yo aspnet
  • Select Web Application Basic [without Membership and Authorization] and tap Enter

  • 选择Web Application Basic [without Membership and Authorization] 然后回车

  • Select Bootstrap (3.3.6) as the UI framework and tap Enter

  • UI framework下选择Bootstrap(3.3.6) 然后回车

  • Use "MyFirstApp" for the app name and tap Enter

  • 使用“MyFirstApp”作为引用的名称,然后回车

When the generator completes scaffolding the files, it will instruct you to restore, build, and run the application.

当生成完成所需的文件后,它会提示你接下来该恢复、构建和运行这个应用程序。

Your project is now created, you can use the following commands to get going
cd "MyFirstApp"
dotnet restore
dotnet build (optional, build will also happen with it's run)
dotnet run

Developing ASP.NET Core Applications on a Mac With Visual Studio Code

在Mac上使用Visual Studio Code开发Asp.Net Core应用程序

  • Start Visual Studio Code

  • 打开Visual Studio Code

  • Tap File > Open and navigate to your ASP.NET Core app

  • 点击 File > Open,导航到你的Asp.Net Core应用目录

When the application is opened, Visual Studio Code will prompt to restore the needed project dependencies as well as add build and debug dependencies.

当应用程序被打开时,Visual Studio Code会提示恢复所需的项目依赖项以及添加构建和调试所需的依赖项。

Tap "Yes" to add the build and debug assets.

点击“Yes”添加所需构建和调试的部件。

Tap "Restore" to restore the project dependencies. Alternately, you can enter ⌘⇧P in Visual Studio Code and then type dot as shown:

点击“Restore”恢复项目所需依赖项。在开发中,你也可以在Visual Studio Code中按⌘⇧P进行恢复:

You can run commands directly from within Visual Studio Code, including dotnet restore and any tools referenced in the project.json file, as well as custom tasks defined in .vscode/tasks.json. Visual Studio Code also includes an integrated console where you can execute these commands without leaving the editor.

你可以直接在Visual Studio Code中运行包括恢复和使用 project.json中的项目引用,也可以在.vscode/tasks.json中自定义任务。Visual Studio Code还包括集成的控制台,你可以在不离开编辑器的情况下执行这些命令。

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.

如果这是你第一次使用Visual Studio代码(或刚用不久),你会发现它提供了一个非常精简,快速、干净的界面,快速处理文件,同时还提供了很多工具让编写代码非常富有成效。

In the left navigation bar, there are five icons, representing four viewlets:

在左边的导航栏中,有5个小图标,分别是:

  • Explore

  • Search
  • Git
  • Debug
  • Extensions

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.

VSCode已经集成了Git,你的系统如果已经安装好的话,可直接使用。你可以在Git视图里轻松的create repository,commits,和push。

The Debug viewlet supports interactive debugging of applications.

Debug视图支持与应用的交互式调试。

Code's editor has a ton of great features. You'll notice unused using statements are underlined and can be removed automatically by using ⌘ . when the lightbulb icon appears. 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 same keyboard shortcuts, such as ⌘KC to comment a block of code, and ⌘KU to uncomment.

VSCode编辑器界面也有很多非常棒的功能。当有黄色灯泡小图标时,你会发现没有在没有引用的声明下有下划线,可以使用⌘.自动修复。你的类和方法上会显示它们在项目中有多少次被引用。如果你曾经使用过Visual Studio,你会发现VSCode拥有很多相同的快捷键,比如⌘KC来注释代码,⌘KU来取消注释等等。

More on editor in Visual Studio Code.

更多功能查看Visual Studio Code

Running Locally Using Kestrel

使用Kestrel在本地运行

The sample is configured to use Kestrel for the web server. You can see it configured in the project.json file, where it is specified as a dependency.

示范已经使用Kestrel配置好Web Server了。你可以在project.json文件中看到它被配置成依赖项。

"Microsoft.AspNetCore.Server.Kestrel":

Using Visual Studio Code Debugger

使用Visual Studio Code调试

If you choose to have the debug and build assets added to the project:

如果需要调试的和构建的已经添加到项目中:

  • Tap the Debug icon in the View Bar on the left pane

  • 点击左侧面板中的Debug图标

  • Tap the "Play (F5)" icon to launch the app

  • 点击“Play(F5)”图片,运行应用。

Your default browser will automatically launch and navigate to http://localhost:5000

你的默认浏览器将自动运行并打开http://localhost:5000

  • To stop the application, close the browser and hit the "Stop" icon on the debug bar

  • 关闭浏览器点击调试条上的“Stop”图标,可以停止应用。

Using the dotnet commands

使用dotnet命令

  • Run dotnet run command to launch the app from terminal/bash

  • 在terminal/bash中运行dotnet命令

  • Navigate to http://localhost:5000

  • 浏览器打开http://localhost:5000

  • To stop the web server enter ⌃+C.

  • ⌃+C停止web服务器

Publishing to Azure

发布到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.

在你开发你的应用的时候,你能轻松的使用VSCode集成的Git更新到在Microsoft Azure上的生产环境。

Initialize Git

初始化Git

Initialize Git in the folder you're working in. Tap on the Git viewlet and click the Initialize Git repository button.

在你工作的文件中初始化Git。点击Git视图,再点击Initialize Git repository按钮。

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.

Git会跟踪更改,如果你更新了一个文件,Git视图会显示这个文件自最后一次提交后有更改。

Initialize Azure Website

初始化Azure Web站点

You can deploy to Azure Web Apps directly using Git.

你可以使用Git把应用程序部署到Azure。

Create a Web App in the Azure Portal to host your new application.

在Azure后台创建一个Web应用部署你的新应用程序。

Configure the Web App in Azure to support continuous deployment using Git.

在Azure上配置Web应用以使其支持Git。

Record the Git URL for the Web App from the Azure portal.

从Azure后台记录你的Git Url

In a Terminal window, add a remote named azure with the Git URL you noted previously.

在终端窗口中,添加一个名为azure提交到之前你记录的Git Url上。

git remote add azure https://shayneboyer@myfirstappmac.scm.azurewebsites.net:443/MyFirstAppMac.git

Push to master. git push azure master to deploy.

推送到master,git会推送到azure上相应的master。

Browse to the newly deployed web app.

打开浏览器浏览您的应用。

Looking at the Deployment Details in the Azure Portal, you can see the logs and steps each time there is a commit to the branch.

在Azure后台你可以查看开发的详细信息,包括每次提交到分支的日志和步骤。

原文链接

https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/your-first-mac-aspnet

【翻译】在Mac上使用VSCode创建你的第一个Asp.Net Core应用的更多相关文章

  1. 在mac上使用vscode创建第一个C++项目

    https://blog.csdn.net/bujidexinq/article/details/106539523 准备工作:安装好vscode安装插件『C/C++』正式开始:首先是创建一个空的文件 ...

  2. Mac上利用VScode配置c/c++开发环境

    Mac上利用VScode配置c/c++开发环境 哭辽,Typora里面最好不要插入表情,不然保存会闪退 首先你要有一个vscode 在扩展里面下载c/c++ 第一步 ⬆+com+p 打开命令模式:选择 ...

  3. 使用Visual Studio Code创建第一个ASP.NET Core应用程序

    全文翻译自:Your First ASP.NET Core Application on a Mac Using Visual Studio Code 这篇文章将向你展示如何在Mac上写出你的第一个A ...

  4. docker4dotnet #3 在macOS上使用Visual Studio Code和Docker开发asp.net core和mysql应用

    .net猿遇到了小鲸鱼,觉得越来越兴奋.本来.net猿只是在透过家里那田子窗看外面的世界,但是看着海峡对岸的苹果园越来越茂盛,实在不想再去做一只宅猿了.于是,.net猿决定搭上小鲸鱼的渡轮到苹果园去看 ...

  5. 用VSCode开发一个asp.net core 2.0+angular 5项目(4): Angular5全局错误处理

    第一部分: http://www.cnblogs.com/cgzl/p/8478993.html 第二部分: http://www.cnblogs.com/cgzl/p/8481825.html 第三 ...

  6. kubernetes高级之创建只读文件系统以及只读asp.net core容器

    系列目录 使用docker创建只读文件系统 容器化部署对应用的运维带来了极大的方便,同时也带来一些新的安全问题需要考虑.比如黑客入侵到容器内,对容器内的系统级别或者应用级别文件进行修改,会造成难以估量 ...

  7. 在mac上用parallels创建双windows虚拟机调试windows驱动

    先创建两个windows 7 虚拟机,一个装windbg作为调试机,一个被调试 1 调试机 1 先装windbg https://developer.microsoft.com/en-us/windo ...

  8. Golang 在mac上用VSCode开发、Delve调试

    本文包含以下内容: 1.安装VSCode: 2.用Delve调试Go项目: 3.自定义代码片段: 1.安装VSCode 先去下载VSCode,这个链接里面也有官方文档. 安装插件: vscode-ic ...

  9. 在Mac上使用vs-code快速上手c语言学习(入门文,老鸟退散)

    天下事,合久必分.分久必合,你肯定想不到当你逃离到Mac平台这么多年之后,有一天你会再用微软的产品来写代码 :) 其实微软的产品虽然用户体验总是做不到最好,但整体上的确拉低了行业的进入门槛,对于编程也 ...

随机推荐

  1. 快速构建Windows 8风格应用33-构建锁屏提醒

    原文:快速构建Windows 8风格应用33-构建锁屏提醒 引言 Windows Phone(8&7.5)和Windows 8引入了锁屏概念,其实做过Windows Phone 7.5应用开发 ...

  2. ubuntu安装wine之后进不了系统

    以前曾经装过一次wine,安装的时候没碰到什么问题,但卸载的时候却出问题了,把我nouvean显卡给删除了. 自然,我下一次启动的时候就进不了桌面了.所以我得重装一次,那一次重装的是整个系统! 今天突 ...

  3. ajax提交表单 验证

    function submitKH(mobileInputId,nameInputId) { var mobileInputSelector ='#'+ mobileInputId; var pass ...

  4. 输入 URL 到页面完成加载过程中的所有发生的事情?

    转到浏览器中输入URL给你一个页面后,.有些事情,你每天都在使用,学的是计算机网络知道是怎么回事.DNS解析然后页面的回馈,只是要讲好还是有难度. 之前fex团队的nwind专门写过这个问题的博客: ...

  5. 方向梯度直方图(HOG)和颜色直方图的一些比較

    近期在学习视频检索领域的镜头切割方面的知识,发现经常使用的方法是直方图的方法,所以才专门有时间来学习下.查看到这两种直方图的时候,感觉有点接近,好像又不同,放在这做个比較.大部分还是百科的内容,只是对 ...

  6. 【转】android创建Popwindow弹出菜单的两种方式

    方法一的Activity package com.app.test02; import android.app.Activity; import android.os.Bundle; import a ...

  7. .net图片裁剪抠图之性能优化

    //.net图片裁剪抠图:1.将不坐标点存入GraphicsPath中:GraphicsPath gPath = new GraphicsPath();2. 通常我们判断一个坐标点是否在闭合区间内通采 ...

  8. SQLSERVER 总结1

    数据:描述事物的符号记录 数据库:按照数据结构来组织和存储管理的数据仓库 数据库管理系统:位于用户与操作系统之间的一层数据管理软件 数据库系统:在计算机系统中引入数据库后的系统构成.由数据库,数据库管 ...

  9. Parameter Binding in ASP.NET Web API(参数绑定)

    Parameter Binding in ASP.NET Web API(参数绑定) 导航 阅读本文之前,您也可以到Asp.Net Web API 2 系列导航进行查看 http://www.cnbl ...

  10. Spring注解:@Resource、@PreConstruct、@PreDestroy、@Component

    要使用Spring的注解,必须在XML文件中配置有属性,告诉人家你要使用注解,Spring容器才会去加载类上的注解: <?xml version="1.0" encoding ...