Friday 28 October 2016

VS code, asp.net core. Microsoft on all 3 platforms.

Microsoft are writing tools to develop and publish their applications on all 3 platforms. asp.net core is a slimmed down open source asp.net with web forms mercifully removed. Visual Studio code is a lightweight (by Microsoft standards), programming editor. It's cross platform (iOS, Linux, Win) and not too fat. The setup file I downloaded was 32Mb, taking 133.6Mb of disk space. It installed seriously fast (compared with other dev software from Microsoft).

I suppose this is a virtue of giving geeks more control over the development side. They will actually write tools for authoring software on any and every platform. There is presumably a Chrome version in the works too? Any application written should be portable across platforms with ease. It's a completely different philosophy from what we've been used to.

This blog is just a log of Shawn Wildermuth's long (> 9 hours) Pluralsight course "Building a Web App with ASP.NET Core, MVC 6, EF Core, and Angular", as I acquaint myself with the latest version. So much of it is command line driven, I feel I should write it down to remind myself what to do next time.

Entering code . from the command line executes VScode at lightning speed. e.g.

F:\code\CSharp\HelloWorld>code .

It loads with the project in that folder "HelloWorld", but without intellisense or coloration because each individual language must have support added separately. To add C# support, Ctrl+Shift+X shows a list of extensions, from which I selected C#. Added it, enabled it, the code editor restarts in less than a second. VSCode does not create projects like full Visual Studio. We need to use nodejs and npm for that. My copies of these two were quite old.

F:\code\CSharp\HelloWorld>node --version v4.4.3 F:\code\CSharp\HelloWorld>npm --version 2.15.1

So I installed a new nodejs from nodejs.org, which seemed to take forever! Snooze. Waking up several minutes later I do:

F:\code\CSharp\HelloWorld>node --version v6.9.1 F:\code\CSharp\HelloWorld>npm --version 3.10.8

Now, I'm happier creating a new project from the command line using yoeman, after first installing yoeman (with the global option), the asp.net generator is also installed

F:\code\CSharp\HelloWorld>npm install yo -g F:\code\CSharp\HelloWorld>npm install generator-aspnet -g

Now I will generate an asp.net application. First moving up a level out of my current project.

F:\code\CSharp\HelloWorld>cd.. F:\code\CSharp>yo aspnet

We see a command line menu system:

? What type of application do you want to create? (Use arrow keys) > Empty Web Application Empty Web Application (F#) Console Application Console Application (F#) Web Application Web Application Basic [without Membership and Authorization] Web Application Basic [without Membership and Authorization] (F#) (Move up and down to reveal more choices)

Pick "Web Application". If the command arrows are not working just enter the number for that choice ( 5 ) Select the Bootstrap option and call it FunWithYo

navigate to it.

F:\code\CSharp>cd FunWithYo F:\code\CSharp\FunWithYo>dir

Attempting to run it at this stage shows it's still missing asp.net. So we must restore it, before running it.

F:\code\CSharp\FunWithYo>dotnet restore F:\code\CSharp\FunWithYo>dotnet run

The whole can be seen in a browser on port 5000 localhost:5000

My frist asp.net core MVC application up. Ctrl+c (from the command line, where it is running) stops it.

Once the new project is complete, code ., opens VS code with the current project loaded. We need to answer Yes to the question
Required assets to build and debug are missing from your project. Add them?