mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
add a project guid if a sql project doesn't have one (#18009)
This commit is contained in:
@@ -376,6 +376,7 @@ export const True = 'True';
|
|||||||
export const False = 'False';
|
export const False = 'False';
|
||||||
export const Private = 'Private';
|
export const Private = 'Private';
|
||||||
export const ProjectGuid = 'ProjectGuid';
|
export const ProjectGuid = 'ProjectGuid';
|
||||||
|
export const PropertyGroup = 'PropertyGroup';
|
||||||
export const Type = 'Type';
|
export const Type = 'Type';
|
||||||
export const ExternalStreamingJob: string = 'ExternalStreamingJob';
|
export const ExternalStreamingJob: string = 'ExternalStreamingJob';
|
||||||
export const Sdk: string = 'Sdk';
|
export const Sdk: string = 'Sdk';
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import * as utils from '../common/utils';
|
|||||||
import * as xmlFormat from 'xml-formatter';
|
import * as xmlFormat from 'xml-formatter';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as templates from '../templates/templates';
|
import * as templates from '../templates/templates';
|
||||||
|
import * as UUID from 'vscode-languageclient/lib/utils/uuid';
|
||||||
|
|
||||||
import { Uri, window } from 'vscode';
|
import { Uri, window } from 'vscode';
|
||||||
import { ISqlProject, SqlTargetPlatform } from 'sqldbproj';
|
import { ISqlProject, SqlTargetPlatform } from 'sqldbproj';
|
||||||
@@ -146,8 +147,13 @@ export class Project implements ISqlProject {
|
|||||||
try {
|
try {
|
||||||
this._projectGuid = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.ProjectGuid)[0].childNodes[0].nodeValue!;
|
this._projectGuid = this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.ProjectGuid)[0].childNodes[0].nodeValue!;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
void window.showErrorMessage(constants.errorReadingProject(constants.ProjectGuid, this.projectFilePath));
|
// if no project guid, add a new one
|
||||||
console.error(utils.getErrorMessage(e));
|
this._projectGuid = UUID.generateUuid();
|
||||||
|
const newProjectGuidNode = this.projFileXmlDoc!.createElement(constants.ProjectGuid);
|
||||||
|
const newProjectGuidTextNode = this.projFileXmlDoc!.createTextNode(`{${this._projectGuid}}`);
|
||||||
|
newProjectGuidNode.appendChild(newProjectGuidTextNode);
|
||||||
|
this.projFileXmlDoc!.documentElement.getElementsByTagName(constants.PropertyGroup)[0]?.appendChild(newProjectGuidNode);
|
||||||
|
await this.serializeToProjFile(this.projFileXmlDoc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export let openSdkStyleSqlProjectBaseline: string;
|
|||||||
export let openSdkStyleSqlProjectWithFilesSpecifiedBaseline: string;
|
export let openSdkStyleSqlProjectWithFilesSpecifiedBaseline: string;
|
||||||
export let openSdkStyleSqlProjectWithGlobsSpecifiedBaseline: string;
|
export let openSdkStyleSqlProjectWithGlobsSpecifiedBaseline: string;
|
||||||
export let openSdkStyleSqlProjectWithBuildRemoveBaseline: string;
|
export let openSdkStyleSqlProjectWithBuildRemoveBaseline: string;
|
||||||
|
export let openSdkStyleSqlProjectNoProjectGuidBaseline: string;
|
||||||
|
|
||||||
const baselineFolderPath = __dirname;
|
const baselineFolderPath = __dirname;
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ export async function loadBaselines() {
|
|||||||
openSdkStyleSqlProjectWithFilesSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithFilesSpecifiedBaseline.xml');
|
openSdkStyleSqlProjectWithFilesSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithFilesSpecifiedBaseline.xml');
|
||||||
openSdkStyleSqlProjectWithGlobsSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithGlobsSpecifiedBaseline.xml');
|
openSdkStyleSqlProjectWithGlobsSpecifiedBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithGlobsSpecifiedBaseline.xml');
|
||||||
openSdkStyleSqlProjectWithBuildRemoveBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithBuildRemoveBaseline.xml');
|
openSdkStyleSqlProjectWithBuildRemoveBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectWithBuildRemoveBaseline.xml');
|
||||||
|
openSdkStyleSqlProjectNoProjectGuidBaseline = await loadBaseline(baselineFolderPath, 'openSdkStyleSqlProjectNoProjectGuidBaseline.xml');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {
|
async function loadBaseline(baselineFolderPath: string, fileName: string): Promise<string> {
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build">
|
||||||
|
<Sdk Name="Microsoft.Build.Sql" Version="1.0.0" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Name>TestProjectName</Name>
|
||||||
|
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql150DatabaseSchemaProvider</DSP>
|
||||||
|
<ModelCollation>1033, CI</ModelCollation>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Target Name="BeforeBuild">
|
||||||
|
<Delete Files="$(BaseIntermediateOutputPath)\project.assets.json" />
|
||||||
|
</Target>
|
||||||
|
<ItemGroup>
|
||||||
|
<SqlCmdVariable Include="ProdDatabaseName">
|
||||||
|
<DefaultValue>MyProdDatabase</DefaultValue>
|
||||||
|
<Value>$(SqlCmdVar__1)</Value>
|
||||||
|
</SqlCmdVariable>
|
||||||
|
<SqlCmdVariable Include="BackupDatabaseName">
|
||||||
|
<DefaultValue>MyBackupDatabase</DefaultValue>
|
||||||
|
<Value>$(SqlCmdVar__2)</Value>
|
||||||
|
</SqlCmdVariable>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PreDeploy Include="Script.PreDeployment1.sql" />
|
||||||
|
<None Include="Script.PreDeployment2.sql" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
@@ -1097,7 +1097,6 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
should(projFileText.includes('<Build Remove="folder1\\nestedFolder\\**" />')).equal(false, projFileText);
|
should(projFileText.includes('<Build Remove="folder1\\nestedFolder\\**" />')).equal(false, projFileText);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('Should handle excluding nested glob included folders', async function (): Promise<void> {
|
it('Should handle excluding nested glob included folders', async function (): Promise<void> {
|
||||||
const testFolderPath = await testUtils.generateTestFolderPath();
|
const testFolderPath = await testUtils.generateTestFolderPath();
|
||||||
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectBaseline, testFolderPath);
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectBaseline, testFolderPath);
|
||||||
@@ -1344,6 +1343,21 @@ describe('Project: sdk style project content operations', function (): void {
|
|||||||
should(projFileText.includes('<Build Remove="folder1\\**" />')).equal(false, projFileText);
|
should(projFileText.includes('<Build Remove="folder1\\**" />')).equal(false, projFileText);
|
||||||
should(projFileText.includes('<Build Remove="folder2\\**" />')).equal(false, projFileText);
|
should(projFileText.includes('<Build Remove="folder2\\**" />')).equal(false, projFileText);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should add a project guid if there is not one in the sqlproj', async function (): Promise<void> {
|
||||||
|
projFilePath = await testUtils.createTestSqlProjFile(baselines.openSdkStyleSqlProjectNoProjectGuidBaseline);
|
||||||
|
let projFileText = (await fs.readFile(projFilePath)).toString();
|
||||||
|
|
||||||
|
// verify no project guid
|
||||||
|
should(projFileText.includes(constants.ProjectGuid)).equal(false);
|
||||||
|
|
||||||
|
const project: Project = await Project.openProject(projFilePath);
|
||||||
|
|
||||||
|
// verify project guid was added
|
||||||
|
projFileText = (await fs.readFile(projFilePath)).toString();
|
||||||
|
should(project.projectGuid).not.equal(undefined);
|
||||||
|
should(projFileText.includes(constants.ProjectGuid)).equal(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Project: add SQLCMD Variables', function (): void {
|
describe('Project: add SQLCMD Variables', function (): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user