Today is the first day of .NET Conf 2019, a slew of videos are coming out to introduce new and exciting technologies in the world of .NET. I watched some of them and I'm really excited about the improvements in Asp.net Core and C#. Here are a couple of interesting things I learned today.
Razor Class Library - static files improvements
During the keynote Daniel Roth showed that the static files from the new Razor Class Library (RCL) can integrate with the application without much extra work.
This is a new feature in Asp.net Core and .NET Core 3.0 where your class libraries can carry static files that are made available to the application when the project is referenced.
This is significant because all my plugins, widgets and themes are Razor Class Libraries. Right now in Asp.net Core 2.2 to make the static files available to the application I had to implement a
ExtensionStaticFileConfigureOptions that derives from
IPostConfigureOptions<StaticFileOptions> and then I had to wire it up in the
Startup.cs. Not only is this extra work, but the development experience also was degraded after this for some reason, as any changes in the RCLs require a recompile. I still haven't figured out why or how to get around that.
But with Asp.net Core 3.0, it is improved. In the demo all Dan did in the application that referenced the RCL is to add a stylesheet reference in the head section of the
_Host.cshtml file, the convention is
_content followed by the name of your RCL and then followed by the path to your style sheet.
<link href="_content/RazorClassLibrary1/styles.css" rel="stylesheet" />
C# 8.0 - Nullable reference types
Nullable reference types is a major feature in C# 8, it seems to me its goal is to make everything non-nullable by default, then you explicitly tell the compiler if you want something to be null, such as
string?. This feature for sure will cause major effort when it comes to upgrading existing projects, so here Mads Torgersen gives his view on how possibly to approach it.
Realistically the upgrade will be done piecemeal. If you turn this feature on at your project level in .csproj
<Nullable>enable</Nullable> you will likely get a sea of warnings and squiggles. A nicer approach is to have directives at the file level, put
#nullable enable inside your individual C# file. And you can choose to enable / disable annotation as well as warnings. Annotation is the actual api of things such as
string?, so if you put that after you disable annotations for example you will have a warning, like this
#nullable disable annotations string? test; // warning here after your disable annotations
Mads mentioned about "Nullable adoption phase" which is the period from now till .NET 5 ship that gives people enough time to gradually get "nullified".
VS Debugging Tips
Leslie Richardson had an excellent session on Tips and Tricks for .NET Debugging in Visual Studio, here are a few tips I picked up from her video.
- Data Break Point - New to .NET Core 3, it allows you to halt your code on a specific object's property whenever it changes even if that property goes out of scope, basically break when value changes.
- Return value showing in Locals - When your return statement is an expression, it used to be hard to know what exactly the value is, for example
return person + " " + book.FinishedBookString();how would you know what the value is returned while debugging? Now you do.
- Edit and Continue - This feature has been there, but it didn't work. Now she said it's been improved.
.NET Community Roundup
- .NET Video - These are 101 videos grouped by topic, though 101 it's actually a good opportunity for me to pick up topics I'm not familiar with.
- Try .NET - This is a GitHub project that allows you to run .NET code on your website inside the browser.
And I really liked Scott's message of encouragement for people to blog more
don't feel like you can't blog or write an e-book or get involved because you don't necessarily know the topic fully, you know your experience you know how you have found it, so blog about your feelings about it, blog about this is how we implemented Asp.net in our company, this is how our migration to .Net Core went down ... your story your unique experience is worth blogging about
Currently I'm busying working on the final features of Fanray v1.1, the Page Builder and Site Navigation. These two are more complex features so it's taking a bit long, but I'm very happy about how they are turning out. After v1.1, the v1.2-preview1 will be a migration to .NET Core 3.0, and this upgrade from 2.2 to 3.0 will be a major undertaking. In addition, the front end happens to require a major upgrade as well soon, as Vuejs 3 and Vuetifyjs 2.1 are coming out and they'll have breaking changes. I'll likely do these in stages
- EF Core and Identity - verify if there are any schema changes on the Identity tables and any breaking changes with EF Core 3
- A superficial project upgrade - see if I could make only the minimal amount of work involved to upgrade the projects to Core 3
- Json.net to System.Text.Json - Json.net is literally used everywhere in the projects, I'll likely keep Json.net and introduce the new Json lib file by file
- Blazor - need to look into this and see how it can be integrated
- C# 8 nullable ref types - good opportunity to go through the entire code base one more time