• Blazor,  Microsoft

    Blazor with dotnet watch run in the Pre-Dotnet 6 and VS 2022 days

    Oh, how we do wait for the release of dotnet 6 and most important VS 2022. Why? Well the promise of hot-reload without hoops to jump through.

    For the most part in VS 2019 16.10.4, “hot-reload” of a Blazor app is not too bad <= Circle that “not too bad”- it does actually work… mostly! Yes, I do refer to the “dotnet watch run”. It does detect changes in your Blazor files and reload the browser page… yeah, BUT it does have issues. Here comes the list….

    It doesn’t detect new files added… go ahead add a new razor page while your project is in “dotnet watch run” – nope it will not find it no matter how many times you hard refresh the browser. Not only razor pages, but new stylesheets- yeap, it’s not going to find those either!

    It has issues when you make too many complicated changes in your code. Yes compile errors that don’t go away.

    It interferes with an already “flaky” intellicode/intellisense… My goodness talking about annoying! Already half the time, bootstrap intellisense stops working on razor pages. And what the hell happened to code snippets? (Probably less about hot-reload than this version of VS being riddled with bugs!)

    Ok, I’m mostly over that now…. deep breath… 1…2…3…4… Alright.

    Let’s get to the point, the matter of always having to type in that “dotnet watch run”, stop it, and type it in again… what’s the point? Let’s create a launch profile so that we can tack this into VS (gee you think the Blazor Template should already have that? Yeap it should). Here we go:

     

    "Watch": {
          "commandName": "Executable",
          "launchBrowser": true,
          "launchUrl": "http://localhost:5000/",
          "commandLineArgs": "watch run",
          "workingDirectory": "$(ProjectDir)",
          "executablePath": "dotnet.exe",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
          }
        }

    In your launchSettings.Json file, place the code above in the “Profile” section…. Match sure this is in the “PROFILE” section!

    Now let the magic begin… well mostly… When you tap the “Watch” on the Build/Debug drop down… that lovely “dotnet watch run” will execute in a window… and now you to can experience the “buggy” hot-reload of a Blazor app. 😎
    ~SG

  • Microsoft,  SQL Server

    BCP and Clustered SQL Oh the Errors

    I got a curious message concerning problems that someone from work was having issues getting a relatively simple BCP (Bulk Copy for SQL) to work.

    So here we go:

    bcp "select top 5 [Data] from [ADataBase].[dbo].[ATable]  where [ProcessedTime] <= GetDate()-1 and MessageType=''SomeProduct'' order by [ProcessedTime] desc for xml raw, root(''MyexportRoot'')"' +
        ' QUERYOUT ""B:\BCPBatch\Data\sample.xml"" -T -c  -S TheSQL\Instance';
    

    It’s a little complicated… Basically pull data from a table in DB on a SQL Instance… and output as xml to an xml file.
    After spending, a few hours, getting all kinds of errors about drive not found, path not found, can’t open the file… bah bah bah. It’s like what the hell?!

    You take that statement and execute it on a console window or powershell window… and no problems, but you get into SSMS, and in a query window… and nothing but errors… So something like this:

    EXECUTE sp_configure 'show advanced options', 1;  
    GO  
    -- To update the currently configured value for advanced options.  
    RECONFIGURE;  
    GO  
    -- To enable the feature.  
    EXECUTE sp_configure 'xp_cmdshell', 1;  
    GO  
    -- To update the currently configured value for this feature.  
    RECONFIGURE;  
    GO  
    
      declare @cmd nvarchar(512);
    -- Please note that the fully qualified table name is needed
    select @cmd = 'bcp "select top 5 [Data] from [ADataBase].[dbo].[ATable] where [ProcessedTime] <= GetDate()-1 and MessageType=''SomeProduct'' order by [ProcessedTime] desc for xml raw, root(''MyexportRoot'')"' + ' QUERYOUT ""B:\BCPBatch\Data\sample.xml"" -T -c -S TheSQL\Instance';
    exec xp_cmdshell @cmd;
    go
    
    EXECUTE sp_configure 'xp_cmdshell', 0;  
    GO  
    -- To update the currently configured value for this feature.  
    RECONFIGURE;  
    GO  
    
    EXECUTE sp_configure 'show advanced options', 0;  
    GO  
    

    And let the errors happen… and they do. What’s the issue here… well nothing really with the code, but with the fact that my TheSql\Instance was in fact Clustered!

    So why is that a problem? It’s this part here:

    QUERYOUT “”B:\BCPBatch\Data\sample.xml””   – the syntax is correct, but on a clustered server file locations are problematic! Meaning, the cluster does not normally have full access to all of the drives. Now, will a network share work? Not sure. I didn’t test that.

    The solution I suggested was to move to another SQL instance that was not clustered, and the script worked.
    ~SG

     

  • Microsoft,  SQL Server

    A slight issue when one wants to install SQL 2019 Dev, etc The ODBC 17 SQL Driver

    On my way to getting the latest SQL Server installed on one of my Dev PC’s- I ran across the issue of getting prompt for:

    msoledbsql.msi

    What the hell…

    ODBC Driver 17 is what that is about. Apparently, the SQL installed is not smart enough to know that one already has ODBC 17 SQL Driver installed and runs into a major “cannot resolve” the problem. The end result is that one does not get the SQL instance installed…

    But after reading lots of “not really helping” blurbs from the Internet, the Solution is simple… well mostly.

    You have to uninstall the “Microsoft ODBC Driver 17 for SQL Server” – one can find it on windows 10 in the APPS & Features. Uninstall it and redo the SQL install. One should have better luck with moving forward with getting SQL installed…

    ~ScottGeek

  • GitHub

    The GitHub Secret thing

    So you travel along in your or someone’s GitHub repo… and we all know what that looks like. The repo code, actions, etc. But did you know that you can make the GitHub Web UI (page) look like a VS Code File Explorer? Ya… you can. It’s not really supported by GitHub (just to be clear)… but yeah.

    What is magic…

    Normally a GitHub url looks something like https://github.com/<User Name>/<Repo Name> simple enough…
    To see the magic… just do a https://github1s.com/<User Name>/<Repo Name>
    That’s right, add a 1s to the DNS name of github.com… You will get a VS Code “On-Line” view of the repo. How cool is that? 😎

    Look in the GH repo: conwnet/github1s

    ~SG

  • .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 @

    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:

     

    Enjoy
    ~ScottGeek