This is a series on the new .Net Core bits.

We finally got some finalised bits in a release this week. So here is a bit of a guide to get you started. I will (probably) be only showing instructions from on Windows, but all dotnet CLI instructions should be cross platform.

Installation

TL;DR => Just uninstall and reinstall following the instructions here: https://www.microsoft.com/net/core#windows

This URL is fun spoken rather than written, dot.net (dot dot net). This is where you go to get started.

Before you start, please remove any previous versions of .NET Core from your system by using Add/Remove programs. Also, please verify that you have all of the Windows dependencies installed.

I didnt read this. Read this. After installing the Visual Studio 2015 Update 3 and .NET Core for Visual Studio official MSI Installer, I had to actually go back and uninstall .Net Core RC2 preview 1. As this stack overflow answer says:

After you install RC2, Make sure your control panel shows ONLY these for .Net Core

  • Microsoft .Net Core 1.0.0 RC2 - VS 2015 Tooling Preview 1 (1.0.20513.14)
  • Microsoft .Net Core 1.0.0 RC2 - SDK Preview 1 (x64) to be version 1.0.0.2702

Except in my case it is:

  • Microsoft .Net Core 1.0.0 - VS 2015 Tooling Preview 2
  • Microsoft .Net Core 1.0.0 - SDK Preview 2 (x64)

I also had to uninstall something named along the lines of "dotnet CLI dev" or "Microsoft Dotnet CLI for Windows" or something like that. Once all that is sorted you should be good to go.

dotnet (CLI)

Ok, so you could just go RTFM. But I will still go ahead and produce the Hello World of dotnet applications. The internet will be full soon, I might as well do my bit.

Firstly, like with git, we create a new folder and initialise it. In this case, the folder is the equivalent of a project folder.

mkdir MyNewApp
cd MyNewApp
dotnet new

Fun fact: the first time you run dotnet new you might see this:

Welcome to .NET Core!
---------------------
Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
Telemetry
--------------
The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include commandline arguments. The data is collected by Microsoft and shared with the community.
You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
Configuring...
-------------------
A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.
Decompressing 100% 6252 ms
Expanding 100% 45184 ms
Created new C# project in C:\dev\temp\MyNewApp.

But I digress. We should now have a new application created with two files:

  • Program.cs
  • project.json

Technically, this is enough for a dotnet app.

First, we need to restore. This is NuGet restore and version locking of the project.json. The project.lock.json file produced is similar to the RubyGem or npm lockfile concept.

dotnet restore
log  : Restoring packages for C:\dev\temp\MyNewApp\project.json...
log  : Writing lock file to disk. Path: C:\dev\temp\MyNewApp\project.lock.json
log  : C:\dev\temp\MyNewApp\project.json
log  : Restore completed in 2520ms.

Now we run a build.

dotnet build
Project MyNewApp (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling MyNewApp for .NETCoreApp,Version=v1.0

Compilation succeeded.
    0 Warning(s)
    0 Error(s)

Time elapsed 00:00:04.6165052

And finally, we run the application.

dotnet run
Project MyNewApp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
Hello World!

That's it. We have a fully executable .Net Core Application.

Visual Studio)

Let's repeat with Visual Studio now. Choose File-> New Project and Select the Console Application (.Net Core) template from under the new .Net Core C# category.

Select Console Application .Net Core from File New Project.

This will create a new Solution with a new Project, a new xproj format. The folder structure is roughly:

  • MyNewApp
    • src
      • MyNewApp
        • Properties
          • AssemblyInfo.cs
        • MyNewApp.xproj
        • Program.cs
        • project.json
        • project.lock.json
    • global.json
    • MyNewApp.sln

It is worth noting that the tooling is still not finalised, and that the xproj and msbuild tooling is likely to continue to change, and will the other csproj folders and the project.json file things.

So now we have a project in Visual Studio. If we build and run, both will succeed but there isn't much to see. Let's add the following to our Progam.cs Main method:

Console.WriteLine("Hello World!");
Console.ReadKey();

Now If we build and run, we should see our Hello World app run. (Press any key to exit).

Hello World .Net Core app running.

Easy

Next time we will take a deeper look into the project.json file and start to experiment on ways to build more complex applications with the new .Net Core.