Darüber habe ich einen Artikel in meinem Blog geschrieben: http://pvlerick.github.io/2009/03/encrypt-appconfig-section-using-powershell-as-a-post-build-event
Meine Idee war, dass das Passwort in der IDE klar sein soll, aber in der web.config/app.config des Ausgabeordners verschlüsselt.
Das Skript lautet
param(
[String] $appPath = $(throw "Application exe file path is mandatory"),
[String] $sectionName = $(throw "Configuration section is mandatory"),
[String] $dataProtectionProvider = "DataProtectionConfigurationProvider"
)
#The System.Configuration assembly must be loaded
$configurationAssembly = "System.Configuration, Version=2.0.0.0, Culture=Neutral, PublicKeyToken=b03f5f7f11d50a3a"
[void] [Reflection.Assembly]::Load($configurationAssembly)
Write-Host "Encrypting configuration section..."
$configuration = [System.Configuration.ConfigurationManager]::OpenExeConfiguration($appPath)
$section = $configuration.GetSection($sectionName)
if (-not $section.SectionInformation.IsProtected)
{
$section.SectionInformation.ProtectSection($dataProtectionProvider);
$section.SectionInformation.ForceSave = [System.Boolean]::True;
$configuration.Save([System.Configuration.ConfigurationSaveMode]::Modified);
}
Write-Host "Succeeded!"
Der Post-Build-Befehl lautet
powershell "& ""C:\Documents and Settings\VlericP\My Documents\WindowsPowerShell\EncryptAppConfigSection.ps1""" '$(TargetPath)' 'connectionStrings'