From 9544a46d666dbf094554fad793c9b6c717c1fe7e Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 16 Jan 2019 14:39:15 -0800 Subject: [PATCH 1/7] Only delete temp file if exists. --- debugging/coreclr/netCoreProjectProvider.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/debugging/coreclr/netCoreProjectProvider.ts b/debugging/coreclr/netCoreProjectProvider.ts index 54d0547ae2..34e029e96e 100644 --- a/debugging/coreclr/netCoreProjectProvider.ts +++ b/debugging/coreclr/netCoreProjectProvider.ts @@ -56,7 +56,10 @@ export class MsBuildNetCoreProjectProvider implements NetCoreProjectProvider { } finally { await this.fsProvider.unlinkFile(getTargetPathProjectFile); - await this.fsProvider.unlinkFile(targetOutputFilename); + + if (await this.fsProvider.fileExists(targetOutputFilename)) { + await this.fsProvider.unlinkFile(targetOutputFilename); + } } } } From b31b11eef51dbaabbf841a736fef64cea15744db Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 16 Jan 2019 15:03:50 -0800 Subject: [PATCH 2/7] Add validation to app project/folder properties. --- .../dockerDebugConfigurationProvider.ts | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/debugging/coreclr/dockerDebugConfigurationProvider.ts b/debugging/coreclr/dockerDebugConfigurationProvider.ts index eafdc0c73e..3511ddd96f 100644 --- a/debugging/coreclr/dockerDebugConfigurationProvider.ts +++ b/debugging/coreclr/dockerDebugConfigurationProvider.ts @@ -92,12 +92,9 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi throw new Error('No workspace folder is associated with debugging.'); } - const appFolder = this.inferAppFolder(folder, debugConfiguration); - - const resolvedAppFolder = DockerDebugConfigurationProvider.resolveFolderPath(appFolder, folder); + const { appFolder, resolvedAppFolder } = await this.inferAppFolder(folder, debugConfiguration); const appProject = await this.inferAppProject(debugConfiguration, resolvedAppFolder); - const resolvedAppProject = DockerDebugConfigurationProvider.resolveFolderPath(appProject, folder); const appName = path.basename(resolvedAppProject, '.csproj'); @@ -188,18 +185,32 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi }; } - private inferAppFolder(folder: WorkspaceFolder, configuration: DockerDebugConfiguration): string { + private async inferAppFolder(folder: WorkspaceFolder, configuration: DockerDebugConfiguration): Promise<{ appFolder: string, resolvedAppFolder: string }> { + let appFolder; + if (configuration) { if (configuration.appFolder) { - return configuration.appFolder; + appFolder = configuration.appFolder; } - - if (configuration.appProject) { - return path.dirname(configuration.appProject); + else if (configuration.appProject) { + appFolder = path.dirname(configuration.appProject); } } - return folder.uri.fsPath; + if (appFolder === undefined) { + appFolder = folder.uri.fsPath; + } + + var folders = { + appFolder, + resolvedAppFolder: DockerDebugConfigurationProvider.resolveFolderPath(appFolder, folder) + }; + + if (!await this.fsProvider.dirExists(folders.resolvedAppFolder)) { + throw new Error(`The application folder '${folders.resolvedAppFolder}' does not exist. Ensure that the 'appProject' or 'appFolder' properties are set correctly in the debug configuration.`); + } + + return folders; } private async inferAppOutput(configuration: DockerDebugConfiguration, targetOS: PlatformOS, resolvedAppProject: string): Promise { From 92b76064f8e9f57af195bac500a8a5881fce5532 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 16 Jan 2019 15:17:01 -0800 Subject: [PATCH 3/7] Validate appProject configuration property. --- .../dockerDebugConfigurationProvider.ts | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/debugging/coreclr/dockerDebugConfigurationProvider.ts b/debugging/coreclr/dockerDebugConfigurationProvider.ts index 3511ddd96f..97900c157b 100644 --- a/debugging/coreclr/dockerDebugConfigurationProvider.ts +++ b/debugging/coreclr/dockerDebugConfigurationProvider.ts @@ -94,8 +94,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi const { appFolder, resolvedAppFolder } = await this.inferAppFolder(folder, debugConfiguration); - const appProject = await this.inferAppProject(debugConfiguration, resolvedAppFolder); - const resolvedAppProject = DockerDebugConfigurationProvider.resolveFolderPath(appProject, folder); + const { appProject, resolvedAppProject } = await this.inferAppProject(folder, debugConfiguration, resolvedAppFolder); const appName = path.basename(resolvedAppProject, '.csproj'); @@ -207,7 +206,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi }; if (!await this.fsProvider.dirExists(folders.resolvedAppFolder)) { - throw new Error(`The application folder '${folders.resolvedAppFolder}' does not exist. Ensure that the 'appProject' or 'appFolder' properties are set correctly in the debug configuration.`); + throw new Error(`The application folder '${folders.resolvedAppFolder}' does not exist. Ensure that the 'appFolder' or 'appProject' property is set correctly in the Docker debug configuration.`); } return folders; @@ -224,22 +223,37 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi return relativeTargetPath; } - private async inferAppProject(configuration: DockerDebugConfiguration, resolvedAppFolder: string): Promise { - if (configuration) { - if (configuration.appProject) { - return configuration.appProject; + private async inferAppProject(folder: WorkspaceFolder, configuration: DockerDebugConfiguration, resolvedAppFolder: string): Promise<{ appProject: string, resolvedAppProject: string }> { + let appProject; + + if (configuration && configuration.appProject) { + appProject = configuration.appProject; + } + + if (appProject === undefined) { + const files = await this.fsProvider.readDir(resolvedAppFolder); + + const projectFile = files.find(file => path.extname(file) === '.csproj'); + + if (projectFile) { + appProject = path.join(resolvedAppFolder, projectFile); } } - const files = await this.fsProvider.readDir(resolvedAppFolder); + if (appProject === undefined) { + throw new Error('Unable to infer the application project file. Set either the \'appFolder\' or \'appProject\' property in the Docker debug configuration.'); + } - const projectFile = files.find(file => path.extname(file) === '.csproj'); + var projects = { + appProject, + resolvedAppProject: DockerDebugConfigurationProvider.resolveFolderPath(appProject, folder) + }; - if (projectFile) { - return path.join(resolvedAppFolder, projectFile); + if (!await this.fsProvider.fileExists(projects.resolvedAppProject)) { + throw new Error(`The application project file '${projects.resolvedAppProject}' does not exist. Ensure that the 'appFolder' or 'appProject' property is set correctly in the Docker debug configuration.`); } - throw new Error('Unable to infer the application project file. Set either the `appFolder` or `appProject` property in the Docker debug configuration.'); + return projects; } private static inferContext(folder: WorkspaceFolder, resolvedAppFolder: string, configuration: DockerDebugConfiguration): string { From 840aadf63cc3a682aa1c4cfa964c1fab7ab0dd01 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 16 Jan 2019 15:27:05 -0800 Subject: [PATCH 4/7] Validate context property. --- .../dockerDebugConfigurationProvider.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/debugging/coreclr/dockerDebugConfigurationProvider.ts b/debugging/coreclr/dockerDebugConfigurationProvider.ts index 97900c157b..d5e6f3c523 100644 --- a/debugging/coreclr/dockerDebugConfigurationProvider.ts +++ b/debugging/coreclr/dockerDebugConfigurationProvider.ts @@ -104,7 +104,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi const appOutput = await this.inferAppOutput(debugConfiguration, os, resolvedAppProject); - const buildOptions = DockerDebugConfigurationProvider.inferBuildOptions(folder, debugConfiguration, appFolder, resolvedAppFolder, appName); + const buildOptions = await this.inferBuildOptions(folder, debugConfiguration, appFolder, resolvedAppFolder, appName); const runOptions = DockerDebugConfigurationProvider.inferRunOptions(folder, debugConfiguration, appName, os); const launchOptions = { @@ -129,9 +129,8 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi return configuration; } - private static inferBuildOptions(folder: WorkspaceFolder, debugConfiguration: DockerDebugConfiguration, appFolder: string, resolvedAppFolder: string, appName: string): LaunchBuildOptions { - const context = DockerDebugConfigurationProvider.inferContext(folder, resolvedAppFolder, debugConfiguration); - const resolvedContext = DockerDebugConfigurationProvider.resolveFolderPath(context, folder); + private async inferBuildOptions(folder: WorkspaceFolder, debugConfiguration: DockerDebugConfiguration, appFolder: string, resolvedAppFolder: string, appName: string): Promise { + const resolvedContext = await this.inferContext(folder, resolvedAppFolder, debugConfiguration); let dockerfile = debugConfiguration && debugConfiguration.dockerBuild && debugConfiguration.dockerBuild.dockerfile ? DockerDebugConfigurationProvider.resolveFolderPath(debugConfiguration.dockerBuild.dockerfile, folder) @@ -256,12 +255,20 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi return projects; } - private static inferContext(folder: WorkspaceFolder, resolvedAppFolder: string, configuration: DockerDebugConfiguration): string { - return configuration && configuration.dockerBuild && configuration.dockerBuild.context + private async inferContext(folder: WorkspaceFolder, resolvedAppFolder: string, configuration: DockerDebugConfiguration): Promise { + const context = configuration && configuration.dockerBuild && configuration.dockerBuild.context ? configuration.dockerBuild.context : path.normalize(resolvedAppFolder) === path.normalize(folder.uri.fsPath) ? resolvedAppFolder // The context defaults to the application folder if it's the same as the workspace folder (i.e. there's no solution folder). : path.dirname(resolvedAppFolder); // The context defaults to the application's parent (i.e. solution) folder. + + const resolvedContext = DockerDebugConfigurationProvider.resolveFolderPath(context, folder); + + if (!await this.fsProvider.dirExists(resolvedContext)) { + throw new Error(`The context folder '${resolvedContext}' does not exist. Ensure that the 'context' property is set correctly in the Docker debug configuration.`); + } + + return resolvedContext; } private createLaunchBrowserConfiguration(result: LaunchResult): DebugConfigurationBrowserOptions { From 9b1b006375db8466da86635f29867d2258cc5705 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 16 Jan 2019 15:43:16 -0800 Subject: [PATCH 5/7] Add validation for dockerfile property. --- .../dockerDebugConfigurationProvider.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/debugging/coreclr/dockerDebugConfigurationProvider.ts b/debugging/coreclr/dockerDebugConfigurationProvider.ts index d5e6f3c523..99fb31bd66 100644 --- a/debugging/coreclr/dockerDebugConfigurationProvider.ts +++ b/debugging/coreclr/dockerDebugConfigurationProvider.ts @@ -132,11 +132,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi private async inferBuildOptions(folder: WorkspaceFolder, debugConfiguration: DockerDebugConfiguration, appFolder: string, resolvedAppFolder: string, appName: string): Promise { const resolvedContext = await this.inferContext(folder, resolvedAppFolder, debugConfiguration); - let dockerfile = debugConfiguration && debugConfiguration.dockerBuild && debugConfiguration.dockerBuild.dockerfile - ? DockerDebugConfigurationProvider.resolveFolderPath(debugConfiguration.dockerBuild.dockerfile, folder) - : path.join(appFolder, 'Dockerfile'); // CONSIDER: Omit dockerfile argument if not specified or possibly infer from context. - - dockerfile = DockerDebugConfigurationProvider.resolveFolderPath(dockerfile, folder); + const dockerfile = await this.inferDockerfile(folder, resolvedAppFolder, debugConfiguration); const args = debugConfiguration && debugConfiguration.dockerBuild && debugConfiguration.dockerBuild.args; @@ -271,6 +267,20 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi return resolvedContext; } + private async inferDockerfile(folder: WorkspaceFolder, resolvedAppFolder: string, configuration: DockerDebugConfiguration): Promise { + let dockerfile = configuration && configuration.dockerBuild && configuration.dockerBuild.dockerfile + ? configuration.dockerBuild.dockerfile + : path.join(resolvedAppFolder, 'Dockerfile'); // CONSIDER: Omit dockerfile argument if not specified or possibly infer from context. + + dockerfile = DockerDebugConfigurationProvider.resolveFolderPath(dockerfile, folder); + + if (!await this.fsProvider.fileExists(dockerfile)) { + throw new Error(`The Dockerfile '${dockerfile}' does not exist. Ensure that the 'dockerfile' property is set correctly in the Docker debug configuration.`); + } + + return dockerfile; + } + private createLaunchBrowserConfiguration(result: LaunchResult): DebugConfigurationBrowserOptions { return result.browserUrl ? { From efd5d0c2a1d26591c173ead54ace0a3a8efd3996 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Wed, 16 Jan 2019 15:59:33 -0800 Subject: [PATCH 6/7] Resolve linter errors. --- debugging/coreclr/dockerDebugConfigurationProvider.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/debugging/coreclr/dockerDebugConfigurationProvider.ts b/debugging/coreclr/dockerDebugConfigurationProvider.ts index 99fb31bd66..0b8a2d119e 100644 --- a/debugging/coreclr/dockerDebugConfigurationProvider.ts +++ b/debugging/coreclr/dockerDebugConfigurationProvider.ts @@ -180,13 +180,12 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi } private async inferAppFolder(folder: WorkspaceFolder, configuration: DockerDebugConfiguration): Promise<{ appFolder: string, resolvedAppFolder: string }> { - let appFolder; + let appFolder: string; if (configuration) { if (configuration.appFolder) { appFolder = configuration.appFolder; - } - else if (configuration.appProject) { + } else if (configuration.appProject) { appFolder = path.dirname(configuration.appProject); } } @@ -195,7 +194,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi appFolder = folder.uri.fsPath; } - var folders = { + const folders = { appFolder, resolvedAppFolder: DockerDebugConfigurationProvider.resolveFolderPath(appFolder, folder) }; @@ -219,7 +218,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi } private async inferAppProject(folder: WorkspaceFolder, configuration: DockerDebugConfiguration, resolvedAppFolder: string): Promise<{ appProject: string, resolvedAppProject: string }> { - let appProject; + let appProject: string; if (configuration && configuration.appProject) { appProject = configuration.appProject; @@ -239,7 +238,7 @@ export class DockerDebugConfigurationProvider implements DebugConfigurationProvi throw new Error('Unable to infer the application project file. Set either the \'appFolder\' or \'appProject\' property in the Docker debug configuration.'); } - var projects = { + const projects = { appProject, resolvedAppProject: DockerDebugConfigurationProvider.resolveFolderPath(appProject, folder) }; From 32d850faadd3bade5aacbe6b6b44a2d716ba7993 Mon Sep 17 00:00:00 2001 From: Phillip Hoff Date: Thu, 14 Feb 2019 15:31:24 -0800 Subject: [PATCH 7/7] Retrigger build