Friday, September 19, 2025

Visual Studio: Finding Using Statements Added to Source Code by Visual Studio

In a previous post (Visual Studio: Disabling Add Using Statements on Paste), I showed that Visual Studio has a feature that adds using statements to C# files even when a project takes advantage of project-level global usings. And yes, this feature does turn itself back on (see below -- it's back):



Periodically, in a large project, I like searching for these superfluous using statements. The way to do this is to use a regular expression. From Visual Studio, select Find in Files, which is under Edit → Find and Replace → Find in Files (CTRL+SHIFT+F). In the search textbox, paste the following regular expression:

(?m)^using\s+

Make sure you select the "Use regular expressions" checkbox in the "Find and Replace" dialog (see below):


File types can be *.* or *.cs. Click on "Find All" and purge away.

Below is ChatGPT's breakdown of the regular expression,  (?m)^using\s+ :


Thursday, September 18, 2025

Windows 11: Updating WSL to the Latest Verson

In this vlog I will show you how to update your WSL (Windows Subsystem for Linux) on a Windows host.

I found myself using a backup laptop for a project. I ran the following to check the WSL version from a PowerShell terminal window running as administrator:

wsl --version

The output was as follows:

WSL version: 2.3.26.0
Kernel version: 5.15.167.4-1
WSLg version: 1.0.65
MSRDC version: 1.2.5620
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26100.6584

ChatGPT Pointed out my WSL was released November 2024: 

WSL 2.3.26 with kernel 5.15.167.4

The latest version is WSL 2.5.10 , released August 2025.

I ran the following from the PowerShell terminal:

wsl --update

Which installed WSL 2.6.1, so ChatGPT was incorrect saying 2.5.10 was the latest.

Out of caution I ran:

wsl --shutdown

The double-checked with:

wsl --version 

This showed I was up to date with WSL 2.6.1:

WSL version: 2.6.1.0
Kernel version: 6.6.87.2-1
WSLg version: 1.0.66
MSRDC version: 1.2.6353
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26100.1-240331-1435.ge-release
Windows version: 10.0.26100.6584






Monday, July 14, 2025

Removing Windows News Widget using PowerShell

Even on a professional laptop Microsoft places a news widget that forces unwanted political content and inane celebrity news on its users. In a previous post I showed how to remove this unwanted feature from Windows: Windows 11: Remove Microsoft News Widget. In the aforementioned blog, the winget command was used to remove the widget. Unfortunately winget is not available on every corporate version of Windows.

To remove this widget for the current user, perform the following PowerShell command:

Get-AppxPackage MicrosoftWindows.Client.WebExperience | 
    Remove-AppxPackage


To remove for all users, perform the following PowerShell command while running as an administrator:

Get-AppxPackage -AllUsers MicrosoftWindows.Client.WebExperience |
    Remove-AppxPackage -AllUsers

Tuesday, June 24, 2025

Azure: Web App Viewing Deployed Files

I have a web app that needs to invoke an executable. Said executable is missing. So in Azure I must:

1. Open portal.azure.com
2. Navigate to the specific Web App
3. For Web App, use the left menu and select Development Tools | Advanced Tools | Go


4. If warned that you are leaving portal.azure.com, select Continue.

This opens the Kudu site at:

https://<your-app-name>.scm.azurewebsites.net/

Kudu is an advanced deployment and management engine behind Azure App Services, which also covers Web Apps.

From the menu select Debug Console and pick your favorite console: CMD or PowerShell




Under Linux navigate to:

site/wwwroot/

Under Windows navigate to:

C:\home\site\wwwroot


Friday, April 25, 2025

Visual Studio: Disabling Add Using Statements on Paste

Of late, I am tending to paste a lot more code into existing C# source files due to AI. Visual Studio 2022 introduced a feature that after code is pasted, Visual Studio will add any missing using statements to the source file. When working with CSV-related code, without my knowledge, Visual Studio adds the following to the top of a source file:

using Microsoft.VisualBasic.FileIO;

I do not want tools such as Visual Studio 2022, Copilot, or ChatGPT to write code without my knowledge or consent.

To disable the automatic addition of using directives after pasting in Visual Studio 2022 or later:

  1. From the Tools menu, select Options…
  2. Navigate to Text Editor → C# → Advanced
  3. Uncheck Add missing using directives on paste


I have disabled this feature multiple times. It seems to re-enable. Proof of Skynet?



Visual Studio: C# Project-Level Global Usings

Visual Studio 2022 and its support for C# 10.0 and .NET 6.0 allow using statements to be placed at the project level (using the syntax global using <namespace>;), stored within the project’s Properties. To access this feature, right-click a project in Solution Explorer, select Properties from the context menu, and then choose the Global Usings tab:


Using the above cleans up individual C# files, which can become pointlessly cluttered, as shown in the following example:

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System;

It is possible to have a standalone C# file that serves the same purpose, such as a per-project GlobalUsing.cs:

global using Microsoft.AspNetCore.Http;
global using Microsoft.Extensions.Logging;
global using System.Collections.Generic;
global using System.IO;
global using System.Threading.Tasks;
global using System;

A dedicated file, such as GlobalUsing.cs, is cleaner than per-source-file using statements. However, setting project-level global usings remains the cleanest approach.

As always, beware of the following, should some malevolent entity disable the feature for your project:





Tuesday, April 1, 2025

SQL Server: T-SQL Adding a CreatedUtc and ModifiedUtc to a Database Table

As a 120 WPM typist (you read that right), ChatGPT or its cousins are a time-saver. I know the drill of adding a column or columns to an existing table. I want the columns to be required, but this means I have to first assign a value to each existing row in the database.

Take adding CreatedUtc/ModifiedUtc to a table (or all tables, long term) in a database. Here is what you tell ChatGPT:

For a SQL Server table write the following T-SQL:

  1. Use ALTER TABLE to add CreatedUtc and ModifiedUtc columns of type DATETIME2 as nullable
  2. Assign a DATETIME2 UTC value of January 1, 2025, 00:00:00 to a variable @stockCreatedDateTimeUtc
  3. Update all existing entries in the table to set CreatedUtc and ModifiedUtc to @stockCreatedDateTimeUtc
  4. Write an ALTER TABLE script to make CreatedUtc and ModifiedUtc not nullable

And here are the results but ChatGPT missed the required GO under the ALTER TABLE:

ALTER TABLE YourTableName
ADD CreatedUtc DATETIME2 NULL,
    ModifiedUtc DATETIME2 NULL;

GO

DECLARE @stockCreatedDateTimeUtc DATETIME2 = '2025-01-01 00:00:00';

UPDATE YourTableName
SET CreatedUtc = @stockCreatedDateTimeUtc,
    ModifiedUtc = @stockCreatedDateTimeUtc;

ALTER TABLE YourTableName
ALTER COLUMN CreatedUtc DATETIME2 NOT NULL;

ALTER TABLE YourTableName
ALTER COLUMN ModifiedUtc DATETIME2 NOT NULL;

Total time: under 60 seconds. Maybe 10 minutes if I typed it out by hand. You still need to know how to code T-SQL and understand SQL Server to use AI correctly.