Dotnet CLI

Dotnet CLI

Recently I wrote about how good angular works with .net core. And since I already went through that exercise I decided to share some of my experience with the Dotnet CLI and how to get your dotnet application up and running.

First, lets start by creating new dotnet application, the command is really simple, and it has options also for console or mvc applications. Here are some examples:

dotnet new
dotnet new console
dotnet new mvc

When adding on removing libraries from nuget, you must not forget to restore using

dotnet restore

In order to just run the application you can use

dotnet run

And finally when you want to get production ready build for your application, you can run

dotnet publish -c Release

All this so far is simple and straight forward. The only thing that needs a little more attention is when using entity framework. Here are the 3 thins you need to do in order to get entity framework up and running.

  1. Add Microsoft.EntityFrameworkCore.Tools.DotNet as a DotNetCliToolReference. See sample project below:
    <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    </ItemGroup>
  2. Execute dotnet add package Microsoft.EntityFrameworkCore.Design
  3. Execute dotnet restore. If restore does not succeed, the tools may not have installed correctly.

In some cases when you have model first approach you need

dotnet ef database update

Leave a Comment

Your email address will not be published. Required fields are marked *