diff --git a/src/IISExpress.ts b/src/IISExpress.ts index e7005dd2..14641e0e 100644 --- a/src/IISExpress.ts +++ b/src/IISExpress.ts @@ -12,10 +12,11 @@ import TelemetryReporter from 'vscode-extension-telemetry'; export interface IExpressArguments { - path: string; + path: string; port: number; clr: settings.clrVersion; protocol: settings.protocolType; + config?: string; } export class IISExpress { @@ -65,11 +66,12 @@ export class IISExpress { clr: options.clr ? options.clr : settings.clrVersion.v40, // If no protocol set fallback to http as opposed to https - protocol: options.protocol ? options.protocol : settings.protocolType.http + protocol: options.protocol ? options.protocol : settings.protocolType.http, + + //Path to ApplicationHost.Config + config: options.config ? options.config : ''; }; - - // The path stored in options could be a relative path such as './' or './child-sub-folder' // It may also include the legacy full path of the workspace rootpath // Which caused issues - when checked into source control & other users did not have same folder structure @@ -106,7 +108,13 @@ export class IISExpress { // 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:any) { console.log(error); this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath, "appCmd": `add site -name:${siteName} -bindings:${this._args.protocol}://localhost:${this._args.port} -physicalPath:${this._args.path}`}); @@ -118,7 +126,13 @@ export class IISExpress { // 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:any) { console.log(error); this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath}); @@ -128,10 +142,16 @@ export class IISExpress { telemtry.updateCountAndReport(this._context, this._reporter, telemtry.keys.start); telemtry.updateCountAndReport(this._context, this._reporter, telemtry.keys.sponsorware); - // This is the magic that runs the IISExpress cmd from the appcmd config list - this._iisProcess = process.spawn(this._iisPath, [`-site:${siteName}`]); + //This is the magic that runs the IISExpress cmd from the appcmd config list + var iisArgs: string[] = [`-site:${siteName}`]; + + if(this._args.config){ + iisArgs.unshift(`/config:${this._args.config}`) + } - // Create Statusbar item & show it + this._iisProcess = process.spawn(this._iisPath, iisArgs); + + //Create Statusbar item & show it this._statusbar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); // Set props on statusbar & show it @@ -180,7 +200,12 @@ export class IISExpress { // 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:any) { console.log(error); this._reporter.sendTelemetryException(error, {"appCmdPath": this._iisAppCmdPath, "appCmd": `delete site ${siteName}`}); diff --git a/src/iisexpress-schema.json b/src/iisexpress-schema.json index cbaa37da..70e2bd8d 100644 --- a/src/iisexpress-schema.json +++ b/src/iisexpress-schema.json @@ -27,6 +27,10 @@ "type": "string", "description": "This property is optional & allows you to set an absolute path to the folder or subfolder as the root of your site/project for IIS Express to run. Additionally this support relative paths to the workspace folder such as ./my-sub-folder" }, + "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 de02b41a..cb314af1 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -5,6 +5,7 @@ import * as util from './util'; export interface Isettings { port: number; path: string; + config?: string; url?: string; clr: clrVersion; protocol: protocolType; @@ -45,7 +46,8 @@ export function getSettings(uri:vscode.Uri| undefined):Isettings{ port : getRandomPort(), path: './', clr: clrVersion.v40, - protocol: protocolType.http + protocol: protocolType.http, + config: getLocalApplicationHostConfig() }; let settings:Isettings; @@ -122,6 +124,28 @@ export function getSettings(uri:vscode.Uri| undefined):Isettings{ } } +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