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 2 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
35 changes: 31 additions & 4 deletions src/IISExpress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IExpressArguments {
port?: number;
clr?: settings.clrVersion;
protocol?: settings.protocolType;
config?: string;
}

// TODO:
Expand Down Expand Up @@ -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;

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