I’ve been spending a lot of time trying to get up to speed on the new .Net Core product. The product is at version 1.0.1 but everything is constantly changing. Many NuGet packages are not compatible with .Net Core and the packages that are compatible are still marked as pre-release. This phase of a software product is called the bleeding edge. Normally, I like to avoid the bleeding edge, and wait for a product to at least make it to version 1. However, the advantages of the new .Net Core make the pain and suffering worth it.
Let’s start with some of the good features. First, the dll’s are redesigned to allow better dependency injection. This is a major feature that is long overdue. Even the MVC controllers can be unit tested with ease.
Next up is the fact that dll’s are no longer added to projects by themselves and the NuGet package manager determines what your project needs. I have long viewed NuGet as an extra hassle, but Microsoft has finally made this a pleasure to work with. In the past, NuGet just makes version control hard because you have to remember to exclude the NuGet packages from your check-in. This has not changed (not in TFS anyway), but the way that NuGet works with projects in .Net Core has changed. Each time your project loads, the NuGet packages are loaded. What packages are used is determined by the project.json file in each project (instead of the old nuget packages.config file). Typing in a package name and saving the project.json will cause the package to load. This cuts your development time if you need a package loaded into multiple projects. Just copy the line of code in your project.json file and paste into other project.json files.
It appears that Microsoft is leaning more toward XUnit for unit testing. I haven’t used XUnit much in the past, but I’m starting to really warm up to it. I like the simplicity. No attribute is needed on the unit class. There is a “Theory” attribute that can feed inline data into a unit test multiple times. This turns a unit test into one test per input set.
The new IOC container is very simple. In an MVC controller class, you can specify a constructor with parameters using your interfaces. The built-in IOC container will automatically match your interface with the instance setup in the startup source.
The documentation produced by Microsoft is very nice: https://docs.asp.net/en/latest/intro.html. It’s clean, simple and explains all the main topics.
The new command line commands are simple to use. The “dotnet” command can be used to restore NuGet packages with the “dotnet restore” command. The build is “dotnet build” and “dotnet test” is used to execute the unit tests. The dotnet command uses the config files to determine what to restore, build or test. This feature is most important for people who have to setup and deal with continuous integration systems such as Jenkins or Team City.
OK, nothing is perfect, and this is a very new product. Microsoft and many third-party vendors are scrambling to get everything up to speed, but .Net Core still in the early stages of development. So here is a list of hopefully temporary problems with .Net Core.
The NuGet package manager is very fussy. Many times I just use the user interface to add NuGet packages, because I’m unsure of the version that is available. Using a wild-card can cause a package version to be brought in that I don’t really want. I seem to spend a lot more time trying to make the project.json files work without error. Hopefully, this problem will be diminished after the NuGet packages catch up to .Net Core.
If you change the name of a project that another project is dependent on you’ll get a build error. In order to fix this issue you need to exit from Visual Studio and rename the project directory to match and then fix the sln file to recognize the same directory change.
Many 3rd party products are do not support .Net Core yet. I’m using Resharper Ultimate and the unit tests do not work with this product. Therefore, the code coverage tool does not work. I’m confident that JetBrains will fix this issue within the next month or two, but it’s frustrating to have a tool I rely on that doesn’t work.
Many of the 3rd party NuGet packages don’t work with .Net Core. Fake it easy is one such package. There is no .Net Core compatible package as of this blog post. Eventually, these packages will be updated to work with Core, but it’s going to take time.
What to do
I’m old enough to remember when .Net was introduced. It took me a long time to get used to the new paradigm. Now there’s a new paradigm, and I intend to get on the band-wagon as quick as I can. So I’ve done a lot of tests to see how .Net Core works and what has been changed. I’m also reading a couple of books. The first book I bought was the .Net Core book:
This is a good book if you want to browse through and learn everything that is new in .Net Core. The information in this book is an inch deep and a mile wide. So you can use it to learn what technologies are available, and then zero in on a subject that you want to explore, then go to the Internet and search for research materials.
The other book I bought was this one:
This book is thicker than the former and the subject is narrowed somewhat. I originally ordered this as an MVC 6 book, but they delayed selling the book and renamed it Core. I’m very impressed by this book because each chapter shows a different technology to be used with MVC and there are unit tests with explanations for each. So there is an application that the author builds throughout the book. Each chapter builds on the previous program and adds some sort of functionality, like site navigation or filtering. Then the author explains how to write the unit tests for these features in the chapter that contains the feature. Most books go through chapter by chapter with different features, then there is a chapter on how to use the unit test features of a product. This is a refreshing change from that technique.
I am currently working through this book to get up to speed as quick as possible. I would recommend any .Net programmer to get up to speed on Core as soon as possible.