Because of the old maxim "anything you do more than once should be automated", we all find ourselves working with tools to auto-generate projects and solutions for Helix architecture these days. Mostly these tools work fine – but every so often you can bump your head against unexpected behaviour – as I did recently:
Cue some head scratching...
const files = fs.readdirSync(this.destinationPath()); const SolutionFile = files.find(file => file.toUpperCase().endsWith(".SLN")); const scriptParameters = '-SolutionFile \'' + this.destinationPath(SolutionFile) + '\' -Name ' + this.settings.LayerPrefixedProjectName + ' -Type ' + this.layer + ' -ProjectPath \'' + this.settings.ProjectPath + '\'' + ' -SolutionFolderName ' + this.templatedata.projectname;
This is the code that gets called when you run
yo helix:add
– So because my backup file was coming up first in the solution folder's file listing, the change was getting made to my backup file – not to my active solution. A behaviour I could quickly check with a diff between these two files, to show that it was the copy which had recevied my updates:
Confusion resolved! And a simple change to rename the backup file so it would sort last fixed my problem.
And yes, I know – I could just use Source Control to undo changes rather than messing with backups. But sometimes "the lazy answer" teaches you something new. And it's not uncommon for me to find source trees with multiple solution files...
↑ Back to top