Creating application in Windows through Visual Studio Code

Visual Studio is the IDE and is aware of projects and templates. As stated earlier, Visual Studio Code is a file and folder-based editor and hence it is not aware of projects and templates. So to create the same application through Visual Studio Code, we will make use of the .NET command line. Let's get going!

Open Visual Studio Code, go to View, and click on TERMINAL. It will open Command Prompt/the PowerShell terminal in the bottom section of Visual Studio Code. If you see the PowerShell terminal, type cmd so that it turns into Command Prompt. This is an optional step if you are comfortable with PowerShell.

Let's try and explore the commands available to create a new project, so let's type dotnet --help . This is the help command for dotnet and will let us know about the options that we have available for creating a .NET Core 2.0 MVC application as shown in the following screenshot:

The SDK lists all the possible commands and options that can be used with explanations. So keep in mind, any time you need any help with .NET commands, SDK is there to help us. Just ask for help by typing dotnet --help in the terminal.

From the command list, it looks like the command of interest to us is the new command, as its description reads that this command initializes .NET projects.

So, let's ask SDK how to use the new command by typing dotnet new --help. This will let us know the command that we need to run to create a new MVC application:

Based on the preceding help text, let's enter the following command:

dotnet new mvc -lang C# -n HelloDotNETCore2

This will create a new MVC project named HelloDotNetCore2 in the C# language, in the folder named HelloDotNetCore2 at the location of the terminal. Now let's build and run the application by typing the following commands:

cd HelloDotNetCore2
dotnet build
dotnet run

The first command navigates to the newly created folder, HelloDotNetCore2. Then, we build the application with the second command and run it through the third command. The dotnet build command is just to show that we have a build command as well. The dotnet run command actually builds and runs the application. Now, go to the browser of your choice and navigate to http://localhost:5000 to see the application running in your browser:

Alternatively, you can go to the Explorer view in the activity bar, open the HelloDotNetCore2 folder, and press F5. This will also build the application and launch it in the browser.

Steps for creating the application in Ubuntu through Visual Studio Code are the same as in Windows, but instead of Command Prompt, we have Bash.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset