Full text translated from:Your First ASP. Application on a Mac Using Visual Studio Code
This article will show you how to write your first ASP. NET core application on a Mac.
The content of this article:
- Build the development environment
- Building Applications with Yeoman
- Developing ASP. NET applications using visual Studio core
- Use Kestrel to run this application locally
- Publish this application to Azure
- Learning Resources
Build the development environment
Download and install. Net core and Visual Studio Code with C # extensions on your development machine.
Building Applications with Yeoman
Create an ASP. NET core project by following the steps shown in building Projects with Yeoman.
Developing ASP. NET applications using visual Studio core
- Expand File>open, and navigate to the ASP. NET Core directory you created
At the Terminal/bash prompt, run the dotnet Restore project dependency. Alternatively, you can enter command shift pin visual Studio core as shown, and then type the dot to achieve the same goal.
You can run directly in visual Studio core, including all of the commands referenced in the project.json file in dotnet restore .
This empty project template is only used to show "Hello world!". Open Startup.cs in visual Studio core to see how this project is configured.
If this is your first time using Visual Studio Core (or just using this tool), just know: This tool provides a very smooth, fast and concise way of working, and writing code with her is very efficient.
In the left navigation bar, the four icons represent four functions, respectively:
Explore allows you to quickly navigate to any directory in the file system and, of course, makes it easy to view recently used files. At the same time, she identifies the file that was not saved or the newly created folder. You can easily create files (you don't even have to open a separate window). Also, you can easily save all the files in the menu options.
Search allows you to quickly find the file name or file content in the files directory.
If you have Git installed, the code will be fully integrated with Git. You can initialize the repository, commit the code, and so on in Git.
Debug supports debugging-time interaction (interactive debugging of applications).
Visual Studio Core has a lot of exciting features. As you can see, unused using statements are underlined and you can use command when the lamp icon appears . Remove them. Classes and methods will also show how many times they have been referenced in this project. If you have used Visual studio,visual Studio core with many of the same shortcut keys, such as command K C to annotate a block of code,command k u is used to uncomment.
Use Kestrel to run this application locally
This example uses the Kestrel configuration. You can see it in the project.json file, where it is specified as a dependency.
{ "version":"1.0.0-*", "compilationoptions": { "Emitentrypoint":true }, "Dependencies": { "Microsoft.NETCore.App": { "type":"Platform", "version":"1.0.0-rc2-3002702" }, "Microsoft.AspNetCore.Server.Kestrel":"1.0.0-rc2-final", "Microsoft.Extensions.Logging.Console":"1.0.0-rc2-final" }, "Frameworks": { "netcoreapp1.0": {} }}
- Run the dotnet Run command to launch the app.
- Open Browser, navigate to localhost:5000
- Enter Ctrl + C to stop the network server
Publish this application to Azure
If you've developed an application, you can push changes to your production environment using GIT, which is integrated into visual Studio core and runs on Azure.
Initialize git
Initialize git under the folder you're using. Tap the Git icon and click the Initialize Git repository button.
To add a submission overview, press Enter or click the Checkmark icon to submit the modified file.
Git tracks changes, so when you change a file, Git displays the file that changed since you last submitted it.
Initializing Azure Website
You can use Git to deploy apps directly to Auzre Web apps.
- Create a new Web App in Azure. If you don't have an azure account, you can create a new free account.
- To support "Use GIT for continuous deployment" (continuous deployment using GIT), configure the Web App in Auzre.
Remember that the Git URL is assigned to the app in the Azure portal.
- In the console window, add a remote service named Azure with the git URL you just remembered.
git remote add Azure https://[email protected]
Deploy with git push for Azure master .
- Browse the deployed Web App. You should see the Hello world! displayed
Learning Resources
- Visual Studio Code
- Building Projects with Yeoman
- Fundamentals
Create the first ASP. NET core application using Visual Studio code