Working with ASP.NET Core on Visual Studio Code
Tags: dotnet, vscode, csharp, dotvvm
Published: 2020-04-13 20:54:08

DotVVM is an open-source framework of ASP.NET that allows us to create web applications using the MVVM design pattern (Model View View-Model) design pattern using C# and HTML. 

Do you want to know more about DotVVM? To do this you can check its official website at: [www.dotvvm.com](www.dotvvm.com).

In this tutorial, we will learn how to work with DotVVM through the Microsoft source code editor: Visual Studio Code. Here are the contents:

1. DotVVM in the Visual Studio Code environment.  
2. Working with DotVVM in Visual Studio Code. 
3. Working with NuGet packages in Visual Studio Code.   
4. Plus: Deploy DotVVM applications with ASP.NET Core to Azure from Visual Studio Code.

##1: DotVVM in the Visual Studio Code environment##

+ .NET Core SDK 3.1 to work with ASP.NET Core: [https://dotnet.microsoft.com/download/dotnet-core/3.1](https://dotnet.microsoft.com/download/dotnet-core/3.1).
+ Visual Studio Code: [https://code.visualstudio.com/](https://code.visualstudio.com/).
+ DotVVM for Visual Studio Code: [https://marketplace.visualstudio.com/items?itemName=TomasHerceg.dotvvm-vscode](https://marketplace.visualstudio.com/items?itemName=TomasHerceg.dotvvm-vscode)

For the deployment of web applications with DotVVM we will also need the following extension:

+ Azure App Service: [https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureappservice](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azureappservice).

In addition, we can also add the extension of C-for features such as IntelliSense (autocomplete function), among others:

+ C#: [https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp).

##2: Working with DotVVM in Visual Studio Code##

When working with Visual Studio Code we will always be using commands to perform a particular action. To create a new terminal we go to the main menu and create a new one.

![](https://dev-to-uploads.s3.amazonaws.com/i/ud90bcpgjouo7dvv66v0.png)

DotVVM is a working environment that works on ASP.NET Core, so the base command will be `dotnet`. 

For our purposes, we will use the dotnet command to create web applications with DotVVM, run the applications, and generate the files needed to deploy them to Azure. 

The starting command is one that allows us to get information about all the operations we can perform with .NET: `dotnet --info`.

####Create a new ASP.NET Core app with DotVVM####

When we installed the .NET Core SDK, we received a variety of built-in templates for creating projects and files, including console applications, class libraries, unit test projects, ASP.NET Core applications (including Angular and React projects), and configuration files. To list the built-in templates that we have available, we can run the `dotnet new` command with the `--list` option. The results are as follows:

![](https://dev-to-uploads.s3.amazonaws.com/i/iqpup92vyyur2v80w1gx.png)

In order to create applications of type DotVVM we must add the respective template, for this, we can run the following command:

`dotnet new --install DotVVM.Templates::*`

By running the dotnet new -- list command again we can verify that the DotVVM template has been added correctly:

![](https://dev-to-uploads.s3.amazonaws.com/i/ymy1duolzoirbx87wm4w.png)

With this, what remains is to create a new project through the command:

`dotnet new dotvvm`

This process will take a few seconds:

![](https://dev-to-uploads.s3.amazonaws.com/i/dkjnqhtabi0oh0csda7j.png)

Upon completion, the files of the new DotVVM project will be created:

![](https://dev-to-uploads.s3.amazonaws.com/i/jh2yl9wjgef7br29bjqg.png)

####Run a DotVVM project in Visual Studio Code####

Now that we have created the project, the first thing we can do as the first activity is to run the project. To do this we use the following command:

`dotnet run`

As the first time building and running the project, this process can take a while. The next times the time will be less, all depending on the dimensions and components that are used in the project. When the complication process is finished, we will have available the paths to view the web application:

![](https://dev-to-uploads.s3.amazonaws.com/i/ippuipe94xsezq9fbls5.png)

Result: 

![](https://dev-to-uploads.s3.amazonaws.com/i/jyhrsiw42nrasedtz6ry.png)

##3: Working with NuGet Packages in Visual Studio Code##

When working on developing web applications, we will often need to add reusable code units, known as NuGet packages, for the implementation of some specific functionality.

Let's take an example. As developers of web solutions, we need to implement a website for student management, in which the aforementioned students can be added, modified, and deleted, in other words, perform CRUD operations (Create, Read, Update, and Delete) about a student's entity. 

To meet the objectives of the sample, you need to install the following NuGet packages in order to work with the database and with the development of the respective services:

+ Microsoft.EntityFrameworkCore
+ Microsoft.EntityFrameworkCore.SqlServer

To manage NuGet packages from our DotVVM project, you need to use the `dotnet` commands (CLI).

To add a NuGet package we will use the following command:

`dotnet add package <PACKAGE_NAME>`

Or the following command in case we want to specify the version as well:

`dotnet add package <PACKAGE_NAME> -v <VERSION>`

To list the NuGet packages associated with the project, you must use the following command:

`dotnet list package`

The result when listing the NuGet packages associated with the project in DotVVM is this:

![](https://dev-to-uploads.s3.amazonaws.com/i/fdinxxlj17f34f89n8oh.png)

The `dotnet run` execution of this case study is as follows:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/3roped0dhcxehbemm010.png)

The source code for this example can be found in the following repository on GitHub: [DotVVM Sample CRUD](https://github.com/esdanielgomez/DotVVMcrud).

##4: Plus: Deploy DotVVM apps with ASP.NET Core to Azure from Visual Studio Code##

As an additional addition to this article, we'll learn how to deploy a DotVVM project with ASP.NET Core in Visual Studio Code. To do this, you need to have the plug-in initially mentioned installed: *Azure App Service for Visual Studio Code*.

![](https://dev-to-uploads.s3.amazonaws.com/i/o66wssmxojow8s769qhr.png)

When you install the Azure extension, we will be asked to identify ourselves with our Azure account. 

As the first step in deployment, you need to prepare the necessary files for this process. To do this we use the following command:

`dotnet publish`

The result is as follows:

![](https://dev-to-uploads.s3.amazonaws.com/i/07p8jor9iuruj29yxoc4.png)

In this case, the command line tells us where these files were created, in this case in: `\bin\Debug\netcoreapp3.0\publish\`. 

What we have left for doing is to go to the *Publish* folder, right-click and select the option: Deploy to Web App.

![](https://dev-to-uploads.s3.amazonaws.com/i/c83bxmhvrv71vyk7aqp9.png)

Then a small pop-up box will be presented in which we will be asked to specify the App Service resource to deploy the application.  

Once the deployment to Azure is complete, a pop-up message in Visual Studio Code will tell us that the process is over and that we can view the published web page.

![](https://dev-to-uploads.s3.amazonaws.com/i/1py7ypiwuvf0tfh56q61.png)

In this case, the result of this post is similar to the student system example mentioned above, but already in Azure:

![](https://dev-to-uploads.s3.amazonaws.com/i/f0y7xsp8w62h57tz5s8w.png)

What's next?

With what we learned in this article, we can now work with web application development with the DotVVM work environment with ASP.NET Core in Visual Studio Code. Below are some additional resources that may be useful:

Want to know the steps to create a DotVVM app in Visual Studio 2019? To do this you can review this article: [Steps to create an MVVM application (Model-View-Viewmodel) with DotVVM and ASP.NET Core](https://dev.to/esdanielgomez/steps-to-create-an-mvvm-application-model-view-view-model-with-dotvvm-and-asp-net-core-fm2).

Want to take your first steps in developing web applications with ASP.NET Core and DotVVM? Learn more in this tutorial: [DotVVM and ASP.NET Core: Implementing CRUD operations](https://dev.to/dotvvm/dotvvm-and-asp-net-core-implementing-crud-operations-l2e).

Want to know everything you need to deploy web applications with ASP.NET Core and DotVVM in Azure? Learn more at: [Deploy DotVVM and .NET Core web applications to Azure (Everything you need to know)](https://dev.to/dotvvm/deploy-dotvvm-and-net-core-web-applications-to-azure-everything-you-need-to-know-3651).

Any concerns do not hesitate to write to me.
See you on [Twitter](https://twitter.com/enDanielGomez)!! :)