Scott Hanselman

Free .NET Training - The Videos from .NET Conf 2017 are now available

October 4, '17 Comments [6] Posted in DotNetCore
Sponsored By

.NET Conf was worldwide this year.NET Conf 2017 is done and it was great. We had three days of sessions, and two of the days had two tracks, so there's more than 40 hours of great free videos and training for you to check out and share. Some of the content was from Microsoft but a bunch of the videos were from community and open source project members who Skyped into the studio! While I was in Redmond, Washington, Miguel de Icaza and Scott Hunter did a keynote from Devintersection in Stockholm.

There were also a number of local dotNetConf events! I hope you consider hosting one in your locale next year! While the virtual conference was filmed and broadcast LIVE, all the session videos are posted now at https://channel9.msdn.com/Events/dotnetConf/2017. There's 46 videos but here's a few of my favorites.

Containerized ASP.NET Core Apps with Kubernetes

Mete Atemal from Google joined us to talk about Containerized ASP.NET Core Apps with Kubernetes

image

Build Your Own Cortana Skill

Dorene Brown showed us how to wrote a Cortana skill in C# and .NET.

image

What's New in Visual Studio 2017

Kasey does a deep drive into a TON of the more advanced VS2017 features.

image

Diagnostics 101

The Legend himself, Jon Skeet, does a fantastic code-heavy talk on how to diagnose your app when things go wrong.

image

Go Serverless with Azure Functions and C#

Cecil Phillip breaks down the "serverless" buzzword and shows you how to use Azure Functions.

image

Get started with F# and .NET Core

Phillip Carter is geeked about F# and you should be too!

image

Full Stack F# with Fable

Once you've gotten started with F#, take a look at Fable and start writing Full Stack F# with F# on both the server and client!

image

Turning software into computer chips with Hastlayer

