diff --git a/extensions/sql-database-projects/src/models/project.ts b/extensions/sql-database-projects/src/models/project.ts index fbea48abfa..9ea7be6e43 100644 --- a/extensions/sql-database-projects/src/models/project.ts +++ b/extensions/sql-database-projects/src/models/project.ts @@ -172,16 +172,17 @@ export class Project implements ISqlProject { for (let ig = 0; ig < this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.ItemGroup).length; ig++) { const itemGroup = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.ItemGroup)[ig]; - // find all files to include that are specified in the project file + // find all files to include that are specified to be included and removed (for sdk style projects) in the project file + // the build elements are evaluated in the order they are in the sqlproj (same way sdk style csproj handles this) try { const buildElements = itemGroup.getElementsByTagName(constants.Build); - // for (let b = 0; b < buildElements.length; b++) { - const relativePath = buildElements[b].getAttribute(constants.Include)!; + // + const includeRelativePath = buildElements[b].getAttribute(constants.Include)!; - if (relativePath) { - const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath)); + if (includeRelativePath) { + const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(includeRelativePath)); // sdk style projects can handle other globbing patterns like and if (this._isSdkStyleProject && !(await utils.exists(fullPath))) { @@ -192,25 +193,23 @@ export class Project implements ISqlProject { filesSet.add(newFileRelativePath); }); } else { - filesSet.add(relativePath); + filesSet.add(includeRelativePath); // Right now only used for external streaming jobs const typeAttribute = buildElements[b].getAttribute(constants.Type)!; if (typeAttribute) { - entriesWithType.push({ relativePath, typeAttribute }); + entriesWithType.push({ relativePath: includeRelativePath, typeAttribute: typeAttribute }); } } } - } - // - // after all the files have been included, remove the ones specified in the sqlproj to remove - if (this._isSdkStyleProject) { - for (let b = 0; b < buildElements.length; b++) { - const relativePath = buildElements[b].getAttribute(constants.Remove)!; + // + // remove files specified in the sqlproj to remove if this is an sdk style project + if (this._isSdkStyleProject) { + const removeRelativePath = buildElements[b].getAttribute(constants.Remove)!; - if (relativePath) { - const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath)); + if (removeRelativePath) { + const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(removeRelativePath)); const globRemoveFiles = await utils.globWithPattern(fullPath); globRemoveFiles.forEach(gf => { diff --git a/extensions/sql-database-projects/src/test/baselines/openSdkStyleSqlProjectWithBuildRemoveBaseline.xml b/extensions/sql-database-projects/src/test/baselines/openSdkStyleSqlProjectWithBuildRemoveBaseline.xml index 2565aec26e..d01d6e2baa 100644 --- a/extensions/sql-database-projects/src/test/baselines/openSdkStyleSqlProjectWithBuildRemoveBaseline.xml +++ b/extensions/sql-database-projects/src/test/baselines/openSdkStyleSqlProjectWithBuildRemoveBaseline.xml @@ -16,7 +16,12 @@ + + + + + diff --git a/extensions/sql-database-projects/src/test/project.test.ts b/extensions/sql-database-projects/src/test/project.test.ts index ddd7bb130d..d8c4e32da1 100644 --- a/extensions/sql-database-projects/src/test/project.test.ts +++ b/extensions/sql-database-projects/src/test/project.test.ts @@ -929,21 +929,40 @@ describe('Project: sdk style project content operations', function (): void { const project: Project = await Project.openProject(projFilePath); - should(project.files.filter(f => f.type === EntryType.File).length).equal(6); + should(project.files.filter(f => f.type === EntryType.File).length).equal(7); + + // make sure all the correct files from the globbing patterns were included and removed are evaluated in order - // make sure all the correct files from the globbing patterns were included and excluded // // + // expected: ..\other\folder1\file1.sql is not included should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\file1.sql').length).equal(0); should(project.files.filter(f => f.relativePath === '..\\other\\folder1\\file2.sql').length).equal(1); + // + // + // expected: ..\other\folder2\file2.sql is not included + should(project.files.filter(f => f.relativePath === '..\\other\\folder2\\file1.sql').length).equal(0); + should(project.files.filter(f => f.relativePath === '..\\other\\folder2\\file2.sql').length).equal(0); + // + // + // expected: folder1\file2.sql is included should(project.files.filter(f => f.relativePath === 'folder1\\file1.sql').length).equal(0); - should(project.files.filter(f => f.relativePath === 'folder1\\file2.sql').length).equal(0); + should(project.files.filter(f => f.relativePath === 'folder1\\file2.sql').length).equal(1); should(project.files.filter(f => f.relativePath === 'folder1\\file3.sql').length).equal(0); should(project.files.filter(f => f.relativePath === 'folder1\\file4.sql').length).equal(0); should(project.files.filter(f => f.relativePath === 'folder1\\file5.sql').length).equal(0); + // + // + // expected: folder2\file3.sql is included + should(project.files.filter(f => f.relativePath === 'folder2\\file1.sql').length).equal(1); + should(project.files.filter(f => f.relativePath === 'folder2\\file2.sql').length).equal(1); + should(project.files.filter(f => f.relativePath === 'folder2\\file3.sql').length).equal(1); + should(project.files.filter(f => f.relativePath === 'folder2\\file4.sql').length).equal(1); + should(project.files.filter(f => f.relativePath === 'folder2\\file5.sql').length).equal(1); + // should(project.files.filter(f => f.relativePath === 'file1.sql').length).equal(0); });