This is a series on the .Net Core 1.0 bits. Looking for .Net Core 2 Series?
- Getting Started <=(We are here)
- What's in the box
- Using Multiple Projects
- Publishing Portable Applications
- Self-contained Applications
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.
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 18.104.22.16802
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.
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:
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.
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.
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.
Project MyNewApp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. Hello World!
That's it. We have a fully executable .Net Core Application.
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.
This will create a new Solution with a new Project, a new
xproj format. The folder structure is roughly:
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).
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.