Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for diffrent ApplicationHost.Config files #36

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions src/IISExpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 : '';

Check notice

Code scanning / CodeQL

Syntax error

Error: ',' expected.
};



// 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
Expand Down Expand Up @@ -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}`});
Expand All @@ -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});
Expand All @@ -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
Expand Down Expand Up @@ -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}`});
Expand Down
4 changes: 4 additions & 0 deletions src/iisexpress-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
26 changes: 25 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as util from './util';
export interface Isettings {
port: number;
path: string;
config?: string;
url?: string;
clr: clrVersion;
protocol: protocolType;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down