remove default VS properties when converting legacy to SDK-style sql project (#19255)

This commit is contained in:
Kim Santiago
2022-05-04 12:00:38 -07:00
committed by GitHub
parent 4d8fdf5833
commit d122e7636c
3 changed files with 49 additions and 2 deletions

View File

@@ -661,8 +661,42 @@ export class Project implements ISqlProject {
}
}
const parent = importsToRemove[0]?.parentNode;
importsToRemove.forEach(i => { parent?.removeChild(i); });
const importsParent = importsToRemove[0]?.parentNode;
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
const sdkNode = this.projFileXmlDoc!.createElement(constants.Sdk);