Add local debug support for C# Scripts

This commit is contained in:
Eric Jizba 2018-01-23 10:47:23 -08:00
Родитель 283d77109b
Коммит d61db5d4ad
4 изменённых файлов: 67 добавлений и 12 удалений

Просмотреть файл

@ -15,6 +15,7 @@
* [Node 8.0+](https://nodejs.org/)
* For C# based Functions:
* [VS Code Debugger for C#](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp)
> NOTE: The default experience for C# uses class libraries (*.cs files), which provide superior performance, scalability, and versatility over C# Scripts (*.csx files). If you want to use C# Scripts, you may change your `azureFunctions.projectLanguage` user setting to `C#Script`.
* For Java based Functions:
* [VS Code Debugger for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-debug)
* [JDK 1.8+](http://www.oracle.com/technetwork/java/javase/downloads/index.html)

Просмотреть файл

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { localize } from "../../localize";
import { ProjectRuntime, TemplateFilter } from "../../ProjectSettings";
import { funcHostTaskId, funcHostTaskLabel } from "./IProjectCreator";
import { ScriptProjectCreatorBase } from './ScriptProjectCreatorBase';
export class CSharpScriptProjectCreator extends ScriptProjectCreatorBase {
public readonly templateFilter: TemplateFilter = TemplateFilter.Verified;
public readonly runtime: ProjectRuntime = ProjectRuntime.beta;
public getTasksJson(): {} {
return {
version: '2.0.0',
tasks: [
{
label: funcHostTaskLabel,
identifier: funcHostTaskId,
type: 'shell',
command: 'func host start',
isBackground: true,
presentation: {
reveal: 'always'
}
}
]
};
}
public getLaunchJson(): {} {
return {
version: '0.2.0',
configurations: [
{
name: localize('azFunc.attachToNetCoreFunc', "Attach to .NET Core Functions"),
type: 'coreclr',
request: 'attach',
processId: '\${command:azureFunctions.pickProcess}'
}
]
};
}
public getRecommendedExtensions(): string[] {
return ['ms-vscode.csharp'];
}
}

Просмотреть файл

@ -17,6 +17,7 @@ import { gitUtils } from '../../utils/gitUtils';
import * as workspaceUtil from '../../utils/workspace';
import { VSCodeUI } from '../../VSCodeUI';
import { CSharpProjectCreator } from './CSharpProjectCreator';
import { CSharpScriptProjectCreator } from './CSharpScriptProjectCreator';
import { IProjectCreator } from './IProjectCreator';
import { JavaProjectCreator } from './JavaProjectCreator';
import { JavaScriptProjectCreator } from './JavaScriptProjectCreator';
@ -54,6 +55,9 @@ export async function createNewProject(telemetryProperties: TelemetryProperties,
case ProjectLanguage.CSharp:
projectCreator = new CSharpProjectCreator(outputChannel);
break;
case ProjectLanguage.CSharpScript:
projectCreator = new CSharpScriptProjectCreator();
break;
default:
projectCreator = new ScriptProjectCreatorBase();
break;

Просмотреть файл

@ -47,7 +47,7 @@ suite('Create New Project Tests', async function (this: ISuiteCallbackContext):
undefined,
undefined
);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath);
assert.equal(await fse.pathExists(path.join(projectPath, 'src')), true, 'src folder does not exist');
assert.equal(await fse.pathExists(path.join(projectPath, 'pom.xml')), true, 'pom.xml does not exist');
});
@ -63,7 +63,7 @@ suite('Create New Project Tests', async function (this: ISuiteCallbackContext):
test(csharpProject, async () => {
const projectPath: string = path.join(testFolderPath, csharpProject);
await testCreateNewProject(projectPath, ProjectLanguage.CSharp, false);
await testCommonProjectFilesExist(projectPath, false, true);
await testCommonProjectFilesExist(projectPath, true, true);
const projectName: string = path.basename(projectPath);
assert.equal(await fse.pathExists(path.join(projectPath, `${projectName}.csproj`)), true, 'csproj does not exist');
});
@ -72,56 +72,56 @@ suite('Create New Project Tests', async function (this: ISuiteCallbackContext):
test(bashProject, async () => {
const projectPath: string = path.join(testFolderPath, bashProject);
await testCreateNewProject(projectPath, ProjectLanguage.Bash, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
const batchProject: string = 'BatchProject';
test(batchProject, async () => {
const projectPath: string = path.join(testFolderPath, batchProject);
await testCreateNewProject(projectPath, ProjectLanguage.Batch, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
const csharpScriptProject: string = 'CSharpScriptProject';
test(csharpScriptProject, async () => {
const projectPath: string = path.join(testFolderPath, csharpScriptProject);
await testCreateNewProject(projectPath, ProjectLanguage.CSharpScript, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, true, true);
});
const fsharpScriptProject: string = 'FSharpScriptProject';
test(fsharpScriptProject, async () => {
const projectPath: string = path.join(testFolderPath, fsharpScriptProject);
await testCreateNewProject(projectPath, ProjectLanguage.FSharpScript, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
const phpProject: string = 'PHPProject';
test(phpProject, async () => {
const projectPath: string = path.join(testFolderPath, phpProject);
await testCreateNewProject(projectPath, ProjectLanguage.PHP, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
const powerShellProject: string = 'PowerShellProject';
test(powerShellProject, async () => {
const projectPath: string = path.join(testFolderPath, powerShellProject);
await testCreateNewProject(projectPath, ProjectLanguage.PowerShell, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
const pythonProject: string = 'PythonProject';
test(pythonProject, async () => {
const projectPath: string = path.join(testFolderPath, pythonProject);
await testCreateNewProject(projectPath, ProjectLanguage.Python, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
const typeScriptProject: string = 'TypeScriptProject';
test(typeScriptProject, async () => {
const projectPath: string = path.join(testFolderPath, typeScriptProject);
await testCreateNewProject(projectPath, ProjectLanguage.TypeScript, true);
await testCommonProjectFilesExist(projectPath, true);
await testCommonProjectFilesExist(projectPath, false);
});
test('createNewProject API', async () => {
@ -146,14 +146,14 @@ suite('Create New Project Tests', async function (this: ISuiteCallbackContext):
assert.equal(inputs.length, 0, 'Not all inputs were used.');
}
async function testCommonProjectFilesExist(projectPath: string, previewLanguage: boolean = false, hasExtensionRecommendations: boolean = false): Promise<void> {
async function testCommonProjectFilesExist(projectPath: string, hasLaunchJson: boolean = true, hasExtensionRecommendations: boolean = false): Promise<void> {
assert.equal(await fse.pathExists(path.join(projectPath, '.gitignore')), true, '.gitignore does not exist');
assert.equal(await fse.pathExists(path.join(projectPath, 'host.json')), true, 'host.json does not exist');
assert.equal(await fse.pathExists(path.join(projectPath, 'local.settings.json')), true, 'function.json does not exist');
assert.equal(await fse.pathExists(path.join(projectPath, '.git')), true, '.git folder does not exist');
const vscodePath: string = path.join(projectPath, '.vscode');
assert.equal(await fse.pathExists(path.join(vscodePath, 'settings.json')), true, 'settings.json does not exist');
if (!previewLanguage) {
if (hasLaunchJson) {
assert.equal(await fse.pathExists(path.join(vscodePath, 'launch.json')), true, 'launch.json does not exist');
}
assert.equal(await fse.pathExists(path.join(vscodePath, 'tasks.json')), true, 'tasks.json does not exist');