Config Dragon ist ein Befehlszeilen -Dienstprogramm, mit dem Sie Konfigurationsdateien in .NET -Lösungen einrichten können.
Es wird ein configDragon.bat und ein ConfigDragon.json zu Ihrem Projekt hinzugefügt.
Die Standardvorlage sieht so aus.
{
"RepositoryRootDirectory" : "" ,
"HgExecutablePath" : "%USERPROFILE%\AppData\Local\Atlassian\SourceTree\hg_local\hg.exe" ,
"GitExecutablePath" : "%USERPROFILE%\AppData\Local\Atlassian\SourceTree\git_local\bin\git.exe" ,
"ConfigActions" : [
{
"Name" : "Dev" ,
"ConfigItems" : [
{
"Name" : "AppConfigChange" ,
"RelativeDirectory" : "PATH_RELATIVE_TO_RepositoryRootDirectory" ,
"TargetFilename" : "app.config" ,
"PackageName" : "DevelopmentPackage"
}
]
} ,
{
"Name" : "Prod" ,
"ConfigItems" : [
{
"Name" : "AppConfigChange" ,
"RelativeDirectory" : "PATH_RELATIVE_TO_RepositoryRootDirectory" ,
"TargetFilename" : "app.config" ,
"PackageName" : "ProductionPackage"
}
]
}
] ,
"ConfigPackages" : [
{
"Name" : "DevelopmentPackage" ,
"AppSettings" : {
"YOUR_APP_SETTING_KEY" : "YOUR_APP_SETTING_VALUE"
} ,
"ConnectionStrings" : {
"YOUR_CONNECTION_STRING_NAME" : "YOUR_CONNECTION_STRING_VALUE"
} ,
"XmlSettings" : [
{
"Selector" : "/configuration/nlog:nlog/nlog:rules/nlog:logger[@writeTo='logfile']/@minlevel" ,
"Value" : "TRACE" ,
"Description" : "Sets the nlog level" ,
"Namespaces" : {
"nlog" : "http://www.nlog-project.org/schemas/NLog.xsd"
}
} ,
{
"Selector" : "/vs:Project/vs:ProjectExtensions/vs:VisualStudio/vs:FlavorProperties/vs:WebProjectProperties/vs:IISUrl" ,
"Value" : "http://localhost:8000" ,
"Description" : "Sets the local IIS express url to localhost" ,
"Namespaces" : {
"vs" : "http://schemas.microsoft.com/developer/msbuild/2003"
}
}
]
} ,
{
"Name" : "ProductionPackage" ,
"AppSettings" : {
"YOUR_APP_SETTING_KEY" : "YOUR_APP_SETTING_VALUE"
} ,
"ConnectionStrings" : {
"YOUR_CONNECTION_STRING_NAME" : "YOUR_CONNECTION_STRING_VALUE"
} ,
"XmlSettings" : [
{
"Selector" : "/configuration/nlog:nlog/nlog:rules/nlog:logger[@writeTo='logfile']/@minlevel" ,
"Value" : "TRACE" ,
"Description" : "Sets the nlog level" ,
"Namespaces" : {
"nlog" : "http://www.nlog-project.org/schemas/NLog.xsd"
}
} ,
{
"Selector" : "/vs:Project/vs:ProjectExtensions/vs:VisualStudio/vs:FlavorProperties/vs:WebProjectProperties/vs:IISUrl" ,
"Value" : "http://localhost:8000" ,
"Description" : "Sets the local IIS express url to localhost" ,
"Namespaces" : {
"vs" : "http://schemas.microsoft.com/developer/msbuild/2003"
}
}
] ,
"StringSettings" : [
{
"Needle" : "value="123456"" ,
"ReplacementValue" : "value="test"" ,
"Description" : "Replace a setting"
}
]
}
]
}Richten Sie ein Konfigurationspaket ein, das Ihre Verbindungszeichenfolge und die App -Einstellungsänderungen enthält.
{
"Name" : "DevelopmentPackage" ,
"AppSettings" : {
"YOUR_APP_SETTING_KEY" : "YOUR_APP_SETTING_VALUE"
} ,
"ConnectionStrings" : {
"YOUR_CONNECTION_STRING_NAME" : "YOUR_CONNECTION_STRING_VALUE"
} ,
"XmlSettings" : [
{
"Selector" : "/configuration/nlog:nlog/nlog:rules/nlog:logger[@writeTo='logfile']/@minlevel" ,
"Value" : "TRACE" ,
"Description" : "Sets the nlog level" ,
"Namespaces" : {
"nlog" : "http://www.nlog-project.org/schemas/NLog.xsd"
}
} ,
{
"Selector" : "/vs:Project/vs:ProjectExtensions/vs:VisualStudio/vs:FlavorProperties/vs:WebProjectProperties/vs:IISUrl" ,
"Value" : "http://localhost:8000" ,
"Description" : "Sets the local IIS express url to localhost" ,
"Namespaces" : {
"vs" : "http://schemas.microsoft.com/developer/msbuild/2003"
}
}
] ,
"StringSettings" : [
{
"Needle" : "value="123456"" ,
"ReplacementValue" : "value="test"" ,
"Description" : "Replace a setting"
}
]
} {
"Name" : "Dev" ,
"ConfigItems" : [
{
"Name" : "YOUR_PROJECT_NAME" ,
"RelativeDirectory" : "PATH_RELATIVE_TO_RepositoryRootDirectory" ,
"TargetFilename" : "app.config" ,
"PackageName" : "DevelopmentPackage"
}
]
}Um den Änderungsaufruf "configDragon.bat dev" auszuführen, um die Änderungen in Ihrem Projekt anzuwenden. Das war's!
Sie können mehrere Konfigurationselemente zum gleichen Paket aufrufen. Ein Szenario, in dem dies benötigt wird, ist eine Lösung mit mehreren Projekten, die dieselbe Konfigurationsänderung benötigen.
XML -Änderungen Verwenden Sie einen XPath 1.0 -Selektor, um den Knoten zum Ändern zu finden. Eine XML -Einstellung verfügt über einen Schlüssel-/Wert -Satz von Namespaces, den Sie hinzufügen können, wenn Ihr XML Namespaces verwendet. https://www.w3schools.com/xml/xpath_examples.asp hat ein einfaches Tutorial darüber, wie XPath funktioniert.
Der Saitenersatz funktioniert wie erwarten. Es sucht nach einer Zeichenfolge und ersetzt sie durch eine andere Zeichenfolge. Dies ist nützlich, um Variablen in JavaScript -Dateien festzulegen. Die Zeichenfolge muss entkommen und gültig sein, um zu arbeiten.
"StringSettings" : [
{
"Needle" : "value="123456"" ,
"ReplacementValue" : "value="test"" ,
"Description" : "Replace a setting"
}
]In diesem Beispiel würden wir nach Value = "123456" suchen und ihn durch Value = "Test" ersetzen.