A collection of useful command line utilities for .NET Core Solutions & Projects
$ dotnet add package slnutilA collection of utilities for working with .NET Solutions and Projects (.sln and .slnx).
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
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.
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
| 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. |
| findsolutions | Find solution files (sln and slnx) in a folder tree and optionally list projects with reference analysis. |
| 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. |
| 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. |
View assembly info for a DLL.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| filename | Required | String | Assembly to view |
Bulk rename for files and folders.
| 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 |
Generate a class diagram for an assembly.
| 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. |
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.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| solutionpath | Optional | String | Solution file to use |
| preview | Optional | Boolean | Preview changes only |
Create a solution and projects
| 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 |
Deploy EF Core Migrations from DLL binaries.
| 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 |
Clean development folder tree. Removes node_modules, .git, bin, obj, and TestResults folders.
| 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. |
Find solution files (sln and slnx) in a folder tree and optionally list projects with reference analysis.
| 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 |
Formats XML files
| 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 |
Get database connection string in appsettings.json.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| filename | Optional | String | Path to json config file |
| name | Required | String | Name of the connection string to get |
Create C# classes from JSON with serialization attributes for System.Text.Json.
| 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. |
Lists packages referenced in legacy style packages.config files.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| rootdir | Optional | String | Path to start search from |
Gets list of projects in a solution.
| 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. |
Reads a text file and prints it to the console character by character. This is helpful for diagnosing encoding issues and weird text issues.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| input | Required | String | Path to the text file to read and print. |
Replace token in file.
| 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 |
Execute SQL command or SQL script file against a database.
| 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) |
Set database connection string in appsettings.json.
| 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 |
Set the target framework version on all projects.
| 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. |
Set a string value in a json file.
| 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 |
Changes NuGet package references in a C# project file to a new value.
| 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 |
Set a project property value on all projects.
| 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. |
Set the assembly and nuget package version property value on a project.
| 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. |
Sorts the elements in a property group for a csproj file.
| 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. |
Sorts the references in an item group for a csproj file.
| 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. |
Encodes a string value as a base 64 string.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| value | Required | String | Value to encode as base64 |
Modifies a file's date to current date time or creates a new empty file if it doesn't exist.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| filename | Required | String | Path to file |
Reads bicep file or files and updates the api versions to latest.
| 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. |
Validate that specified connection string can connect to SQL Server.
| Argument | Is Optional | Data Type | Description |
|---|---|---|---|
| filename | Optional | String | Path to json config file |
| name | Required | String | Name of the connection string to validate |
Changes package references in a C# project file to use wildcard version rather than fixed version number.
| 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. |
Reads a block of text from the clipboard and formats it for use in a VSCode snippet.
| Argument | Is Optional | Data Type | Description |
|---|