update names for msbuild sdk style projects (#17677)

* update names for msbuild sdk style projects

* remove msbuild from names

* update comments
This commit is contained in:
Kim Santiago
2021-11-16 11:23:19 -10:00
committed by GitHub
parent 24a6de404c
commit 6725e07ece
11 changed files with 48 additions and 48 deletions

View File

@@ -21,7 +21,7 @@ export const msdb = 'msdb';
export const msdbDacpac = 'msdb.dacpac'; export const msdbDacpac = 'msdb.dacpac';
export const MicrosoftDatatoolsSchemaSqlSql = 'Microsoft.Data.Tools.Schema.Sql.Sql'; export const MicrosoftDatatoolsSchemaSqlSql = 'Microsoft.Data.Tools.Schema.Sql.Sql';
export const databaseSchemaProvider = 'DatabaseSchemaProvider'; export const databaseSchemaProvider = 'DatabaseSchemaProvider';
export const sqlMsbuildSdk = 'Microsoft.Build.Sql'; export const sqlProjectSdk = 'Microsoft.Build.Sql';
// Project Provider // Project Provider
export const emptySqlDatabaseProjectTypeId = 'EmptySqlDbProj'; export const emptySqlDatabaseProjectTypeId = 'EmptySqlDbProj';

View File

@@ -34,7 +34,7 @@ export class Project implements ISqlProject {
private _preDeployScripts: FileProjectEntry[] = []; private _preDeployScripts: FileProjectEntry[] = [];
private _postDeployScripts: FileProjectEntry[] = []; private _postDeployScripts: FileProjectEntry[] = [];
private _noneDeployScripts: FileProjectEntry[] = []; private _noneDeployScripts: FileProjectEntry[] = [];
private _isMsbuildSdkStyleProject: boolean = false; private _isSdkStyleProject: boolean = false; // https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview
public get dacpacOutputPath(): string { public get dacpacOutputPath(): string {
return path.join(this.projectFolderPath, 'bin', 'Debug', `${this._projectFileName}.dacpac`); return path.join(this.projectFolderPath, 'bin', 'Debug', `${this._projectFileName}.dacpac`);
@@ -88,8 +88,8 @@ export class Project implements ISqlProject {
return this._noneDeployScripts; return this._noneDeployScripts;
} }
public get isMsbuildSdkStyleProject(): boolean { public get isSdkStyleProject(): boolean {
return this._isMsbuildSdkStyleProject; return this._isSdkStyleProject;
} }
private projFileXmlDoc: Document | undefined = undefined; private projFileXmlDoc: Document | undefined = undefined;
@@ -119,8 +119,8 @@ export class Project implements ISqlProject {
const projFileText = await fs.readFile(this._projectFilePath); const projFileText = await fs.readFile(this._projectFilePath);
this.projFileXmlDoc = new xmldom.DOMParser().parseFromString(projFileText.toString()); this.projFileXmlDoc = new xmldom.DOMParser().parseFromString(projFileText.toString());
// check if this is a new msbuild sdk style project // check if this is an sdk style project https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview
this._isMsbuildSdkStyleProject = this.CheckForMsbuildSdkStyleProject(); this._isSdkStyleProject = this.CheckForSdkStyleProject();
// get files and folders // get files and folders
this._files = await this.readFilesInProject(); this._files = await this.readFilesInProject();
@@ -151,14 +151,14 @@ export class Project implements ISqlProject {
/** /**
* Gets all the files specified by <Build Inlude="..."> and removes all the files specified by <Build Remove="..."> * Gets all the files specified by <Build Inlude="..."> and removes all the files specified by <Build Remove="...">
* and all files included by the default glob of the folder of the sqlproj if it's an msbuild sdk style project * and all files included by the default glob of the folder of the sqlproj if it's an sdk style project
*/ */
private async readFilesInProject(): Promise<FileProjectEntry[]> { private async readFilesInProject(): Promise<FileProjectEntry[]> {
const filesSet: Set<string> = new Set(); const filesSet: Set<string> = new Set();
const entriesWithType: { relativePath: string, typeAttribute: string }[] = []; const entriesWithType: { relativePath: string, typeAttribute: string }[] = [];
// default glob include pattern for msbuild sdk style projects // default glob include pattern for sdk style projects
if (this._isMsbuildSdkStyleProject) { if (this._isSdkStyleProject) {
try { try {
const globFiles = await utils.getSqlFilesInFolder(this.projectFolderPath, true); const globFiles = await utils.getSqlFilesInFolder(this.projectFolderPath, true);
globFiles.forEach(f => { globFiles.forEach(f => {
@@ -183,8 +183,8 @@ export class Project implements ISqlProject {
if (relativePath) { if (relativePath) {
const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath)); const fullPath = path.join(utils.getPlatformSafeFileEntryPath(this.projectFolderPath), utils.getPlatformSafeFileEntryPath(relativePath));
// msbuild sdk style projects can handle other globbing patterns like <Build Include="folder1\*.sql" /> and <Build Include="Production*.sql" /> // sdk style projects can handle other globbing patterns like <Build Include="folder1\*.sql" /> and <Build Include="Production*.sql" />
if (this._isMsbuildSdkStyleProject && !(await utils.exists(fullPath))) { if (this._isSdkStyleProject && !(await utils.exists(fullPath))) {
// add files from the glob pattern // add files from the glob pattern
const globFiles = await utils.globWithPattern(fullPath); const globFiles = await utils.globWithPattern(fullPath);
globFiles.forEach(gf => { globFiles.forEach(gf => {
@@ -205,7 +205,7 @@ export class Project implements ISqlProject {
// <Build Remove....> // <Build Remove....>
// after all the files have been included, remove the ones specified in the sqlproj to remove // after all the files have been included, remove the ones specified in the sqlproj to remove
if (this._isMsbuildSdkStyleProject) { if (this._isSdkStyleProject) {
for (let b = 0; b < buildElements.length; b++) { for (let b = 0; b < buildElements.length; b++) {
const relativePath = buildElements[b].getAttribute(constants.Remove)!; const relativePath = buildElements[b].getAttribute(constants.Remove)!;
@@ -238,8 +238,8 @@ export class Project implements ISqlProject {
private async readFolders(): Promise<FileProjectEntry[]> { private async readFolders(): Promise<FileProjectEntry[]> {
const folderEntries: FileProjectEntry[] = []; const folderEntries: FileProjectEntry[] = [];
// glob style getting folders for new msbuild sdk style projects // glob style getting folders for sdk style projects
if (this._isMsbuildSdkStyleProject) { if (this._isSdkStyleProject) {
const folders = await utils.getFoldersInFolder(this.projectFolderPath, true); const folders = await utils.getFoldersInFolder(this.projectFolderPath, true);
folders.forEach(f => { folders.forEach(f => {
folderEntries.push(this.createFileProjectEntry(utils.trimUri(Uri.file(this.projectFilePath), Uri.file(f)), EntryType.Folder)); folderEntries.push(this.createFileProjectEntry(utils.trimUri(Uri.file(this.projectFilePath), Uri.file(f)), EntryType.Folder));
@@ -448,27 +448,27 @@ export class Project implements ISqlProject {
} }
/** /**
* Checks for the 3 possible ways a project can reference the sql msbuild sdk * Checks for the 3 possible ways a project can reference the sql project sdk
* https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019 * https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2019
* @returns true if the project is an msbuild sdk style project, false if it isn't * @returns true if the project is an sdk style project, false if it isn't
*/ */
public CheckForMsbuildSdkStyleProject(): boolean { public CheckForSdkStyleProject(): boolean {
// type 1: Sdk node like <Sdk Name="Microsoft.Build.Sql" Version="1.0.0" /> // type 1: Sdk node like <Sdk Name="Microsoft.Build.Sql" Version="1.0.0" />
const sdkNodes = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.Sdk); const sdkNodes = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.Sdk);
if (sdkNodes.length > 0) { if (sdkNodes.length > 0) {
return sdkNodes[0].getAttribute(constants.Name) === constants.sqlMsbuildSdk; return sdkNodes[0].getAttribute(constants.Name) === constants.sqlProjectSdk;
} }
// type 2: Project node has Sdk attribute like <Project Sdk="Microsoft.Build.Sql/1.0.0"> // type 2: Project node has Sdk attribute like <Project Sdk="Microsoft.Build.Sql/1.0.0">
const sdkAttribute: string = this.projFileXmlDoc!.documentElement.getAttribute(constants.Sdk)!; const sdkAttribute: string = this.projFileXmlDoc!.documentElement.getAttribute(constants.Sdk)!;
if (sdkAttribute) { if (sdkAttribute) {
return sdkAttribute.includes(constants.sqlMsbuildSdk); return sdkAttribute.includes(constants.sqlProjectSdk);
} }
// type 3: Import node with Sdk attribute like <Import Project="Sdk.targets" Sdk="Microsoft.Build.Sql" Version="1.0.0" /> // type 3: Import node with Sdk attribute like <Import Project="Sdk.targets" Sdk="Microsoft.Build.Sql" Version="1.0.0" />
const importNodes = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.Import); const importNodes = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.Import);
for (let i = 0; i < importNodes.length; i++) { for (let i = 0; i < importNodes.length; i++) {
if (importNodes[i].getAttribute(constants.Sdk) === constants.sqlMsbuildSdk) { if (importNodes[i].getAttribute(constants.Sdk) === constants.sqlProjectSdk) {
return true; return true;
} }
} }
@@ -478,7 +478,7 @@ export class Project implements ISqlProject {
public async updateProjectForRoundTrip(): Promise<void> { public async updateProjectForRoundTrip(): Promise<void> {
if (this._importedTargets.includes(constants.NetCoreTargets) && !this.containsSSDTOnlySystemDatabaseReferences() // old style project check if (this._importedTargets.includes(constants.NetCoreTargets) && !this.containsSSDTOnlySystemDatabaseReferences() // old style project check
|| this.isMsbuildSdkStyleProject) { // new style project check || this.isSdkStyleProject) { // new style project check
return; return;
} }
@@ -1359,8 +1359,8 @@ export class Project implements ISqlProject {
// If folder doesn't exist, create it // If folder doesn't exist, create it
await fs.mkdir(absoluteFolderPath, { recursive: true }); await fs.mkdir(absoluteFolderPath, { recursive: true });
// don't need to add the folder to the sqlproj if this is an msbuild sdk style project because globbing will get the folders // don't need to add the folder to the sqlproj if this is an sdk style project because globbing will get the folders
if (this.isMsbuildSdkStyleProject) { if (this.isSdkStyleProject) {
return this.createFileProjectEntry(relativeFolderPath, EntryType.Folder); return this.createFileProjectEntry(relativeFolderPath, EntryType.Folder);
} }

View File

@@ -27,13 +27,13 @@ export let sqlProjectMissingVersionBaseline: string;
export let sqlProjectInvalidVersionBaseline: string; export let sqlProjectInvalidVersionBaseline: string;
export let sqlProjectCustomCollationBaseline: string; export let sqlProjectCustomCollationBaseline: string;
export let sqlProjectInvalidCollationBaseline: string; export let sqlProjectInvalidCollationBaseline: string;
export let newStyleProjectSdkNodeBaseline: string; export let newSdkStyleProjectSdkNodeBaseline: string;
export let newStyleProjectSdkProjectAttributeBaseline: string; export let newSdkStyleProjectSdkProjectAttributeBaseline: string;
export let newStyleProjectSdkImportAttributeBaseline: string; export let newStyleProjectSdkImportAttributeBaseline: string;
export let openNewStyleSqlProjectBaseline: string; export let openSdkStyleSqlProjectBaseline: string;
export let openNewStyleSqlProjectWithFilesSpecifiedBaseline: string; export let openSdkStyleSqlProjectWithFilesSpecifiedBaseline: string;
export let openNewStyleSqlProjectWithGlobsSpecifiedBaseline: string; export let openSdkStyleSqlProjectWithGlobsSpecifiedBaseline: string;
export let openNewStyleSqlProjectWithBuildRemoveBaseline: string; export let openSdkStyleSqlProjectWithBuildRemoveBaseline: string;
const baselineFolderPath = __dirname; const baselineFolderPath = __dirname;
@@ -58,13 +58,13 @@ export async function loadBaselines() {
sqlProjectInvalidVersionBaseline = await loadBaseline(baselineFolderPath, 'sqlProjectInvalidVersionBaseline.xml'); sqlProjectInvalidVersionBaseline = await loadBaseline(baselineFolderPath, 'sqlProjectInvalidVersionBaseline.xml');
sqlProjectCustomCollationBaseline = await loadBaseline(baselineFolderPath, 'sqlProjectCustomCollationBaseline.xml'); sqlProjectCustomCollationBaseline = await loadBaseline(baselineFolderPath, 'sqlProjectCustomCollationBaseline.xml');
sqlProjectInvalidCollationBaseline = await loadBaseline(baselineFolderPath, 'sqlProjectInvalidCollationBaseline.xml'); sqlProjectInvalidCollationBaseline = await loadBaseline(baselineFolderPath, 'sqlProjectInvalidCollationBaseline.xml');
newStyleProjectSdkNodeBaseline = await loadBaseline(baselineFolderPath, 'newStyleSqlProjectSdkNodeBaseline.xml'); newSdkStyleProjectSdkNodeBaseline = await loadBaseline(baselineFolderPath, 'newSdkStyleSqlProjectSdkNodeBaseline.xml');
newStyleProjectSdkProjectAttributeBaseline = await loadBaseline(baselineFolderPath, 'newStyleSqlProjectSdkProjectAttributeBaseline.xml'); newSdkStyleProjectSdkProjectAttributeBaseline = await loadBaseline(baselineFolderPath, 'newSdkStyleSqlProjectSdkProjectAttributeBaseline.xml');
newStyleProjectSdkImportAttributeBaseline = await loadBaseline(baselineFolderPath, 'newStyleSqlProjectSdkImportAttributeBaseline.xml'); newStyleProjectSdkImportAttributeBaseline = await loadBaseline(baselineFolderPath, 'newSdkStyleSqlProjectSdkImportAttributeBaseline.xml');
openNewStyleSqlProjectBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectBaseline.xml'); openSdkStyleSqlProjectBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectBaseline.xml');
openNewStyleSqlProjectWithFilesSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithFilesSpecifiedBaseline.xml'); openSdkStyleSqlProjectWithFilesSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithFilesSpecifiedBaseline.xml');
openNewStyleSqlProjectWithGlobsSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithGlobsSpecifiedBaseline.xml'); openSdkStyleSqlProjectWithGlobsSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithGlobsSpecifiedBaseline.xml');
openNewStyleSqlProjectWithBuildRemoveBaseline = await loadBaseline(baselineFolderPath, 'openNewStyleSqlProjectWithBuildRemoveBaseline.xml'); openSdkStyleSqlProjectWithBuildRemoveBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithBuildRemoveBaseline.xml');
} }
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> { async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {

View File

@@ -828,7 +828,7 @@ describe('Project: sqlproj content operations', function (): void {
}); });
}); });
describe('Project: Msbuild sdk style project content operations', function (): void { describe('Project: sdk style project content operations', function (): void {
before(async function (): Promise<void> { before(async function (): Promise<void> {
await baselines.loadBaselines(); await baselines.loadBaselines();
}); });
@@ -838,7 +838,7 @@ describe('Project: Msbuild sdk style project content operations', function (): v
}); });
it('Should read project from sqlproj and files and folders by globbing', async function (): Promise<void> { it('Should read project from sqlproj and files and folders by globbing', async function (): Promise<void> {
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectBaseline); projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectBaseline);
await testUtils.createDummyFileStructureWithPrePostDeployScripts(false, undefined, path.dirname(projFilePath)); await testUtils.createDummyFileStructureWithPrePostDeployScripts(false, undefined, path.dirname(projFilePath));
const project: Project = await Project.openProject(projFilePath); const project: Project = await Project.openProject(projFilePath);
@@ -868,7 +868,7 @@ describe('Project: Msbuild sdk style project content operations', function (): v
}); });
it('Should handle files listed in sqlproj', async function (): Promise<void> { it('Should handle files listed in sqlproj', async function (): Promise<void> {
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectWithFilesSpecifiedBaseline); projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectWithFilesSpecifiedBaseline);
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath)); await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
const project: Project = await Project.openProject(projFilePath); const project: Project = await Project.openProject(projFilePath);
@@ -887,7 +887,7 @@ describe('Project: Msbuild sdk style project content operations', function (): v
const testFolderPath = await testUtils.generateTestFolderPath(); const testFolderPath = await testUtils.generateTestFolderPath();
const mainProjectPath = path.join(testFolderPath, 'project'); const mainProjectPath = path.join(testFolderPath, 'project');
const otherFolderPath = path.join(testFolderPath, 'other'); const otherFolderPath = path.join(testFolderPath, 'other');
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectWithGlobsSpecifiedBaseline, mainProjectPath); projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectWithGlobsSpecifiedBaseline, mainProjectPath);
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath)); await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
// create files outside of project folder that are included in the project file // create files outside of project folder that are included in the project file
@@ -920,7 +920,7 @@ describe('Project: Msbuild sdk style project content operations', function (): v
const testFolderPath = await testUtils.generateTestFolderPath(); const testFolderPath = await testUtils.generateTestFolderPath();
const mainProjectPath = path.join(testFolderPath, 'project'); const mainProjectPath = path.join(testFolderPath, 'project');
const otherFolderPath = path.join(testFolderPath, 'other'); const otherFolderPath = path.join(testFolderPath, 'other');
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectWithBuildRemoveBaseline, mainProjectPath); projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectWithBuildRemoveBaseline, mainProjectPath);
await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath)); await testUtils.createDummyFileStructure(false, undefined, path.dirname(projFilePath));
// create files outside of project folder that are included in the project file // create files outside of project folder that are included in the project file
@@ -949,7 +949,7 @@ describe('Project: Msbuild sdk style project content operations', function (): v
}); });
it('Should only add Build entries to sqlproj for files not included by project folder glob and external streaming jobs', async function (): Promise<void> { it('Should only add Build entries to sqlproj for files not included by project folder glob and external streaming jobs', async function (): Promise<void> {
projFilePath = await testUtils.createTestSqlProjFile(baselines.openNewStyleSqlProjectBaseline); projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectBaseline);
const project = await Project.openProject(projFilePath); const project = await Project.openProject(projFilePath);
const folderPath = 'Stored Procedures'; const folderPath = 'Stored Procedures';
@@ -1110,15 +1110,15 @@ describe('Project: round trip updates', function (): void {
should(project.importedTargets.length).equal(3); // additional target should exist by default should(project.importedTargets.length).equal(3); // additional target should exist by default
}); });
it('Should not show update project warning message when opening msbuild sdk style project using Sdk node', async function (): Promise<void> { it('Should not show update project warning message when opening sdk style project using Sdk node', async function (): Promise<void> {
await shouldNotShowUpdateWarning(baselines.newStyleProjectSdkNodeBaseline); await shouldNotShowUpdateWarning(baselines.newSdkStyleProjectSdkNodeBaseline);
}); });
it('Should not show update project warning message when opening msbuild sdk style project using Project node with Sdk attribute', async function (): Promise<void> { it('Should not show update project warning message when opening sdk style project using Project node with Sdk attribute', async function (): Promise<void> {
await shouldNotShowUpdateWarning(baselines.newStyleProjectSdkProjectAttributeBaseline); await shouldNotShowUpdateWarning(baselines.newSdkStyleProjectSdkProjectAttributeBaseline);
}); });
it('Should not show update project warning message when opening msbuild sdk style project using Import node with Sdk attribute', async function (): Promise<void> { it('Should not show update project warning message when opening sdk style project using Import node with Sdk attribute', async function (): Promise<void> {
await shouldNotShowUpdateWarning(baselines.newStyleProjectSdkImportAttributeBaseline); await shouldNotShowUpdateWarning(baselines.newStyleProjectSdkImportAttributeBaseline);
}); });
@@ -1130,7 +1130,7 @@ describe('Project: round trip updates', function (): void {
const project = await Project.openProject(Uri.file(sqlProjPath).fsPath); const project = await Project.openProject(Uri.file(sqlProjPath).fsPath);
should(spy.notCalled).be.true(); should(spy.notCalled).be.true();
should(project.isMsbuildSdkStyleProject).be.true(); should(project.isSdkStyleProject).be.true();
} }
}); });