slnutil 2.40.0

dotnet tool install --global slnutil --version 2.40.0
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local slnutil --version 2.40.0
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=slnutil&version=2.40.0
                    
nuke :add-package slnutil --version 2.40.0
                    

slnutil

A collection of utilities for working with .NET Solutions and Projects (.sln and .slnx).

NuGet NuGet Downloads License: MIT

Written by Benjamin Day
Pluralsight Author | Microsoft MVP | Scrum.org Professional Scrum Trainer
https://www.benday.com
https://www.slidespeaker.ai
info@benday.com
YouTube: https://www.youtube.com/@_benday

Key features

  • Create solutions and projects with unit tests & integration tests for...
  • Create class diagrams for all or part of a project using Mermaid
  • Update the .NET Framework version for all projects in a solution
  • Enable Roslyn code analysis (Microsoft.CodeAnalysis.NetAnalyzers) across a solution by creating or merging a Directory.Build.props at the solution root
  • Detect projects in a solution that still use packages.config (vs. modern PackageReference) for NuGet management
  • Set or increment the assembly version for a project
  • Set a project property value in a csproj file
  • Deploy Entity Framework Core Migrations from a DLL (aka. deploy migrations without the source code)
  • Validate a connection string against SQL Server to make sure it connects
  • Bulk rename files and folders
  • Edit json from the command line
  • Set the connection string in appsettings.json from the command line
  • Generate C# classes from JSON
  • Run SQL commands or script files against SQL Server
  • Check and update versions in Bicep files
  • Format XML files (single file or recursive)
  • View assembly information
  • And lots more...

Suggestions, Problems, or Bugs?

Got ideas for utilities you'd like to see? Found a bug? Let us know by submitting an issue https://github.com/benday-inc/slnutil/issues. Want to contribute? Submit a pull request.

Installing

The slnutil is distributed as a .NET Core Tool via NuGet. To install it go to the command prompt and type
dotnet tool install slnutil -g

Commands

Command Name Description
assemblyinfo View assembly info for a DLL.
rename Bulk rename for files and folders.
classdiagram Generate a class diagram for an assembly.
cleanreferences Simplifies package references in a C# project file. Mostly this fixes stuff in the EF Core references that breaks Azure DevOps & GitHub builds like PrivateAssets and IncludeAssets directives.
createsolution Create a solution and projects
deployefmigrations Deploy EF Core Migrations from DLL binaries.
devtreeclean Clean development folder tree. Removes node_modules, .git, bin, obj, and TestResults folders.
enablecodeanalysis Enable Roslyn code analysis across a solution by creating/merging a Directory.Build.props at the solution root.
findsolutions Find solution files (sln and slnx) in a folder tree and optionally list projects with reference analysis.
formatjson Formats JSON files
formatxml Formats XML files
getconnectionstring Get database connection string in appsettings.json.
classesfromjson Create C# classes from JSON with serialization attributes for System.Text.Json.
listpackages-oldstyle Lists packages referenced in legacy style packages.config files.
listsolutionprojects Gets list of projects in a solution.
printfile Reads a text file and prints it to the console character by character. This is helpful for diagnosing encoding issues and weird text issues.
replacetoken Replace token in file.
runsql Execute SQL command or SQL script file against a database.
setconnectionstring Set database connection string in appsettings.json.
setframework Set the target framework version on all projects.
setjsonvalue Set a string value in a json file.
setpackageversion Changes NuGet package references in a C# project file to a new value.
setprojectproperty Set a project property value on all projects.
setprojectversion Set the assembly and nuget package version property value on a project.
sortpropertygroup Sorts the elements in a property group for a csproj file.
sortreferences Sorts the references in an item group for a csproj file.
base64 Encodes a string value as a base 64 string.
touch Modifies a file's date to current date time or creates a new empty file if it doesn't exist.
updatebicepversions Reads bicep file or files and updates the api versions to latest.
updategithubactionsversions Reads a GitHub Actions YAML file and updates the action versions to latest.
validateconnectionstring Validate that specified connection string can connect to SQL Server.
wildcardreference Changes package references in a C# project file to use wildcard version rather than fixed version number.
snippetize Reads a block of text from the clipboard and formats it for use in a VSCode snippet.

assemblyinfo

View assembly info for a DLL.

Arguments

Argument Is Optional Data Type Description
filename Required String Assembly to view

rename

Bulk rename for files and folders.

Arguments

