Alle Beiträge von Sascha Baumann

Visual Studio Extensions: SlowCheetah to transform XML and JSON Configuration Files

I have been using this Extension at some occasions, and it’s good to see, that it’s still around.

You might have noticed, that you can add transformations for your Web.config file based on the Build Configurations you are using. By default, transformations for Release and Debug are added automatically. If you have added your own Configuration, you can add transformations for these too.

This will create a transformation file, to modify the original Web.Config. You can replace Connections Strings, Servernames, Pathsettings – Basically everything, based on the Original Web.Config you have created.

However, if you try to do this for example for App.config in a Console Application, you will notice that there is no such option. Not even transformations are added for the default Build Configurations.

This is, where SlowCheetah comes in handy. You can install it via Extension Manager, and after restarting Visual Studio, it will be available.

After Installation is complete, we can have a look at out previous Console Application again and Right-Click on the App.Config file. Et voila, now we have an Option called “Add Transform”.

When executing this command, it will ask you to install the SlowCheetah Nuget package. This is required to run transformations, even if the Extension itself is not installed. So, not every member of your team needs to install the extension, only the people modifying the Configuration need it. But it will work for all team-members by using the installed Nuget package.

After we have done this, SlowCheetah creates the transformations for the default Configurations. If we add special configurations later, we just have to run the “Add Transform” again, to have new transformations added.

You can also find SlowCheetah in the Visual Studio Market Place

The Sourcecode can be found on GitHub: https://github.com/Microsoft/slow-cheetah

Champions of C# 9 : “Simplified parameter null validation code”

In this blog post I wan’t to have a closer look at a current proposals for the upcoming C# Version 9.

Proposal #2145 – Simplified parameter null validation code.

Usually, if handing over parameters to a method, some checking for NULL is required to prevent unexpected behavior. Have a look at the following sample of a method with some checking.

private string ParseText(string text)
{
    if (text is null)
    {
      throw new ArgumentException(nameof(text));
    }
    return text;
}

In C# 9, this code could be simplified by adding ! as an indicator for “Will not be NULL” to the parametername. The code would then look like this.

private string ParseText(string text!)
{
    return text;
}

Based on This discussion from summer 2019, the new syntax is supposed to throw an Exception too, if the constraint is violated. Most likely also an ArgumentException, but this doesn’t seem to have specified yet.


New Resources Section and first Page “Resources to learn C# and ASP.NET”

Today I published a new section in my Blog, to collect resources to various topics. The goal for these pages is, to stick around and for me to update them regularly, to keep them relevant. The first page of this format is about Learning C# and ASP.NET. As someone who is working with these technologies for almost two decades, I hope I can deliver some useful information for beginners. Also, I am open for suggestions. What resources did I forget ? Let me know.
Sascha