mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
remove default VS properties when converting legacy to SDK-style sql project (#19255)
This commit is contained in:
@@ -437,6 +437,8 @@ export const Type = 'Type';
|
|||||||
export const ExternalStreamingJob: string = 'ExternalStreamingJob';
|
export const ExternalStreamingJob: string = 'ExternalStreamingJob';
|
||||||
export const Sdk: string = 'Sdk';
|
export const Sdk: string = 'Sdk';
|
||||||
export const DatabaseSource = 'DatabaseSource';
|
export const DatabaseSource = 'DatabaseSource';
|
||||||
|
export const VisualStudioVersion = 'VisualStudioVersion';
|
||||||
|
export const SSDTExists = 'SSDTExists';
|
||||||
|
|
||||||
export const BuildElements = localize('buildElements', "Build Elements");
|
export const BuildElements = localize('buildElements', "Build Elements");
|
||||||
export const FolderElements = localize('folderElements', "Folder Elements");
|
export const FolderElements = localize('folderElements', "Folder Elements");
|
||||||
@@ -475,6 +477,11 @@ export const RoundTripSqlDbNotPresentCondition = '\'$(NetCoreBuild)\' != \'true\
|
|||||||
export const DacpacRootPath = '$(DacPacRootPath)';
|
export const DacpacRootPath = '$(DacPacRootPath)';
|
||||||
export const ProjJsonToClean = '$(BaseIntermediateOutputPath)\\project.assets.json';
|
export const ProjJsonToClean = '$(BaseIntermediateOutputPath)\\project.assets.json';
|
||||||
|
|
||||||
|
// Sqlproj VS property conditions
|
||||||
|
export const VSVersionCondition = '\'$(VisualStudioVersion)\' == \'\'';
|
||||||
|
export const SsdtExistsCondition = '\'$(SSDTExists)\' == \'\'';
|
||||||
|
export const targetsExistsCondition = 'Exists(\'$(MSBuildExtensionsPath)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\SSDT\\Microsoft.Data.Tools.Schema.SqlTasks.targets\')';
|
||||||
|
|
||||||
// SqlProj Reference Assembly Information
|
// SqlProj Reference Assembly Information
|
||||||
export const NETFrameworkAssembly = 'Microsoft.NETFramework.ReferenceAssemblies';
|
export const NETFrameworkAssembly = 'Microsoft.NETFramework.ReferenceAssemblies';
|
||||||
export const VersionNumber = '1.0.0';
|
export const VersionNumber = '1.0.0';
|
||||||
|
|||||||
@@ -661,8 +661,42 @@ export class Project implements ISqlProject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const parent = importsToRemove[0]?.parentNode;
|
const importsParent = importsToRemove[0]?.parentNode;
|
||||||
importsToRemove.forEach(i => { parent?.removeChild(i); });
|
importsToRemove.forEach(i => {
|
||||||
|
importsParent?.removeChild(i);
|
||||||
|
});
|
||||||
|
|
||||||
|
// remove VisualStudio properties
|
||||||
|
const vsPropsToRemove = [];
|
||||||
|
for (let i = 0; i < this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.VisualStudioVersion).length; i++) {
|
||||||
|
const visualStudioVersionNode = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.VisualStudioVersion)[i];
|
||||||
|
const conditionAttributeVal = visualStudioVersionNode.getAttribute(constants.Condition);
|
||||||
|
|
||||||
|
if (conditionAttributeVal === constants.VSVersionCondition || conditionAttributeVal === constants.SsdtExistsCondition) {
|
||||||
|
vsPropsToRemove.push(visualStudioVersionNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.SSDTExists).length; i++) {
|
||||||
|
const ssdtExistsNode = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.SSDTExists)[i];
|
||||||
|
const conditionAttributeVal = ssdtExistsNode.getAttribute(constants.Condition);
|
||||||
|
|
||||||
|
if (conditionAttributeVal === constants.targetsExistsCondition) {
|
||||||
|
vsPropsToRemove.push(ssdtExistsNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const vsPropsParent = vsPropsToRemove[0]?.parentNode;
|
||||||
|
vsPropsToRemove.forEach(i => {
|
||||||
|
vsPropsParent?.removeChild(i);
|
||||||
|
|
||||||
|
// Remove the parent PropertyGroup if there aren't any other nodes. Only count element nodes, not text nodes
|
||||||
|
const otherChildren = Array.from(vsPropsParent!.childNodes).filter((c: ChildNode) => c.childNodes);
|
||||||
|
|
||||||
|
if (otherChildren.length === 0) {
|
||||||
|
vsPropsParent!.parentNode?.removeChild(vsPropsParent!);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// add SDK node
|
// add SDK node
|
||||||
const sdkNode = this.projFileXmlDoc!.createElement(constants.Sdk);
|
const sdkNode = this.projFileXmlDoc!.createElement(constants.Sdk);
|
||||||
|
|||||||
@@ -1784,6 +1784,9 @@ describe('Project: legacy to SDK-style updates', function (): void {
|
|||||||
let projFileText = (await fs.readFile(projFilePath)).toString();
|
let projFileText = (await fs.readFile(projFilePath)).toString();
|
||||||
should(projFileText.includes('<Build Include=')).equal(true, 'sqlproj should have Build Includes before converting');
|
should(projFileText.includes('<Build Include=')).equal(true, 'sqlproj should have Build Includes before converting');
|
||||||
should(projFileText.includes('<Folder Include=')).equal(true, 'sqlproj should have Folder Includes before converting');
|
should(projFileText.includes('<Folder Include=')).equal(true, 'sqlproj should have Folder Includes before converting');
|
||||||
|
should(projFileText.includes('<VisualStudioVersion Condition="\'$(VisualStudioVersion)\' == \'\'">')).equal(true, 'sqlproj should have VisualStudioVersion property with empty condition before converting');
|
||||||
|
should(projFileText.includes('<SSDTExists Condition="Exists(\'$(MSBuildExtensionsPath)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\SSDT\\Microsoft.Data.Tools.Schema.SqlTasks.targets\')">')).equal(true, 'sqlproj should have SSDTExists property before converting');
|
||||||
|
should(projFileText.includes('<VisualStudioVersion Condition="\'$(SSDTExists)\' == \'\'">')).equal(true, 'sqlproj should have VisualStudioVersion property with SSDTExists condition before converting');
|
||||||
|
|
||||||
await project.convertProjectToSdkStyle();
|
await project.convertProjectToSdkStyle();
|
||||||
|
|
||||||
@@ -1796,6 +1799,9 @@ describe('Project: legacy to SDK-style updates', function (): void {
|
|||||||
should(projFileText.includes('<Folder Include=')).equal(false, 'All Folder Includes should have been removed');
|
should(projFileText.includes('<Folder Include=')).equal(false, 'All Folder Includes should have been removed');
|
||||||
should(project.files.filter(f => f.type === EntryType.File).length).equal(beforeFileCount, 'Same number of files should be included after Build Includes are removed');
|
should(project.files.filter(f => f.type === EntryType.File).length).equal(beforeFileCount, 'Same number of files should be included after Build Includes are removed');
|
||||||
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(beforeFolderCount, 'Same number of folders should be included after Folder Includes are removed');
|
should(project.files.filter(f => f.type === EntryType.Folder).length).equal(beforeFolderCount, 'Same number of folders should be included after Folder Includes are removed');
|
||||||
|
should(projFileText.includes('<VisualStudioVersion Condition="\'$(VisualStudioVersion)\' == \'\'">')).equal(false, 'VisualStudioVersion property with empty condition should be removed');
|
||||||
|
should(projFileText.includes('<SSDTExists Condition="Exists(\'$(MSBuildExtensionsPath)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\SSDT\\Microsoft.Data.Tools.Schema.SqlTasks.targets\')">')).equal(false, 'SSDTExists property should be removed');
|
||||||
|
should(projFileText.includes('<VisualStudioVersion Condition="\'$(SSDTExists)\' == \'\'">')).equal(false, 'VisualStudioVersion property with SSDTExists condition should be removed');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should not fail if legacy style project does not have Properties folder in sqlproj', async function (): Promise<void> {
|
it('Should not fail if legacy style project does not have Properties folder in sqlproj', async function (): Promise<void> {
|
||||||
|
|||||||
Reference in New Issue
Block a user