Automatically add intermediate folders for SQL project items. (#16332)

* Automatically add intermediate folders for SQL project items.

While using the SQL database projects through the API, I noticed that project may end up in somewhat inconsistent state, where files will be added to the project, but their parent folders will not. This in turn resulted in failure to remove these folders from project - they will show up in the UI tree, but deleting them will cause an error. In order to align with how Visual Studio manages the projects, this change will ensure that all intermediate folders are present in the project, when new files or folders are added.

While this change improves project "correctness" when accessing it through SQL projects extension APIs, there is still a possibility that someone will open an "incorrect" previously created project. This change does not address it and folder removal may still fail.

* Update the code to never throw on duplicate items when adding files and folders to project.

After a conversation with the sqlproj owners, we agreed that there are no scenarios that would prompt us to throw an error, if duplicate item is being added to the project. Ultimately, the goal of such a request would be to have an item in the project file, which is already present, therefore the call becomes a no-op.

This allowed me to simplify the new code that was ensuring all intermediate folders are present in the project when adding files and folders.
This commit is contained in:
Alexander Ivanov
2021-08-03 09:49:11 -07:00
committed by GitHub
parent 052cb54199
commit b35e78a07f
6 changed files with 279 additions and 137 deletions

View File

@@ -192,7 +192,7 @@ describe('ProjectsController', function (): void {
// confirm result
should(proj.files.length).equal(1, 'number of file/folder entries'); // lowerEntry and the contained scripts should be deleted
should(proj.files[0].relativePath).equal('UpperFolder');
should(proj.files[0].relativePath).equal('UpperFolder\\');
should(proj.preDeployScripts.length).equal(0);
should(proj.postDeployScripts.length).equal(0);
should(proj.noneDeployScripts.length).equal(0);
@@ -253,7 +253,7 @@ describe('ProjectsController', function (): void {
// confirm result
should(proj.files.length).equal(1, 'number of file/folder entries'); // LowerFolder and the contained scripts should be deleted
should(proj.files[0].relativePath).equal('UpperFolder'); // UpperFolder should still be there
should(proj.files[0].relativePath).equal('UpperFolder\\'); // UpperFolder should still be there
should(proj.preDeployScripts.length).equal(0);
should(proj.postDeployScripts.length).equal(0);
should(proj.noneDeployScripts.length).equal(0);