From 3060d2ef1884abea6029b24af348267d4bb5dcc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sandstr=C3=B6m?= Date: Thu, 22 Feb 2018 10:52:00 +0100 Subject: [PATCH 1/2] Added support for diffrent ApplicationHost.Config files --- src/IISExpress.ts | 35 +++++++++++++++++++++++++++++++---- src/iisexpress-schema.json | 4 ++++ src/settings.ts | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/IISExpress.ts b/src/IISExpress.ts index 135d5d7e..e5869fcf 100644 --- a/src/IISExpress.ts +++ b/src/IISExpress.ts @@ -12,6 +12,7 @@ export interface IExpressArguments { port?: number; clr?: settings.clrVersion; protocol?: settings.protocolType; + config?: string; } // TODO: @@ -49,6 +50,9 @@ export class IIS { //Folder to run as the arg this._args.path = options.path ? options.path : vscode.workspace.rootPath; + //Path to ApplicationHost.Config + this._args.config = options.config ? options.config : ''; + //CLR version, yes there are still people on 3.5 & default back to v4 if not set this._args.clr = options.clr ? options.clr : settings.clrVersion.v40; @@ -77,7 +81,13 @@ export class IIS { //Add the site to the config (which will invoke/run from iisexpress cmd line) //Not done as async - so we wait until this command completes try { - process.execFileSync(this._iisAppCmdPath, ['add', 'site', `-name:${siteName}`, `-bindings:${this._args.protocol}://localhost:${this._args.port}`, `-physicalPath:${this._args.path}`]); + var siteArgs: string[] = ['add', 'site', `-name:${siteName}`, `-bindings:${this._args.protocol}://localhost:${this._args.port}`, `-physicalPath:${this._args.path}`]; + + if(this._args.config){ + siteArgs.push(`/apphostconfig:${this._args.config}`); + } + + process.execFileSync(this._iisAppCmdPath, siteArgs); } catch (error) { console.log(error); } @@ -88,7 +98,13 @@ export class IIS { //Assign the apppool to the site //appcmd set app /app.name:Site-Staging-201ec232-2906-4052-a431-727ec57b5b2e/ /applicationPool:Clr2IntegratedAppPool try { - process.execFileSync(this._iisAppCmdPath, ['set', 'app', `/app.name:${siteName}/`, `/applicationPool:${appPool}`]); + var appArgs: string[] = ['set', 'app', `/app.name:${siteName}/`, `/applicationPool:${appPool}`]; + + if(this._args.config){ + appArgs.push(`/apphostconfig:${this._args.config}`); + } + + process.execFileSync(this._iisAppCmdPath, appArgs); } catch (error) { console.log(error); } @@ -97,7 +113,13 @@ export class IIS { //This is the magic that runs the IISExpress cmd from the appcmd config list - this._iisProcess = process.spawn(this._iisPath, [`-site:${siteName}`]); + var iisArgs: string[] = [`-site:${siteName}`]; + + if(this._args.config){ + iisArgs.unshift(`/config:${this._args.config}`) + } + + this._iisProcess = process.spawn(this._iisPath, iisArgs); //Create Statusbar item & show it this._statusbar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); @@ -142,7 +164,12 @@ export class IIS { //Delete any existing entries for the site using appcmd //Not done as async - so we wait until this command completes try { - process.execFileSync(this._iisAppCmdPath, ['delete', 'site', `${siteName}`]); + var deleteSiteArgs: string[] = ['delete', 'site', `${siteName}`]; + if(this._args.config){ + deleteSiteArgs.push(`/apphostconfig:${this._args.config}`); + } + + process.execFileSync(this._iisAppCmdPath, deleteSiteArgs); } catch (error) { console.log(error); } diff --git a/src/iisexpress-schema.json b/src/iisexpress-schema.json index e2b73b59..ca53e363 100644 --- a/src/iisexpress-schema.json +++ b/src/iisexpress-schema.json @@ -18,6 +18,10 @@ "type": "string", "description": "This property is optional & allows you to set a path to the folder or subfolder as the root of your site/project for IIS Express to run" }, + "config": { + "type": "string", + "description": "This property is optional & allows you to set a path to the ApplicationHost.Config file you wish to run" + }, "url": { "type": "string", "description": "This property is optional & allows you to set the URL you wish to open eg: '/about/the-team'" diff --git a/src/settings.ts b/src/settings.ts index 5765cf0f..8202820a 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -4,6 +4,7 @@ import * as vscode from 'vscode'; export interface Isettings { port: number; path: string; + config?: string; url?: string; clr: clrVersion; protocol: protocolType; From 695d62208a1a89c93cd4337435554d6ceb4984df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sandstr=C3=B6m?= Date: Mon, 26 Feb 2018 10:29:44 +0100 Subject: [PATCH 2/2] Added support for using local applicationhost.config files located in .vscode folder. Config file specified in settings overrides local file in .vscode folder --- src/settings.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/settings.ts b/src/settings.ts index 8202820a..3dc49641 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -92,11 +92,45 @@ export function getSettings():Isettings{ settings = jsonfile.readFileSync(settingsFilePath); } + //Check if path to applicationhost.config file is defined in settings + if(!settings.config){ + //Checks if local applicationhost.config file exists + let localApplicatonHostConfig = getLocalApplicationHostConfig(); + + if(localApplicatonHostConfig){ + //File exists + //Add path to settings + settings.config = localApplicatonHostConfig; + } + } + //Return an object back from verifications return settings; } +function getLocalApplicationHostConfig(){ + let vscodeFilePath = vscode.workspace.rootPath + "\\.vscode\\applicationhost.config"; + let fileExists = false; + + try { + //Checks if local applicationhost.config file exists + fileExists = fs.existsSync(vscodeFilePath); + } + catch(err){ + //Error checking if file exists + //Maybe permissions or something else? + vscode.window.showErrorMessage('Unable to check if .vscode/applicationhost.config exists'); + } + + if(fileExists){ + //File exists + //Return path to local applicationhost.config file + return vscodeFilePath; + } + + return ""; +} //IIS Express docs recommend ports greater than 1024 //http://www.iis.net/learn/extensions/using-iis-express/running-iis-express-without-administrative-privileges