Argument Is Optional Data Type Description
rootdir Optional String Starting directory for the rename operation
from Required String String to search for and replace
to Required String Replacement value
prefix Optional String Prefix all matching values with this value
preview Optional Boolean Preview changes
recursive Optional Boolean Recurse the directory tree

classdiagram

Generate a class diagram for an assembly.

Arguments

Argument Is Optional Data Type Description
namespace Optional String Filter by namespace
filename Required String Path to assembly that you want a class diagram for.
hideinheritance Optional Boolean Hide inheritance relationships.
typenamesmatchexact Optional Boolean Exact match for type names. Default is contains.
localonly Optional Boolean Only show methods and properties that are declared locally. Don't show inherited members.
typenames Optional String Show types that exist in this comma separated list. Default search is contains match that matches by substring.

cleanreferences

Simplifies package references in a C# project file. Mostly this fixes stuff in the EF Core references that breaks Azure DevOps & GitHub builds like PrivateAssets and IncludeAssets directives.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution file to use
preview Optional Boolean Preview changes only

createsolution

Create a solution and projects

Arguments

Argument Is Optional Data Type Description
rootdir Optional String Starting directory. If not supplied, the tool uses the current directory.
type Required String Type of solution to create. Valid values are: webapi, mvc, console, commands, maui, maui-demo
namespace Required String This is the root namespace for the solution. For example: Benday.SampleApp
verbose Optional Boolean verbose

deployefmigrations

Deploy EF Core Migrations from DLL binaries.

Arguments

Argument Is Optional Data Type Description
binariesdir Optional String Path to EF Core migration binaries. Defaults to current directory.
startupdll Optional String Path to EF Core startup DLL.
migrationsdll Optional String Path to EF Core migrations DLL.
dbcontextname Optional String Name of the EF Core DbContext class.
namespace Optional String Root namespace of the EF Core migrations DLL.
verbose Optional Boolean Output results as comma-separated values

devtreeclean

Clean development folder tree. Removes node_modules, .git, bin, obj, and TestResults folders.

Arguments

Argument Is Optional Data Type Description
rootdir Optional String Starting directory. If not supplied, the tool uses the current directory.
keepgit Optional Boolean If true, skips delete of .git folders and preserves any git repositories. Default value is true. Set this value to false to delete .git folders.
keepnodemodules Optional Boolean If true, skips delete of node_modules folders. Default value is false.

enablecodeanalysis

Enable Roslyn code analysis across a solution by creating/merging a Directory.Build.props at the solution root.

Two distinct sets of Roslyn analyzers can be enabled:

Package Rule prefix What it covers
Microsoft.CodeAnalysis.NetAnalyzers CA* Code quality: null checks, performance, design, reliability
Microsoft.CodeAnalysis.CSharp.CodeStyle IDE* Code style: readonly fields, var preferences, naming, formatting

Both are enabled by default. Use /enforce-code-style:false to skip the code style package and rely only on CA* rules.

