Skip to content

Instantly share code, notes, and snippets.

View peteraritchie's full-sized avatar
😖

Peter Ritchie peteraritchie

😖
View GitHub Profile
@peteraritchie
peteraritchie / Push-NewReleaseTag.ps1
Last active November 11, 2026 20:24
PowerShell script to add and push a new release version tag on the current branch commit
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory, HelpMessage = "Enter the new tag to push.")]
[string]$Tag
)
function Test-IsGitRepository {
param (
[string]$Path = (Get-Location).Path
)
@peteraritchie
peteraritchie / XmlDocExtractor.cs
Created October 3, 2026 16:22
A C# class that accepts an Assembly instance and extracts all public types and their members to XML Doc text.
// ReSharper disable MemberCanBePrivate.Global
using System.Reflection;
using System.Xml.Linq;
namespace XmlDocExtraction;
/// <summary>
/// Provides functionality to extract XML documentation from assemblies.
/// </summary>
/// <remarks>
@peteraritchie
peteraritchie / Compare-Folders.ps1
Created September 28, 2026 17:49
PowerShell script to compare the contents of two folders based on file hashes.
<#
.SYNOPSIS
Compare the contents of two folders based on file hashes.
.DESCRIPTION
This script calculates SHA256 hashes for all files in two specified folders
(and their subdirectories) and compares them. It outputs any differences
in file content or structure.
.PARAMETER Folder1
@peteraritchie
peteraritchie / EntityEntryExtensions.cs
Last active September 16, 2026 20:51
Extension method to get #entity-framework shadow property entry using the try pattern in #csharp
using System.Diagnostics.CodeAnalysis;
using Microsoft.EntityFrameworkCore.ChangeTracking;
namespace Common;
public static class EntityEntryExtensions
{
extension<TEntity>(EntityEntry<TEntity> entityEntry) where TEntity : class
{
@peteraritchie
peteraritchie / GetDatabaseTables.cs
Last active September 12, 2026 15:44
Get Sqlite database tables via a `DbContext` object #dotnet #csharp
public static Dictionary<string, string> GetDatabaseTables(DbContext db)
{
Dictionary<string, string> tablesDictionary = [];
var connection = db.Database.GetDbConnection();
using var command = connection.CreateCommand();
command.CommandText = "SELECT name, sql from sqlite_schema where type='table';";
using var reader = command.ExecuteReader();
while (reader.Read())
{
var entityName = reader.GetString(0);
@peteraritchie
peteraritchie / Remove-ObjBin.ps1
Created August 27, 2026 16:40
This script searches for all 'bin' and 'obj' directories under the given path and deletes them. #VisualStudio
<#PSScriptInfo
.VERSION 1.0.0
.AUTHOR Peter Ritchie
.COMPANYNAME
.COPYRIGHT
.TAGS Visual Studio, dotnet
@peteraritchie
peteraritchie / Remove-TestResults.ps1
Created August 26, 2026 18:22
Powershell script to remove all '.trx' and '.coverage' files from 'TestResults' directories and delete the directories if they are empty
<#PSScriptInfo
.VERSION 1.0.0
.AUTHOR Peter Ritchie
.COMPANYNAME
.COPYRIGHT
.TAGS
<#
.SYNOPSIS
Gets the build validation policies for repositories associated with solution files in the specified path.
.DESCRIPTION
Retrieves and lists the build validation branch policies for repositories that correspond to solution files found in the specified path.
.PARAMETER Path
Specifies the path to search for solution files.
#>
[CmdletBinding()]
param(
@peteraritchie
peteraritchie / SKILL.md
Created August 20, 2026 17:28
Github Copilot generated skill to update a test project to use MsTest.Sdk
name migrating-to-mstest-sdk
description Migrates .NET test projects from the traditional MSTest setup (Microsoft.NET.Test.Sdk + MSTest.TestAdapter + MSTest.TestFramework) to MSTest.Sdk, the modern project SDK approach that bundles all testing infrastructure. Use when upgrading test projects, modernizing MSTest configuration, adopting MSTest Platform (MTP), or when users ask to "switch to MSTest.Sdk", "use latest MSTest", "migrate to MTP", or "update test project to MSTest SDK". Also relevant during .NET version upgrades when test projects are being modernized.
metadata
traits discovery
test|mstest|sdk|migration|dotnet
lazy

Migrating to MSTest.Sdk

@peteraritchie
peteraritchie / Add-XmlElement.ps1
Created August 14, 2026 15:55
A PowerShell script to add an XML element to a specified XPath in an XML file.
<#
.SYNOPSIS
Adds an XML element to a specified XPath in an XML file.
.DESCRIPTION
This script reads an XML file, adds a specified XML element to a given XPath within that file.
It can optionally overwrite existing elements if the -Force parameter is specified.
.PARAMETER Path
The path to the XML file.