What's new on ASP.NET Core RC2? dotnet cli on Windows

This is my first blog post ever! I decide to write a serie of blog posts to share some of my personal experience dealing with what's new on ASP.NET Core RC2. The first thing I have tested is the new dotnet cli. The .NET CLI is open source on GitHub and cross-platform, but in this post, I focus on Windows. So, let's get started and keep it simple!

How to install dotnet cli?

There is a new cool url dot.net , the previous url is also refering to the same web page get.asp.net

Let's clic on "Download .NET Core" and then choose Windows platform. If you prefer to develop with the command line, you can download the .NET Core SDK for Windows.

Five Steps

Let's initialize a sample Hello World application! First, I create a new directory I name it rc2 using the command md rc2 or mkdir rc2 . These commands are the same. Then, I change directory to rc2 using the command cd rc2 .

When I do dotnet new , 2 files are created : Program.cs and project.json. Those files are the minimum for doing an asp.net core RC2 console app.

The fourth command dotnet restore will restore the packages specified in the project.json file.

dotnet run compiles the project if it's not compiled otherwise it skipps that compilation phase to run the project. In this case, it prints "Hello World!" on the console.

If you want to chat with the community and read several pages of heated .NET Core debate, I invite you dear reader to invite yourself on the Slack address https://aspnetcore.slack.com where you will find almost 60 channels mainly #dotnet-cli highlighted here.

To fire Visual Studio Code, all you need is to type code .
alt but if you want to use Visual Studio Code Insiders just type code-insiders . in the command line to open the current folder.
alt One Visual Studio Code instance is opened. It asks you if you want to add required assets to build and debug which are missing from your project. Let's click "Yes"!

The fact that you click on "Yes", two json files are automatically generated. The first file is launch.json.

The second file is tasks.json.

Personally, I used to do a Ctrl+Shift+B to build my project. I really love that keyboard shortcut :-). Note here, I use some of my preferred C# 6 new feature which is using static directive. We can now import the static or enumerated members of a class into our namespace. We can then use the static members of a class directly without qualifying them with their namespace or type name! That's really awesome :-).

The debugger console warns us that symbols for rc2.dll could not be loaded. Even when we chose .NET Core Launch (console) in the combobox as show in the picture just below and hit F5, the debugger can't break on the breakpoint on the line #9.

So in order to generate PDB files, we should add an entry in the project.json exactly inside "buildOptions" node. This modification would change for the future version of Visual Studio Code. But for now, all what we need to write is "debugType": "portable". Do not forget the tailing , just after "emitEntryPoint": true in order to have a valid json file.

Here, I typed Ctrl+Shift+P to use the command mode of Visual Studio Code then I wrote ext to show installed extensions.

The required extension to do this build is the C# for Visual Studio Code extension. If you don't have it just type Ctrl+Shift+P then write install ext C#. You will need to restart Visual Studio Code on each extension install.

Tada! The breakpoint is reached and notice the Visual Studio Code status bar highlighted in a nice orange color.

That's all for this starting post. On the next post, I will write about dotnet cli on another different platform. Meanwhile, I will be pleased to hear your feedback.

comments powered by Disqus
Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.