Closed nblumhardt closed 10 years ago
Given this file system:
Web.config
Web.Dev.config
Web.Prod.config
Web.Release.config
Assume we deployed to Prod. We would have run Web.Prod.config, and Web.Release.config. It's obvious those files should be deleted.
But how can we tell that Web.config should be kept, while Web.Dev.config shouldn't? I.e., how do we know which files are transforms and which files aren't?
Will the decision be based on the existence of:
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
On the root node?
Perhaps we'd be better off introducing a Delete files feature, so you could just specify Web.*.config; Views\Web.*.config
as the file list and match everything that needs to be cleaned up.
Doing it this way would be more generally useful, anyway.
This feature will need a method to exclude files or be based off a white list. It's common to have other .config
files match this pattern e.g. Web.log4net.config
.
Perhaps something like the TeamCity approach of + and -?
+:*.config
-:*.log4net.config
Added Clean-Files PowerShell Step Template OctopusDeploy/Library#37
@Lavinski I think that makes this item closeable, since the solution doesn't directly address what's on this ticket. Let's follow up via the PR.
Hello guys, is there any chance of re-opening this issue? :)
The step template is a great workaround (thanks for that!) and I'm using it, but having to have an extra step on every single deployment process is very annoying.
I'd love to have a checkbox on the "Deploy a NuGet package" step, that matches all .config files that match *.any-of-my-environments.config
or *.Release.config
I have very easily achieved this using this script (based on the namespace as @PaulStovell suggests):
Script:
Write-Host 'Preparing to delete config transformation files in $TargetPath:' $TargetPath
function DeleteIfConfigTransformFile($file)
{
try
{
$xdoc = New-Object System.Xml.XmlDocument
$xdoc.Load($file)
if($xdoc.DocumentElement.xdt -eq "http://schemas.microsoft.com/XML-Document-Transform")
{
Write-Host "Deleting file:" $file
#Remove-Item $file
}
else
{
Write-Host "Not deleting config file (doesn't have the correct xdt xml namespace declaration):" $file
}
}
catch
{
Write-Host "Could not xml parse file:" $file
}
}
Get-ChildItem $TargetPath -Recurse | Where-Object { $_.Name -like "*.config" } | ForEach-Object { DeleteIfConfigTransformFile ($_.FullName) }
Note that it requires the files to be named *.config and the root element to be called "configuration". So only config transform files for now. This could be easily changes though.
Export of script template JSON:
{
"Id": "ActionTemplates-5",
"Name": "Delete Config Transform Files",
"Description": "Recursively deletes all files underneath #{TargetPath} which has the extension .config, is parsable xml and has the namespace xmlns:xdt=\"http://schemas.microsoft.com/XML-Document-Transform\" defined.",
"ActionType": "Octopus.Script",
"Version": 7,
"Properties": {
"Octopus.Action.Script.ScriptBody": "Write-Host 'Preparing to delete config transformation files in $TargetPath:' $TargetPath\r\n\r\nfunction DeleteIfConfigTransformFile($file)\r\n{\r\n try\r\n {\r\n $xdoc = New-Object System.Xml.XmlDocument\r\n $xdoc.Load($file)\r\n\r\n if($xdoc.DocumentElement.xdt -eq \"http://schemas.microsoft.com/XML-Document-Transform\")\r\n {\r\n Write-Host \"Deleting file:\" $file\r\n Remove-Item $file\r\n }\r\n else\r\n {\r\n Write-Host \"Not deleting config file (doesn't have the correct xdt xml namespace declaration):\" $file\r\n }\r\n }\r\n catch\r\n {\r\n Write-Host \"Could not xml parse file:\" $file\r\n }\r\n \r\n}\r\n\r\nGet-ChildItem $TargetPath -Recurse | Where-Object { $_.Name -like \"*.config\" } | ForEach-Object { DeleteIfConfigTransformFile ($_.FullName) }"
},
"SensitiveProperties": {},
"Parameters": [
{
"Name": "TargetPath",
"Label": "Target path",
"HelpText": "The path to clean.\n\nUsually you would set this to `Octopus.Action[StepName].Output.Package.InstallationDirectoryPath`.",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"LastModifiedOn": "2015-05-05T14:26:52.105+00:00",
"LastModifiedBy": "epe@dis.dk",
"$Meta": {
"ExportedAt": "2015-05-05T14:27:29.530Z",
"OctopusVersion": "2.6.5.1010",
"Type": "ActionTemplate"
}
}
Thanks @donesbon. I'm using Sitecore which has many config files the other step template deleted, but yours did the job.
@jo3stevens I used it wit Sitecore too. Glad it worked for you
Is there a version of this that would work with an Azure web app deployment?
Hi @johndowns I haven't worked with Octopus or deployment of any kind for a long long time (or Azure for that matter). I won't be of any help :(
Would be great to implement this as par of the deployment step for IIS websites and Azure webapps, I think this is something we all need. /cc @PaulStovell
This thread has been automatically locked since there has not been any recent activity after it was closed. If you think you've found a related issue, please contact our support team so we can triage your issue, and make sure it's handled appropriately.
Via http://help.octopusdeploy.com/discussions/questions/243-deleting-config-transformation-files-after-deploy
Lingering .config files cause issues for some applications.