As discussed in the previous ASP.NET Core article the purpose of this article is to show you how set up a basic gulp template instead of default .NET Core bundles which I personally don't prefer. In my eyes the gulp is far more powerful and simply becomes a must if you deal with larger JavaScript project. The whole empty template can be downloaded from my GitHub page: https://github.com/IvanSivak/ASP.NET-Core-MVC6-Gulp-Template. GulpThe best way to get familiar with my template is just by opening the project and see the changes. Let me just briefly clarify.
Let me know if you have any issues with my template or recommendations. Unfortunately I was unable to export the project into a template (issue has been discussed on stack overflow) but since the project is very simple and clean you should be able to just download and rename the project or use it as a reference to set up your own new project.
0 Comments
After spending a couple of weeks experimenting with the new ASP.NET Core I am confident to say it's the best ASP.NET ever released. There are many reasons why the new version of ASP.NET is better from the previous versions. This article is focused on basic differences, improvements and shows the basic project set up example using gulp. .NET vs. mono vs. NuGetBefore we start let's just remind the basic principles and basic options of .NET. In order to run traditional .NET application there always needs to be a version of .NET Framework installed on a machine where program runs. Whether it's EXE or DLL it always contains so called intermediate language (IL). The IL itself needs to be compiled by just-in-time (JIT) compiler which is included in .NET Framework itself and is part of Common Language Runtime (CLR). In short, just before the program executes the JIT kicks in, compiles the IL and CLR runs the program. Hence, the CLR is responsible for almost every .NET functionality and FCL (Framework Class Library) contains all .NET types and classes. Mono is open source project developed by community. It is compatible with .NET framework and uses the same principle as MS CLR. It offers distributions for Linux, Mac and Windows which makes it a cross-platform alternative for .NET applications. Mono also stands on basis of Xamarin. As every packaging system the NuGet exists to make things easier. Since .NET framework itself is a very large set of classes, types, libraries etc. (the FCL and CLR) it is difficult to make updates. With every new FCL version Microsoft needs to distribute new .NET Framework version. This is what makes the NuGet so useful. You can deliver or update only particular libraries. Great example is MVC or WebAPI. These libraries are NuGet packages. They do not exist in FCL. This is what allowed these libraries to evolve so rapidly. Rapid updates of single NuGet packages not tied to .NET Framework allowed them to be developed and updated much faster. ASP.NET CoreThere are many advantages and changes in ASP.NET Core over the previous ASP.NET. Here is a list to name the most important ones
WebAPI vs. mvc vs. system.web
Example asp.net core projectLet's get started with an example. First of all, if you don't use at least Visual Studio 2015 Update 4 you will need to download the ASP.NET Core template into your visual studio. Everything is nicely described on the official documentation page here: https://docs.asp.net/en/latest/ or you can simply go straight to the download link at: https://www.microsoft.com/net/core. No CSPROJ file & global.jsonOne thing I really like among others is that there's no csproj file anymore. It makes it easier for source version control. How many conflicts of project file we already had in GIT? The ASP.NET Core simply reflects the file system. There's no need for "include in the project" function and so on. Instead the global.json is presented. project.jsonThe project.json contains various meta data of a project, settings such as publishOptions and very important - references to NuGet packages. Note that NuGet packages are not installed into the packages folder anymore. Instead all NuGet packages are inside your user folder, e.g. c:\users\ivan\.nuget wwwrootIn classic ASP.NET everything was pretty much contained within the project root. The new wwwroot folder brings more clarity into web publishing as only what stays in wwwroot folder is accessible by a web server. This can be changed in project.json/publishOptions though, e.g. we want Views folder to be exposed as well hence we can add it as follows: Dependencies & BowerDependencies folder is about client side development. In principle the Bower is the same as NuGet. The difference is that Bower is focused on client side libraries and frameworks (such as jQuery, Bootstrap, Angular etc.) and runs under Node.JS. NPM (Node Package Manager) is the same thing but aims at Node.JS libraries, such as Gulp etc. .Net Core Bundles vs. GulpWhen you create a new ASP.NET Core Web Application the default template uses built-in .NET Core bundles mechanism which takes care of JavaScript and CSS files bundling and minification. The same can be achieved using well known Gulp and both have their pros and cons. Personally, I prefer the Gulp over the built-in .NET Core bundles. My projects usually tend to be JavaScript very rich and it is mostly the JavaScript part that grows a lot. As the development goes by sooner or later you will end up using various gulp plugins such as nunjucks for templates processing and many others. Having it all (the minification and bundling) nicely managed by gulp since the beginning brings more clarity to the project and in my eyes is a way more powerful. There are alternatives, for example ASP.NET MVC Boilerplate template that uses gulp. The whole story behind .NET Core default web template and why it doesn't use gulp is described here. Since Boilerplate is quite heavy template I decided to create my own lightweight ASP.NET Core MVC6 Gulp Template. This will be described in my next article about such lightweight template.
|
AboutBlog about my programming experiments, tests and so on. Categories
All
Archives
November 2016
|