Zoltan explains to me how to use Hastlayer to transform .NET software into electronic circuits on FPGAs!

    image

    Getting Started with .NET

    And finally, last but not least, Kathleen Dollard and I did two hours (part 1 and part 2) on:

    image

    This is just a taste, there's a LOT of great videos so go explore!


    Sponsor: Do you know how many errors, crashes and performance issues your users are experiencing? Raygun installs in minutes. Discover problems you didn't even know about and replicate bugs with greater speed and accuracy. Learn more!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    The Book of the Runtime - The internals of the .NET Runtime that you won't find in the documentation

    September 27, '17 Comments [11] Posted in DotNetCore
    Sponsored By

    The Microsoft Docs at https://docs.microsoft.com are really fantastic lately. All the .NET Docs are on GitHub https://github.com/dotnet/docs/ and you can contribute to them. However, in the world of software engineering (here some a bad, mixed metaphor) there's instructions on how to use a faucet and there's instructions on how to build and design plumbing from scratch.

    RyuJIT High level overview

    There's additional DEEP docs that don't really belong on the docs site. It's the Book of the Runtime and for now it's on GitHub. Here's the BotR FAQ.

    If you're interested in the internals of a system like the .NET Runtime, these docs are a gold mine for you.

    The Book of the Runtime is a set of documents that describe components in the CLR and BCL. They are intended to focus more on architecture and invariants and not an annotated description of the codebase.

    It was originally created within Microsoft in ~ 2007, including this document. Developers were responsible to document their feature areas. This helped new devs joining the team and also helped share the product architecture across the team.

    We realized that the BotR is even more valuable now, with CoreCLR being open source on GitHub. We are publishing BotR chapters to help a new set of CLR developers.

    This book likely isn't for you if you're an app developer. Who is it for?

    • Developers who are working on bugs that impinge on an area and need a high level overview of the component.
    • Developers working on new features with dependencies on a component need to know enough about it to ensure the new feature will interact correctly with existing components.
    • New developers need this chapter to maintain a given component.

    These aren't design documents, these are docs that were written after features are implemented in order to explain how they work in practice.

    Recently Carol Eidt wrote an amazing walkthrough to .NET Core's JIT engine. Perhaps start at the JIT Overview and move to the deeper walkthrough. Both are HUGELY detailed and a fascinating read if you're interested in how .NET makes Dynamic Code Execution near-native speed with the RyuJIT - the next-gen Just in Time compiler.

    Here's a few highlights I enjoyed but you should read the whole thing yourself. It covers the high level phases and then digs deeper into the responsibilities of each. You also get a sense of why the RyuJIT is NOT the same JITter from 15+ years ago - both the problem space and processors have changed.

    This is the 10,000 foot view of RyuJIT. It takes in MSIL (aka CIL) in the form of byte codes, and the Importer phase transforms these to the intermediate representation used in the JIT. The IR operations are called “GenTrees”, as in “trees for code generation”. This format is preserved across the bulk of the JIT, with some changes in form and invariants along the way. Eventually, the code generator produces a low-level intermediate called InstrDescs, which simply capture the instruction encodings while the final mappings are done to produce the actual native code and associated tables.

    ryujit-phase-diagram

    This is just one single comprehensive doc in a collection of documents. As for the rest of the Book of the Runtime, here's the ToC as of today, but there may be new docs in the repository as it's a living book.

    Check it out!


    Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test and debug ASP.NET, .NET Framework, .NET Core, Xamarin or Unity applications. Learn more and download a 30-day trial!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    A Functional Web with ASP.NET Core and F#'s Giraffe

    September 18, '17 Comments [26] Posted in DotNetCore
    Sponsored By

    728331198_7c1854e363_bI was watching Ody Mbegbu's YouTube Channel - it's filled with .NET Core and ASP.NET Tutorial Videos - and was checking out one in particular, "Getting Started with ASP.NET Core Giraffe." Dane Vinson pointed me to it.

    There is such a great open source renaissance happening right now with new framework's and libraries popping up in the .NET Core space. I hope you check them out AND support the creators by getting involved, writing docs, filing (kind) issues, and even doing pull requests and fixing bugs or writing tests.

    Ody's video was about Dustin Morris' "Giraffe" web framework. Dustin's description is "A native functional ASP.NET Core web framework for F# developers." You can check it out over at https://github.com/dustinmoris/Giraffe.

    Even better, it uses the "dotnet new" templating system so you can check it out and get started in seconds.

    c:> md \mygiraffeeapp & cd \mygiraffeeapp
    c:\mygiraffeeapp> dotnet new -i "giraffe-template::*"
    c:\mygiraffeeapp> dotnet new giraffe
    The template "Giraffe Web App" was created successfully.
    c:\mygiraffeeapp> dotnet run
    Hosting environment: Production
    Content root path: C:\mygiraffeapp
    Now listening on: http://localhost:5000
    Application started. Press Ctrl+C to shut down.

    Boom. Now I'm checking out Giraffe's "Hello World."

    Because ASP.NET Core is very modular and built on "middleware" pipelines, that means that other frameworks like Giraffe can use the bits they want and remove the bits they down. Remembering that this is F#, not C#, here you can see Giraffe adding itself to the pipeline while still using the StaticFileMiddleware.

    let configureApp (app : IApplicationBuilder) =
    app.UseGiraffeErrorHandler errorHandler
    app.UseStaticFiles() |> ignore
    app.UseGiraffe webApp

    The initial readme.md for Giraffe is the docs for now, and frankly, they are excellent and easy to read. The author says:

    It is not designed to be a competing web product which can be run standalone like NancyFx or Suave, but rather a lean micro framework which aims to complement ASP.NET Core where it comes short for functional developers. The fundamental idea is to build on top of the strong foundation of ASP.NET Core and re-use existing ASP.NET Core building blocks so F# developers can benefit from both worlds.

    Here is a smaller Hello World. Note the use of choose and the clear and terse nature of F#:

    open Giraffe.HttpHandlers
    open Giraffe.Middleware

    let webApp =
    choose [
    route "/ping" >=> text "pong"
    route "/" >=> htmlFile "/pages/index.html" ]

    type Startup() =
    member __.Configure (app : IApplicationBuilder)
    (env : IHostingEnvironment)
    (loggerFactory : ILoggerFactory) =

    app.UseGiraffe webApp

    Is terse an insult? Absolutely not, it's a feature! Check out this single line exampe...and the fish >=> operator! Some people don't like it but I think it's clever.

    let app = route "/" >=> setStatusCode 200 >=> text "Hello World"

    Making more complex:

    let app =
    choose [
    GET >=> route "/foo" >=> text "GET Foo"
    POST >=> route "/foo" >=> text "POST Foo"
    route "/bar" >=> text "Always Bar"
    ]

    Or requiring certain headers:

    let app =
    mustAccept [ "text/plain"; "application/json" ] >=>
    choose [
    route "/foo" >=> text "Foo"
    route "/bar" >=> json "Bar"
    ]

    And you can continue to use Razor views as you like, passing in models written in F#

    open Giraffe.Razor.HttpHandlers

    let model = { WelcomeText = "Hello World" }

    let app =
    choose [
    // Assuming there is a view called "Index.cshtml"
    route "/" >=> razorHtmlView "Index" model
    ]

    There are samples at https://github.com/dustinmoris/Giraffe/tree/master/samples you can check out as well

    * Giraffe photo by Kurt Thomas Hunt, used under CC


    Sponsor: A third of teams don’t version control their database. Connect your database to your version control system with SQL Source Control and find out who made changes, what they did, and why. Learn more!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    The ASP.NET Interns ship their project - A basic blog template for .NET Core

    September 14, '17 Comments [12] Posted in DotNetCore | Open Source
    Sponsored By

    The internsThe Visual Studio Tools team had some great interns this summer. Juliet Daniel, Lucas Isaza, and Uma Lakshminarayan have been working all summer and one of their projects was to make something significant with ASP.NET Core and .NET Core. They decided to write a blog template. This is interesting as none of them had written C# or .NET before. Python, C, JavaScript, but not C#. This was a good exercise for them to not only learn C#/.NET but also give the team real feedback on the entire process. The ASP.NET Community Standup had the interns on the show to give us a walkthrough of their process and what they thought of VS.

    They did their work over at https://github.com/VenusInterns/BlogTemplate so I'd encourage you to star their repository...and maybe get involved! This is a great starter application to explore ASP.NET and possibly do a pull request (make sure to give them a heads up in an issue before refactoring/changing everything ;) ) and contribute.

    The interns used ASP.NET Core's new Razor Pages as well. Razor Pages sits on (is just) MVC so while it might initially look unfamiliar, remember that it's all still using the ASP.NET Core "MVC" pattern under the hood.

    When you install the  .NET Core SDK you'll get a bunch of standard templates so you can:

    • dotnet new console
    • dotnet new mvc
    • dotnet new console --language F#
    • etc

    There are lots of 3rd party and community templates and the beginnings of a website to search them. I expect this to be more formal and move into docs.microsoft.com in time.

    The interns made "dotnet new blog" where blog is the short name of their template. They haven't yet released their template into NuGet for folks to easily install "dotnet new -I blogtemplate.whatever," For now you'll need to clone their repo as if you were developing a template yourself. It's actually a decent way for you to learn how to make templates.

    Try this, using the .NET Core 2.0 SDK.

    C:\> git clone https://github.com/VenusInterns/BlogTemplate.git
    C:\> dotnet new -i C:\BlogTemplate -o C:\myblog
    C:\> cd \myblog\BlogTemplate
    C:\myblog\BlogTemplate> dotnet run
    C:\myblog\BlogTemplate (master) > dotnet run
    Using launch settings from C:\myblog\BlogTemplate\Properties\launchSettings.json...
    Hosting environment: Development
    Content root path: C:\myblog\BlogTemplate
    Now listening on: http://localhost:59938
    Application started. Press Ctrl+C to shut down.

    And here's my nice local new blog. It's got admin, login, comments, the basics.

    image

    At this point you're running a blog. You'll see there is a Solution in there and a project, and because it's a template rather than a packaged project, you can open it up in Visual Studio Code and start making changes. This is an important point. This is an "instance" that you've created. At this point you're on your own. You can expand it, update it, because it's yours. Perhaps that's a good idea, perhaps not. Depends on your goals, but the intern's goal was to better understand the "dotnet new" functionality while making something real.

    Here's some of the features the interns used, in their words.

    • Entity Framework provides an environment that makes it easy to work with relational data. In our scenario, that data comes in the form of blog posts and comments for each post.
    • The usage of LINQ (Language Integrated Query) enables the developer to store (query) items from the blog into a variety of targets like databases, xml documents (currently in use), and in-memory objects without having to redesign how things are queried, but rather where they are stored.
    • The blog is built on Razor Pages from ASP.NET Core. Because of this, developers with some knowledge of ASP.NET Core can learn about the pros and cons of building with Razor Pages as opposed to the previously established MVC schema.
    • The template includes a user authentication feature, done by implementing the new ASP.NET Identity Library for Razor Pages. This was a simple tool to add that consisted of installing the NuGet package and creating a new project with the package and then transferring the previous project files into this new project with Identity. Although a hassle, moving the files from one project to the other was quite simple because both projects were built with Razor Pages.
    • Customizing the theme is fast and flexible with the use of Bootstrap. Simply download a Bootstrap theme.min.css file and add it to the CSS folder in your project (wwwroot > css). You can find free or paid Bootstrap themes at websites such as bootswatch.com. You can delete our default theme file, journal-bootstrap.min.css, to remove the default theming. Run your project, and you'll see that the style of your blog has changed instantly.

    I wouldn't say it's perfect or even production ready, but it's a great 0.1 start for the interns and an interesting codebase to read and improve!

    Here's some ideas if you want a learning exercise!

    • Make the serializers swappable. Can you change XML to JSON or Markdown?
    • Make an RSS endpoint!
    • Add Captcha/reCaptcha
    • Add social buttons and sharing
    • Add Google AMP support (or don't because AMP sucks)
    • Add Twitter card support

    You can also just play with their running instance here. Be nice. https://venusblog.azurewebsites.net/ (Username: webinterns@microsoft.com, Password: Password.1)


    Sponsor: A third of teams don’t version control their database. Connect your database to your version control system with SQL Source Control and find out who made changes, what they did, and why. Learn more!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Experiments in Open Source: Exploring vcr-sharp for Http record and playback

    September 10, '17 Comments [19] Posted in DotNetCore | Open Source
    Sponsored By

    I've always said that reading source code is as important as write it - especially as part of the learning process. You learn a ton about how other coders think and solve problems, plus you learn about lots of new libraries and methods you may not be familiar with.

    Last week I noticed this tweet from Brendan Forster about an experiment he's working on. He is interesting in your feedback on his experiment and if you would use it.

    He's created a new library for .NET called vcr-sharp that is inspired by the vcr Ruby gem and the scotch .NET library.

    Again, he's made it clear he's just experimenting but I think this has some interesting potential.

    Vcr-sharp lets you record and playback HTTP requests! In this example, WithCassette is an extension method on HttpClientFactory. That extension method sets up a DelgatingHandler to a ReplayingHandler. That ReplayingHandler "loads the cassette" and returns it as a cached response.

    using (var httpClient = HttpClientFactory.WithCassette("my-test-scenario"))
    {
    var request = new HttpRequestMessage(HttpMethod.Get, "http://www.iana.org/domains/reserved");
    var response = await httpClient.SendAsync(request);
    var body = await response.Content.ReadAsStringAsync();
    body.ShouldContain("Example domains");
    }

    Also worth noting is that within the VCR-Sharp library Brendan uses an assertion library for .NET called "Shouldly." Shouldly has some interesting extension methods that let you express how you Assert within your Tests.

    They say - this is the old Assert way:

    Assert.That(contestant.Points, Is.EqualTo(1337));
    

    For your troubles, you get this message, when it fails:

    Expected 1337 but was 0
    

    They say - this is how it Should be:

    contestant.Points.ShouldBe(1337);
    

    Which is just syntax, so far, but check out the message when it fails:

    contestant.Points should be 1337 but was 0

    Another example:

    Assert.That(map.IndexOfValue("boo"), Is.EqualTo(2));    // -> Expected 2 but was 1
    map.IndexOfValue("boo").ShouldBe(2);                    // -> map.IndexOfValue("boo") should be 2 but was 1

    It makes tests very easy to read. A nice bit of syntactic sugar:

    [Fact]
    public async Task AppendsNewRequestToCache()
    {
    Environment.SetEnvironmentVariable("VCR_MODE", "Cache");
    var session = "append-second-request";

    using (var httpClient = HttpClientFactory.WithCassette(session))
    {
    var request = new HttpRequestMessage(HttpMethod.Get, "https://www.iana.org/performance/ietf-statistics");
    var response = await httpClient.SendAsync(request);
    }

    var cassette = await ReadCassetteFile(session);
    cassette.http_interactions.Length.ShouldBe(2);
    }

    It also uses BenchmarkDotNet, which you may be familiar with. It allows you to mark methods as [Benchmark] methods and you'll get smart warming up, running, teardowns and statistics like this;

    [Benchmark]
    public async Task ReadFromCache()
    {

    using (var httpClient = HttpClientFactory.WithCassette("example-test"))
    {
    var request = new HttpRequestMessage(HttpMethod.Get, "http://www.iana.org/domains/reserved");
    var response = await httpClient.SendAsync(request);
    }
    } Output:
            Method |     Mean |    Error |   StdDev |
    -------------- |---------:|---------:|---------:|
    ReadFromCache | 684.1 us | 3.154 us | 2.796 us |

    I'd encourage you to check vcr-sharp out over at https://github.com/shiftkey/vcr-sharp, read the source code, and think about how you'd use it. I am sure Brendan would appreciate your thoughts and feedback in the GitHub Issues! Also check out how he uses Tests, Shouldly, and BenchmarkDotNet in his project and consider how you'd use them in yours!


    Sponsor: Raygun provides real time .NET error monitoring and supports all other major programming languages and frameworks too! Forget logs and support tickets. Reproduce software bugs in minutes with Raygun's error tracking software!

    About Scott

    Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

    facebook twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb
    Previous Page Page 2 of 8 in the DotNetCore category Next Page

    Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.