Scans every project in the solution and decides what's needed in Directory.Build.props:

  • For solutions containing .NET Framework projects that use PackageReference, the command adds a PackageReference to Microsoft.CodeAnalysis.NetAnalyzers (Framework projects don't have the analyzers built in). If --enforce-code-style is enabled (the default), Microsoft.CodeAnalysis.CSharp.CodeStyle is also added.
  • For solutions containing only .NET 5+ projects, no PackageReference is added because the SDK ships both analyzer sets.

In all cases the command sets RunCodeAnalysis=false (suppresses the deprecated FxCopCmd.exe post-build step), EnableNETAnalyzers=true, and AnalysisLevel (default latest-Minimum). When --enforce-code-style is enabled, EnforceCodeStyleInBuild=true is also set (which is what activates IDE* rules for SDK-style projects).

If a Directory.Build.props already exists, the command merges into it via XML parsing rather than string manipulation: existing properties and existing PackageReference entries are preserved, and only missing entries are added. Re-runs are idempotent.

Projects that still use packages.config are listed as warnings — they will not pick up the analyzer PackageReference from Directory.Build.props and need to be migrated to PackageReference to benefit (in Visual Studio: right-click packages.config → Migrate packages.config to PackageReference). If you don't want to migrate, run with /per-project:true instead (see below).

Per-project mode (/per-project:true)

For solutions where you don't want to migrate packages.config projects to PackageReference, pass /per-project:true. Instead of writing a Directory.Build.props, slnutil edits each project individually:

  • packages.config projects get a <package> entry added to packages.config (developmentDependency="true") plus <Analyzer> elements added to the .csproj pointing at the analyzer DLLs in the solution-level packages\ folder. Both Microsoft.CodeAnalysis.NetAnalyzers and (if --enforce-code-style is on) Microsoft.CodeAnalysis.CSharp.CodeStyle are handled this way. Only RunCodeAnalysis=false is set as a property — the other MSBuild properties are inert in old-style csproj because analysis is driven directly by the <Analyzer> entries.
  • .NET Framework projects using PackageReference get the analyzer PackageReference(s) added directly to the .csproj, plus RunCodeAnalysis=false, EnableNETAnalyzers=true, and AnalysisLevel properties.
  • .NET 5+ projects only get MSBuild properties set (analyzers ship with the SDK): RunCodeAnalysis=false, EnableNETAnalyzers=true, AnalysisLevel, and EnforceCodeStyleInBuild=true (when --enforce-code-style is on).

Existing values for the MSBuild properties owned by this command are overwritten so behavior is consistent across the solution. Existing PackageReference entries are left alone (no version churn). All other csproj content is preserved, including the old-style MSBuild xmlns. Re-runs are idempotent.

After running in per-project mode against packages.config projects, run nuget.exe restore <solution> (or Visual Studio → Tools → NuGet Package Manager → Restore NuGet Packages) so the analyzer DLLs actually land in the packages\ folder.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution to update. If omitted, searches the current directory for a .sln or .slnx file.
analysis-level Optional String Value for the AnalysisLevel MSBuild property. Default latest-Minimum. Other values: latest-Default, latest-Recommended, latest-All, latest.
analyzer-version Optional String Version of Microsoft.CodeAnalysis.NetAnalyzers to reference for .NET Framework projects. If omitted, queries nuget.org for the latest stable version.
codestyle-version Optional String Version of Microsoft.CodeAnalysis.CSharp.CodeStyle to reference for .NET Framework projects (when --enforce-code-style is on). If omitted, queries nuget.org for the latest stable version.
enforce-code-style Optional Boolean Enable code style enforcement (IDE* rules) during build. For .NET 5+ sets EnforceCodeStyleInBuild=true. For .NET Framework installs Microsoft.CodeAnalysis.CSharp.CodeStyle. Default: true.
per-project Optional Boolean Install analyzers into each project individually (modifies csproj + packages.config) instead of using Directory.Build.props. Required for solutions where projects use packages.config.
dry-run Optional Boolean Preview what would change without writing any files.
create-editorconfig Optional Boolean Also create a starter .editorconfig at the solution root if one doesn't already exist.

findsolutions

Find solution files (sln and slnx) in a folder tree and optionally list projects with reference analysis.

When listprojects and csv are both set, the output CSV includes per-project columns: uses-packages-config (True/False) and target-framework (TFM short form, e.g. net48, net8.0, netstandard2.1).

The reference-type column distinguishes five kinds of references:

  • project-ref<ProjectReference> entries.
  • package-ref — modern SDK-style <PackageReference> entries.
  • framework-ref — bare <Reference Include="System.*" /> entries (GAC / framework assemblies).
  • nuget-via-packages-config<Reference> entries whose HintPath points into a packages\ folder (the NuGet folder used by packages.config projects).
  • binary-ref<Reference> entries whose HintPath points elsewhere (direct DLL references to binaries checked into source control or referenced from an external location).

Arguments

Argument Is Optional Data Type Description
rootdir Optional String Path to start search from. Defaults to current directory.
listprojects Optional Boolean List projects in solutions
csv Optional Boolean Output results as comma-separated values
skipreferences Optional Boolean Skip checking project references when listing projects in solutions

formatjson

Formats JSON files

Arguments

Argument Is Optional Data Type Description
filename Optional String Path to file or wildcard to files
recursive Optional Boolean Apply to matching files recursively
write Optional Boolean Write changes back to the file

formatxml

Formats XML files

Arguments

Argument Is Optional Data Type Description
filename Optional String Path to file or wildcard to files
recursive Optional Boolean Apply to matching files recursively
write Optional Boolean Write changes back to the file

getconnectionstring

Get database connection string in appsettings.json.

Arguments

Argument Is Optional Data Type Description
filename Optional String Path to json config file
name Required String Name of the connection string to get

classesfromjson

Create C# classes from JSON with serialization attributes for System.Text.Json.

Arguments

Argument Is Optional Data Type Description
filename Optional String Optional: file source for the JSON to convert to C# classes.
clipboard Optional Boolean Optional: read JSON from clipboard instead of a file or console input.
innerclasses Optional Boolean Optional: generate inner classes for nested JSON objects.

listpackages-oldstyle

Lists packages referenced in legacy style packages.config files.

Arguments

Argument Is Optional Data Type Description
rootdir Optional String Path to start search from

listsolutionprojects

Gets list of projects in a solution.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution to examine. If this value is not supplied, the tool searches for a sln file automatically.
pathonly Optional Boolean Only show the project paths. Don't show the framework versions.

printfile

Reads a text file and prints it to the console character by character. This is helpful for diagnosing encoding issues and weird text issues.

Arguments

Argument Is Optional Data Type Description
input Required String Path to the text file to read and print.

replacetoken

Replace token in file.

Arguments

Argument Is Optional Data Type Description
filename Required String Path to file
token Required String Token to replace
value Required String String value to set

runsql

Execute SQL command or SQL script file against a database.

Arguments

Argument Is Optional Data Type Description
connectionstring Required String Connection string to the database
query Optional String SQL query to execute
sqlfile Optional String Path to SQL file to execute
display Optional Boolean Display results of query (for SELECT statements)

setconnectionstring

Set database connection string in appsettings.json.

Arguments

Argument Is Optional Data Type Description
filename Optional String Path to json config file
name Required String Name of the connection string to set
value Required String Connection string value

setframework

Set the target framework version on all projects.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution to examine. If this value is not supplied, the tool searches for a sln file automatically.
version Required String Framework version to set projects to.

setjsonvalue

Set a string value in a json file.

Arguments

Argument Is Optional Data Type Description
filename Optional String Path to json config file
level1 Required String First level json property name to set
level2 Optional String Second level json property name to set
level3 Optional String Third level json property name to set
level4 Optional String Fourth level json property name to set
value Optional String String value to set
increment-int Optional Boolean Increment the existing value or use the '/value' as the value if it does not exist or isn't an integer.
increment-minor-version Optional Boolean Increment the minor version of the existing value or use the '/value' as the value if it does not exist or isn't an integer.
increment-patch-version Optional Boolean Increment the patch version of the existing value or use the '/value' as the value if it does not exist or isn't an integer.
bool Optional Boolean Set value into the json as boolean

setpackageversion

Changes NuGet package references in a C# project file to a new value.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution file to use
preview Optional Boolean Preview changes only
filter Optional String Filter package by name. If package name starts with this value, it gets updated.
version Required String Package version to reference

setprojectproperty

Set a project property value on all projects.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution to examine. If this value is not supplied, the tool searches for a sln file automatically.
propertyname Required String Name of the property to set.
propertyvalue Required String Value for the property.

setprojectversion

Set the assembly and nuget package version property value on a project.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution to examine. If this value is not supplied, the tool searches for a sln file automatically.
project Required String Project name to update.
increment Optional Boolean Increment the minor value.
value Optional String Value for the property.

sortpropertygroup

Sorts the elements in a property group for a csproj file.

Arguments

Argument Is Optional Data Type Description
project Optional String Project file to edit. If this value is not supplied, the tool looks for a csproj file in the current directory.

sortreferences

Sorts the references in an item group for a csproj file.

Arguments

Argument Is Optional Data Type Description
project Optional String Project file to edit. If this value is not supplied, the tool looks for a csproj file in the current directory.

base64

Encodes a string value as a base 64 string.

Arguments

Argument Is Optional Data Type Description
value Required String Value to encode as base64

touch

Modifies a file's date to current date time or creates a new empty file if it doesn't exist.

Arguments

Argument Is Optional Data Type Description
filename Required String Path to file

updatebicepversions

Reads bicep file or files and updates the api versions to latest.

Arguments

Argument Is Optional Data Type Description
filename Optional String Name of the bicep file, if you want to update just one file.
previewversions Optional Boolean Allow preview versions for resources.
preview Optional Boolean Do not save changes only preview the changes.

updategithubactionsversions

Reads a GitHub Actions YAML file and updates the action versions to latest.

Arguments

Argument Is Optional Data Type Description
filename Optional String Name of the GitHub Actions YAML file to update.

validateconnectionstring

Validate that specified connection string can connect to SQL Server.

Arguments

Argument Is Optional Data Type Description
filename Optional String Path to json config file
name Required String Name of the connection string to validate

wildcardreference

Changes package references in a C# project file to use wildcard version rather than fixed version number.

Arguments

Argument Is Optional Data Type Description
solutionpath Optional String Solution file to use
preview Optional Boolean Preview changes only
filter Required String Filter package by name. If package name starts with this value, it gets updated.

snippetize

Reads a block of text from the clipboard and formats it for use in a VSCode snippet.

Arguments

Argument Is Optional Data Type Description
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
2.40.0 100 5/19/2026
2.38.0 100 5/18/2026
2.37.0 151 4/10/2026
2.35.1 161 3/5/2026
2.35.0 122 3/4/2026
2.33.0 157 1/20/2026
2.32.1 318 12/17/2025
2.32.0 299 12/17/2025
2.31.0 254 11/4/2025
2.30.0 250 11/3/2025
2.29.0 264 10/2/2025
2.28.0 334 9/4/2025
2.27.0 255 9/4/2025
2.26.0 594 7/21/2025
2.25.0 458 6/11/2025
2.24.0 324 5/16/2025
2.23.0 348 4/24/2025
2.22.0 297 3/21/2025
2.21.0 218 3/21/2025
2.20.0 326 3/9/2025
Loading failed

v2.40 - enablecodeanalysis: also installs Microsoft.CodeAnalysis.CSharp.CodeStyle for IDE rule enforcement (default on; opt out with /enforce-code-style:false); added /codestyle-version to pin the package version;
v2.39 - findsolutions: added target-framework and uses-packages-config columns plus finer-grained reference-type classification (framework-ref, nuget-via-packages-config, fixed PackageReference detection); Added enablecodeanalysis command to streamline VS2026 code
  analysis across a solution, with a per-project mode for packages.config solutions;
v2.38 - Fixing bugs in findsolutions command; Updating createsolution to create modern xunit projects;
v2.37 - Added updategithubactionsversions command to update GitHub Actions versions in workflow files;
v2.36 - Added formatjson command to format JSON files;
v2.35 - Added 'gui' support to launch a blazor UI for this command; Updated dependencies and minor bug fixes;
v2.34 - Modified find solutions command to also find .slnx files;
v2.33 - Modified SetJsonValueCommand to allow incrementing patch version numbers;
v2.32.1 - Updated dependencies to fix security vulnerabilities;
v2.32 - Added support for .net10; Added support for slnx files; Modified create solution command to no longer install FluentAssertions library;
v2.31 - Modified classes from json command to 1) detect DateTime property values 2) optionally generate inner classes instead of separate classes;
v2.30 - Added clipboard option to classes from json command to read JSON from clipboard instead of a file or console input;
v2.29 - Added printfile command to read a text file and print it to the console character by character. This is helpful for diagnosing encoding issues and weird text issues.;
v2.28 - Adding run sql command to execute SQL commands or SQL script files against a SQL Server database;
v2.27 - Adding support for json comments to JsonToClasses command;
v2.26 - Added command to sort references in a csproj file.
v2.25 - Added utility to check versions in bicep files and update to latest.
v2.24 - Added option to devtreeclean to preserve node_modules directories.
v2.23 - Added command to sort the values in the first PropertyGroup of a csproj file; Fixing bugs related to Process.Start() timeouts and stream reading in CreateSolutionCommand.
v2.22 - Added set package version command to update NuGet package versions in project files using optional package name filtering.
v2.21 - Modified set framework version command to more gracefully handle OS-specific targeting. Adding net8.0 and net9.0 to target frameworks.
v2.20 - Added prefix option to bulk rename command
v2.19 - Bug fixes; Support in class diagram for protected members; Class diagram option for showing locally defined members
v2.18 - Fixing bugs in formatxml command
v2.17 - Fixing bugs in class diagram generator
v2.16 - Restored the devtreeclean command which had been accidentally removed.
v2.15 - You don't wanna know. It was a mess.
v2.14 - Generate class diagrams for an assembly.
v2.13 - Added xml formatter command that allows recursive file processing.
v2.12 - Command to update or increment package version number and assembly version number.
v2.11 - Added support for setting values as json boolean in via setjsonvalue.
v2.10 - Fixed bug in setprojectproperty command where values were not updated if the property already existed.
v2.9 - Added assembly info viewer.
v2.8 - Added option to devtreeclean to keep git repositories when cleaning a directory tree.
v2.7 - Added wildcard reference command.
v2.6 - Updated nuget package to include Benday.CommandsFramework v3.2.0.
v2.5 - Updated jsontoclasses to add support for hyphens in json property names.