• .Net,  Microsoft

    The world of Dotnet Templates

    I have long been using templates for dotnet new and of course Visual Studio. So I’ve started down the road of creating my own templates… or a least trying to understand how to create these,

    Now creating templates for dotnet new and especially for Visual Studio has never been a simple task. But let us try.

    The first matter is understanding where templates live. For the most part these are based on your user for your PC. This found by using a PS command:

    join-path -Path $env:USERPROFILE -ChildPath .templateengine

    This will return C:\Users\<your user name>\.templateengine   And as you guess it, there is a .templateengine directory in your users directory. What does that mean, well simply put, when one does a .dotnet new –install, application templates get installed for your user. These actually live in that directory space. Simple enough.

    When you start developing your own templates, you need to be careful, because the list of templates can get very long. That may or may not be a problem.
    A handy PS script to clear out installed templates and put it back to the original set of templates:

    function Reset-Templates{
        [cmdletbinding()]
        param(
            [string]$templateEngineUserDir = (join-path -Path $env:USERPROFILE -ChildPath .templateengine)
        )
        process{
            'resetting dotnet new templates. folder: "{0}"' -f $templateEngineUserDir | Write-host
            get-childitem -path $templateEngineUserDir -directory | Select-Object -ExpandProperty FullName | remove-item -recurse
            &dotnet new --debug:reinit
        }
    }

    Keep in mind, this clears out all templates you have installed under your user. Use with care. If you have a set of favorite templates… yeap, they will get cleared off too!

    Now, where to start? I would go to Sayed’s GitHub repo @

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly9naXRodWIuY29tL3NheWVkaWhhc2hpbWkvdGVtcGxhdGUtc2FtcGxlIiwiaW1hZ2VfaWQiOi0xLCJpbWFnZV91cmwiOiJodHRwczovL2F2YXRhcnMuZ2l0aHVidXNlcmNvbnRlbnQuY29tL3UvMTI4MzE1ND9zPTQwMCZ2PTQiLCJ0aXRsZSI6IlRlbXBsYXRlIFNhbXBsZSBieSBTYXllZCIsInN1bW1hcnkiOiJUaGlzIHJlcG8gY29udGFpbnMgYSBjb3VwbGUgc2FtcGxlcyBzaG93aW5nIGhvdyB5b3UgY2FuIGNyZWF0ZSBhIC5uZXQgY29yZSB0ZW1wbGF0ZSB0aGF0IGNhbiBiZSB1c2VkIGVpdGhlciBieSB0aGUgZG90bmV0IGNvbW1hbmQgbGluZSAoZG90bmV0IG5ldykgb3IgVmlzdWFsIFN0dWRpbyAmIFZpc3VhbCBTdHVkaW8gZm9yIE1hYy4iLCJ0ZW1wbGF0ZSI6InVzZV9kZWZhdWx0X2Zyb21fc2V0dGluZ3MifQ==”]

    It’s a long read, but one can also go over to Channel9 and look for the video series that steps one through the process.

    Another handy resource to search for templates is a web site:

     

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly9kb3RuZXRuZXcuYXp1cmV3ZWJzaXRlcy5uZXQvIiwiaW1hZ2VfaWQiOi0xLCJpbWFnZV91cmwiOiJodHRwczovL2F2YXRhcnMyLmdpdGh1YnVzZXJjb250ZW50LmNvbS91LzI2Nzg4NTgiLCJ0aXRsZSI6ImRvdG5ldCB0ZW1wbGF0ZXMiLCJzdW1tYXJ5IjoiU2l0ZSBmb3IgZmluZGluZyBkb3RuZXQgdGVtcGxhdGVzLiIsInRlbXBsYXRlIjoidXNlX2RlZmF1bHRfZnJvbV9zZXR0aW5ncyJ9″]

    Enjoy
    ~ScottGeek

  • .Net

    The Confusing world of Text.Json and .Net 5

    So one of the base libraries over the years that has been our friend is Newtonsoft.Json – the stuff of legend maybe? Well, if not, certainly anyone whose done .Net and used any kind of Json formatted data certainly knows of Newtonsoft.Json… The “go to Json Serializer”! That is until Microsoft set out to prove to the world they could do it better. Better?

    Like many things in the world of .Net over the years, Microsoft watches these open source libraries… and notices when they become the defacto standard (meaning… Micro either left it out of their core offerings…. or more typical someone did better). Hence Microsoft’s System.Text.Json vs. NewtonSoft.Json.  Oh let the confusion begin!

    Now to Microsoft’s credit they have been working to finally bring System.Text.Json up to speed… but of course they continue to state the their intent is not to bring their Json library up to par with Newtonsoft. And there it is… the two world Json library view… now mostly the complaint I have deals with migrating old code up to using Microsoft’s. It’s a bit of a “rub me the wrong way” kind of careful reading as to which direction to take. Why? Well you get into dependency  issues where Newtonsoft and Microsoft’s library don’t always play well together- that can be a problem when it comes to wanting to use old code (NewtonSoft) in a new app while wanting to take advantage of faster MS .Net 5 serializations….. Yeah, why would one ever want to do that?

    Anyway, I take some time to read a great article @

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly9kZXZibG9ncy5taWNyb3NvZnQuY29tL2RvdG5ldC93aGF0cy1uZXh0LWZvci1zeXN0ZW0tdGV4dC1qc29uLyIsImltYWdlX2lkIjotMSwiaW1hZ2VfdXJsIjoiaHR0cHM6Ly9kZXZibG9ncy5taWNyb3NvZnQuY29tL2RvdG5ldC93cC1jb250ZW50L3VwbG9hZHMvc2l0ZXMvMTAvMjAyMC8xMC9kb3RuZXQtYm90LnBuZyIsInRpdGxlIjoiV2hhdOKAmXMgbmV4dCBmb3IgU3lzdGVtLlRleHQuSnNvbj8gfCAuTkVUIEJsb2ciLCJzdW1tYXJ5IjoiTGVhcm4gYWJvdXQgdGhlIG5ldyBwZXJmb3JtYW5jZSwgcmVsaWFpbGl0eSBhbmQgZWFzeSBhZG9wdGlvbiB0aGF0IGhhcyBiZWVuIG1hZGUgd2l0aCBTeXN0ZW0uVGV4dC5Kc29uLCBhbmQgd2hhdOKAmXMgZ29pbmcgdG8gY29tZSBuZXh0LiIsInRlbXBsYXRlIjoidXNlX2RlZmF1bHRfZnJvbV9zZXR0aW5ncyJ9″]

    Layomi has a great write up of things to consider… especially in the section “Choosing between…” the two different libraries…. It’s a good read.

    ~SG

  • .Net,  .Net Core,  ASP.NET Core,  Microsoft,  Visual Studio 2019

    Dot Net 5 is Here… Check it out.

    Wow… some most excellent videos on what is what in .Net 5! Check it out on

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly93d3cuZG90bmV0Y29uZi5uZXQvIiwiaW1hZ2VfaWQiOjAsImltYWdlX3VybCI6IiIsInRpdGxlIjoiLk5FVCBDb25mIDIwMjAiLCJzdW1tYXJ5IjoiSm9pbiB0aGUgLk5FVCBDb25mIDIwMjAgZnJlZSB2aXJ0dWFsIGV2ZW50IE5vdmVtYmVyIDEwLTEyIHRvIGxlYXJuIGFib3V0IHRoZSBuZXdlc3QgZGV2ZWxvcG1lbnRzIGFjcm9zcyB0aGUgLk5FVCBwbGF0Zm9ybSwgb3BlbiBzb3VyY2UsIGFuZCBkZXYgdG9vbHMuIE1hcmsgeW91ciBjYWxlbmRhciEiLCJ0ZW1wbGF0ZSI6InVzZV9kZWZhdWx0X2Zyb21fc2V0dGluZ3MifQ==”]

    You can also find these on You Tube… search on .Net 5. The Conf 2020 Days 1-3 will be there…

    ~ScottGeek.

  • Other

    DB2 SQL Update on Joined Tables

    From time to time I have to deal with my least favorite subjects like DB2. While DB2 has a functional SQL, it’s dated and has not really kept up with SQL language improvements over the years. But it is all that I have to flow data from the IBM AS400 to the outside world (** it could be worst… like dealing with old COBOL programs).

    So  lets talk about updating column values that involve more that one table. Yeah, joined tables that have to have one or more columns updated.  Why would one need to do this? From time to time one needs to collect batches of rows from more than one table. And in the process of collecting batches one needs to update a “status” and/or date time stamp column to indicate the row was collected. It’s a common pattern in system integrations. When only one table is involved, it’s a simple matter. But when the data collected involves joined tables, then matters get complicated.

    Getting right to it, here’s the general form:

    Update <Table1>
     SET <StatusColumn> = 1 Where
      (Select DISTINCT
        <Table1>.ColumnA,
        <Table1>.ColumnB,
        <Table1>.ColumnC
        From <Table1> <Tabel2>
        Where
         <Table1>.ColumnA = <Table2>.ColumnA1 AND
         <Table1>.ColumnB = <Table2>.ColumnB1 AND
         <Table1>.ColumnC = <Table2>.ColumnC1
       )
    

    The two tables, in our example, have three columns we are Joining on… note this is an implicit join where the actual Join statement is not used.

    This update statement is a normal way to handle updating a column with a join select in the where. But this goes off the rails when it comes to DB2. Meaning it does not work. So how does one fix this?

     

    Update <Table1> 
     SET <StatusColumn> = 1 Where 
      (ColumnA, ColumnB, ColumnB) IN 
       (Select DISTINCT 
         <Table1>.ColumnA, 
         <Table1>.ColumnB, 
         <Table1>.ColumnC 
         From <Table1> <Tabel2> 
         Where 
          <Table1>.ColumnA = <Table2>.ColumnA1 AND
          <Table1>.ColumnB = <Table2>.ColumnB1 AND 
          <Table1>.ColumnC = <Table2>.ColumnC1
        )

    One adds to the Update Where clause a set of columns whose values are IN the Select of the joined tables. Like I said matters get a bit complicated for Joined tables.

    So what happens in the first type of Update in DB2? It does execute, but it updates all rows in the table to the Set value. This happens because, why the Join Select does execute, there’s nothing in DB2 that allows it to be an implicit part of the Update’s Where clause. Yeah, got to love that! What is one really saying there?

    The Where clause of the Update, in DB2, does not allow one to do just a Select… like other SQL implementations. It’s a hidden flaw, because while it looks to execute without an error, it simply does not do the intent. Therefore, one has to explicitly make sure that the Rows selected in the Where clause are part of the Update. Hence, the (columns) IN.

    Yes, as I mentioned, DB2 SQL not amongst my favorite languages to deal with.

    ~SG

  • Microsoft

    Backing up your WSL Distro and Copying it to another PC

    In our last article we talked about Moving an install WSL Distro from it awful install folder to another drive and path. So let’s make a back up of that distro, and then install it on a different PC.

    Using our new favorite tool LxRunOffline let’s make back up of a distro on our PC.

    However, as one starts down the path of using LxRunOffline, there is a slight issue when it comes to WSL2 Distros:

    lxrunoffline export -n openSUSE-Leap-15-1 -f suse.tar.gz
    [ERROR] The action/argument “export” doesn’t support WSL2.

    Ok, not a huge problem… this article just got longer…. LxRunOffline export will work for WSL 1 type Distros… So let’s do an example of both using LxRunOffline and WSL utilities.

    For WSL 1 type Distros:

    LxRunOffline has a command called List- from a Powershell window my list looks like this

    LxRunOffline.exe list
    
    fedoraremix
    docker-desktop
    Debian
    Ubuntu-18.04
    Ubuntu
    openSUSE-Leap-15-1
    docker-desktop-data
    WLinux
    Ubuntu-20.04
    kali-linux
    
    

    Now the LX tool has a command to do a backup. This collects the distro into a Linux tar file (in Linux terms a compressed tape file).

    LxRunOffline export n <NameOfDistro> –f <pathAndNameOfExportFile>

    That’s the general format of the export.

    Now before one goes about exported a Distro – I would really do a WSL –shutdown Why? I think it’s best not to have any Distro’s running when you are trying to export them. It’s not a 100% required, but it is a good practice.

    For WSL 2 type Distros:

    Still do the WSL –shutdown.

    Now we use the WSL command to backup the Distro. Like the LX tool, WSL has basically the same set of commands.
    Get a list of Distros with:

    wsl --list
    Windows Subsystem for Linux Distributions:
    Ubuntu-20.04 (Default)
    fedoraremix
    docker-desktop
    Debian
    Ubuntu-18.04
    Ubuntu
    openSUSE-Leap-15-1
    docker-desktop-data
    WLinux
    kali-linux
    
    

    And the backup command for WSL:

    wsl --export WLinux .\PengWin.tar.gz
    
    dir
    
        Directory: D:\cse.Linux
    
    Mode                 LastWriteTime         Length Name
    ----                 -------------         ------ ----
    -a---          10/17/2020 12:46 PM     9039769600 PengWin.tar.gz
    
    

    Now we have in either case a copy of our Distro that can be imported on another PC with WSL.

    When using WSL.exe

    WSL
    
    --import <Distro> <InstallLocation> <FileName> [Options]
            Imports the specified tar file as a new distribution.
            The filename can be - for standard input.
    
            Options:
                --version <Version>
                    Specifies the version to use for the new distribution.

    The –import command  Allows one to name the Distro, install to a location, from a filename. The options here, –version allows one to change the WSL version while it’s being imported.

    Now LXRunOffline is a little different:

    lxrunoffline install
    
    Options:
      -n arg                Name of the distribution
      -d arg                The directory to install the distribution into.
      -f arg                The tar file containing the root filesystem of the
                            distribution to be installed. If a file of the same
                            name with a .xml extension exists and "-c" isn't
                            specified, that file will be imported as a config file.
      -r arg                The directory in the tar file to extract. This argument
                            is optional.
      -c arg                The config file to use. This argument is optional.
      -v arg (=2)           The version of filesystem to use, latest available one
                            if not specified.
      -s                    Create a shortcut for this distribution on Desktop.
    
    
    

    As we see the install command has a few more options beyond Name, Directory, and tar filename.

    Happy WSL’ing,

    Prev Article: Moving your installed WSL Linux Distro

    Go Back to Index of WSL articles

    ~SG

  • Microsoft

    Moving your installed WSL Linux Distro

    Why start this series with moving Distro’s around and not just about installing? Simple, The distro’s tend to default their install on the C: drive in the login user App Data space (don’t even get me started on over loading c:\users\<YourUserName>).

    So what’s the problem with c:\users\<YourUserName>\AppData\Local?  where do I begin… protected? hidden? Filling up your c: drive… pick one. But the most annoying one when it comes to Windows WSL distros… the install places these in the package folder. So c:\users\<YourUserName>\AppData\Local\Packages, and it does it in a way that usually involves a GUID like naming… Get the picture?

    Ok, enough harping on it… Let’s get to moving things about.

    You start with getting the most handy little utility called LxRunOffline. You can go to their GitHub page:

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly9naXRodWIuY29tL0REb1NvbGl0YXJ5L0x4UnVuT2ZmbGluZSIsImltYWdlX2lkIjotMSwiaW1hZ2VfdXJsIjoiaHR0cHM6Ly9hdmF0YXJzMy5naXRodWJ1c2VyY29udGVudC5jb20vdS8yNTg1NjEwMz9zPTQwMCZ2PTQiLCJ0aXRsZSI6IkREb1NvbGl0YXJ5L0x4UnVuT2ZmbGluZSIsInN1bW1hcnkiOiJBIGZ1bGwtZmVhdHVyZWQgdXRpbGl0eSBmb3IgbWFuYWdpbmcgV2luZG93cyBTdWJzeXN0ZW0gZm9yIExpbnV4IChXU0wpIC0gRERvU29saXRhcnkvTHhSdW5PZmZsaW5lIiwidGVtcGxhdGUiOiJ1c2VfZGVmYXVsdF9mcm9tX3NldHRpbmdzIn0=”]

    Lots of mucking about with install verbiage (that’s a bit on the side of… yeah you really don’t need to do all of that on windows 10). Just go to the release page and download the zip file already:

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly9naXRodWIuY29tL0REb1NvbGl0YXJ5L0x4UnVuT2ZmbGluZS9yZWxlYXNlcyIsImltYWdlX2lkIjotMSwiaW1hZ2VfdXJsIjoiaHR0cHM6Ly9hdmF0YXJzMy5naXRodWJ1c2VyY29udGVudC5jb20vdS8yNTg1NjEwMz9zPTQwMCZ2PTQiLCJ0aXRsZSI6IlJlbGVhc2VzIMK3IEREb1NvbGl0YXJ5L0x4UnVuT2ZmbGluZSIsInN1bW1hcnkiOiJBIGZ1bGwtZmVhdHVyZWQgdXRpbGl0eSBmb3IgbWFuYWdpbmcgV2luZG93cyBTdWJzeXN0ZW0gZm9yIExpbnV4IChXU0wpIC0gRERvU29saXRhcnkvTHhSdW5PZmZsaW5lIiwidGVtcGxhdGUiOiJ1c2VfZGVmYXVsdF9mcm9tX3NldHRpbmdzIn0=”]

    Unzip to a favorite directory… one that is in your execute path works fine. This gives one a exe that will execute from either a command window or powershell.

    So let’s step through it…

    First go ahead and install one or more of your favorite distros for WSL.

    Next we move it….

    ##
    ##  We will do this in Powershell
    ##
    ##  Start with choosing a place we want our distro's to live... in my case the root distro I do is D:\cseWSL\<distroName>
    ##
    
    ## Find your user
    ##
    D:\>whoami
    
    ## I get something like
    mysystem\scott
    
    ## Next for the location you wish to move the distro to... i.e. in my case d:\cseWSL\Ubuntu18
    ## I'm doing my Ubuntu 18.04 
    ##  We set some access control to that directory
    icacls d:\cseWSL\Ubuntu18 /grant "scott:(OI)(CI)(F)"
    ## Here we are setting some inheriate properties and full file access to my user
    ## you can lookup icacls and what those parameters are from the internet
    
    ## Finding out what the distro names are
    ##
    LxRunOffline list 
    
    Ubuntu
    
    ##This is same as the WSL -l  command
    
    ## You can list the current location of a distro using
    LxRunOffline get-dir -n Ubuntu
    ## The -n <distro Name> is required for the get-dir command
    ## For my Fedora distro I get something like this
    ....  \AppData\Local\Packages\WhitewaterFoundryLtd.Co.FedoraRemixforWSL_kd1vv0z0vy70w\LocalState
    
    ## Now the magic part... Moving a distro
    LxRunOffline move -n Ubuntu -d d:\cseWSL\Ubuntu18
    ##  the -n and -d are required for the move command
    ##  if the named distro exists and the directory exists, then this will move the distro over
    ##
    ## To check that everything is ok with the move
    ## Do another LxRunOffline get-dir -n
    ## and see the new location
    ##
    ## Then of course, run your distro to make sure it starts up
    ## LxRunOffline provides a run command
    LxRunOffline run -n Ubuntu
    
    ## Or start the moved distro in the normal way
    
    
     
    
    
    

    Seems a little much to do… but not really.  It comes down to Create a Directory destination, set some permissions, and then run a command.

    There we are… distros located in a Happy Place.

    Next up: Backing up your WSL Distro and Copying it to another PC

    Back to Index of WSL Articles

    ~SG

     

     

  • Microsoft

    WSL Linux on Windows 10 Series of Articles

    Ok it’s time to start a series on WSL.

    I make no apologies when I say I’m not huge Linux fan, but I’m also not lacking when it comes to understanding how to utilize this OS in my Microsoft world.

    First off, I’m not a newbie when it comes to matters of Linux or Unix- I spent a number of years working on HP UX with Window-X/Motif apps I had to support (so to all the Linux Trolls… yeah whatever).

    So why is a “Microsoft Heavy” a.k.a. Me, ScottGeek bothering with the Linux side? Simple, over the past few years with MS moving to an inclusive approach with it’s Development tooling for cross OS apps, why wouldn’t I add Linux to my stack? Now don’t get me wrong, I’m not about to start writing code in Java or some other fork of the C language beyond C#.  But Linux as a OS to deploy apps on, Linux as an IOT host, Linux as an place to share my API’s that the non-MS folks want to use- yeah that works.

    So shall we begin with some topics on WSL:

    Moving your installed WSL Linux Distro
    Backing up your WSL Distro and Copying it to another PC

    ~SG

  • Internet,  Security

    Follow up to Setting up SSL Certs for IIS 10

    As a follow up to this article from the past, I got email from a reader who gave a link to a useful SSL Checker.

    [visual-link-preview encoded=”eyJ0eXBlIjoiZXh0ZXJuYWwiLCJwb3N0IjowLCJwb3N0X2xhYmVsIjoiIiwidXJsIjoiaHR0cHM6Ly93d3cud2Vic2l0ZXBsYW5ldC5jb20vd2VidG9vbHMvc3NsLWNoZWNrZXIvIiwiaW1hZ2VfaWQiOi0xLCJpbWFnZV91cmwiOiJodHRwczovL2R0MnNkZjBkYjh6b2IuY2xvdWRmcm9udC5uZXQvd3AtY29udGVudC90aGVtZXMvd2Vic2l0ZXBsYW5ldC9pbWcvd2Vic2l0ZXBsYW5ldF9pbWFnZS5wbmciLCJ0aXRsZSI6IkZyZWUgU1NMIENoZWNrZXItT25saW5lIFdlYnNpdGUgQ2VydGlmaWNhdGUgQ2hlY2tlciBUb29sIiwic3VtbWFyeSI6Ikp1c3QgZW50ZXIgeW91ciBVUkwgaW50byB0aGlzIGZyZWUgdG9vbCBhbmQgcXVpY2tseSBkZXRlY3QgYW55IGlzc3VlcyB3aXRoIHlvdXIgU1NMIGNlcnRpZmljYXRlIGluc3RhbGxhdGlvbi4gR2V0IHRoZSBmdWxsIGFuYWx5c2lzIGFuZCBleHBpcmF0aW9uIGRhdGUuIiwidGVtcGxhdGUiOiJ1c2VfZGVmYXVsdF9mcm9tX3NldHRpbmdzIn0=”]

    I’ve have used this site (and others) to inspect my SSL deployments. This is handy tool to add to your collection.

    Thanks for the tip Lisa!

    ~ScottGeek