A .NET Global Tool for easily managing connection strings across different environments in C# applications.
- 🔄 Easy Environment Switching - Switch between Development, QA, and Production with one command
- 🛡️ Automatic Backups - Creates timestamped backups before making changes
- 📁 Multiple File Formats - Supports both
appsettings.jsonandweb.config/app.config - 🔒 Security Conscious - Masks sensitive information when displaying connection strings
- ⚡ Global Tool - Install once, use anywhere
- 🎯 Simple Commands - Intuitive command-line interface
Want to see it in action with real databases? Create our ConnectionStringTester demo app - a complete example showing the tool working with real SQLite databases. The demo visually shows your connection strings switching between Development, QA, and Production environments. See the demo documentation for setup instructions.
Install as a .NET Global Tool:
dotnet tool install -g ConnectionStringManagerOr install from local source:
dotnet tool install -g ConnectionStringManager --add-source ./path/to/nupkg# Switch to different environments
connstr -f appsettings.json -e Development
connstr -f appsettings.json -e QA
connstr -f appsettings.json -e Production
# List all connection strings
connstr -f appsettings.json --list
# Switch without creating backup
connstr -f appsettings.json -e Production --no-backup-f, --file <path>- Path to configuration file (required)-e, --environment <env>- Target environment (Development, QA, Production)-l, --list- List all available connection strings-n, --name <pattern>- Custom naming pattern (default:{Environment}Connection)--no-backup- Skip creating backup file-h, --help- Show help information
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=MyApp;Trusted_Connection=true;",
"DevelopmentConnection": "Server=dev-server;Database=MyApp_Dev;Trusted_Connection=true;",
"QAConnection": "Server=qa-server;Database=MyApp_QA;User Id=qa_user;Password=qa_pass;",
"ProductionConnection": "Server=prod-server;Database=MyApp_Prod;User Id=prod_user;Password=secure_pass;"
}
}<configuration>
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=localhost;Database=MyApp;Trusted_Connection=true;"
providerName="System.Data.SqlClient" />
<add name="DevelopmentConnection"
connectionString="Server=dev-server;Database=MyApp_Dev;Trusted_Connection=true;"
providerName="System.Data.SqlClient" />
<add name="QAConnection"
connectionString="Server=qa-server;Database=MyApp_QA;User Id=qa_user;Password=qa_pass;"
providerName="System.Data.SqlClient" />
<add name="ProductionConnection"
connectionString="Server=prod-server;Database=MyApp_Prod;User Id=prod_user;Password=secure_pass;"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>The tool updates your DefaultConnection to match the selected environment's connection string:
- Before:
DefaultConnectionpoints to development database - Run:
connstr -f appsettings.json -e Production - After:
DefaultConnectionnow points to production database - Backup: Original file saved as
appsettings.json.backup.20241218_143022
Your application code remains unchanged - it continues to use DefaultConnection.
PowerShell:
param([string]$Environment = "Development")
connstr -f "src/MyApp/appsettings.json" -e $Environment
dotnet build
dotnet runBatch File:
@echo off
set ENV=%1
if "%ENV%"=="" set ENV=Development
connstr -f appsettings.json -e %ENV%
dotnet run# Azure DevOps / GitHub Actions example
- name: Switch to Production Environment
run: connstr -f src/MyApp/appsettings.json -e Production
- name: Build Application
run: dotnet build -c ReleaseEnsure .NET tools are in your PATH:
# Windows
set PATH=%PATH%;%USERPROFILE%\.dotnet\tools
# Linux/Mac
export PATH="$PATH:$HOME/.dotnet/tools"Verify your connection string naming:
- Default pattern:
{Environment}Connection - Examples:
DevelopmentConnection,QAConnection,ProductionConnection - Use custom pattern:
connstr -f config.json -e Development -n "{Environment}DB"
- Close the config file in your IDE
- Check file permissions
- Verify file path is correct
- .NET 8.0 or later
- Windows, macOS, or Linux
# Update to latest version
dotnet tool update -g ConnectionStringManager
# Uninstall if needed
dotnet tool uninstall -g ConnectionStringManagerMIT License - feel free to use in your projects.
Found a bug or want to add a feature? Issues and pull requests welcome!
Made with ❤️ for C# developers who are tired of manually switching connection strings.