Skip to content

Commit f7c58d8

Browse files
committed
Add support for building NET 5.0 launch.json
1 parent 19a8af1 commit f7c58d8

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

src/assets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ export class AssetGenerator {
161161
const startupProjectDir = path.dirname(this.startupProject.Path);
162162
const relativeProjectDir = path.join('${workspaceFolder}', path.relative(this.workspaceFolder.uri.fsPath, startupProjectDir));
163163
const configurationName = 'Debug';
164-
const targetFramework = protocol.findNetCoreAppTargetFramework(this.startupProject).ShortName;
165-
const result = path.join(relativeProjectDir, `bin/${configurationName}/${targetFramework}/${this.startupProject.AssemblyName}.dll`);
164+
const targetFramework = protocol.findNetCoreAppTargetFramework(this.startupProject) ?? protocol.findNet5TargetFramework(this.startupProject);
165+
const result = path.join(relativeProjectDir, `bin/${configurationName}/${targetFramework.ShortName}/${this.startupProject.AssemblyName}.dll`);
166166
return result;
167167
}
168168

src/omnisharp/protocol.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ export interface ProjectInformationResponse {
287287
DotNetProject: DotNetProject;
288288
}
289289

290-
export enum DiagnosticStatus
291-
{
290+
export enum DiagnosticStatus {
292291
Processing = 0,
293292
Ready = 1
294293
}
@@ -740,6 +739,16 @@ export function findNetFrameworkTargetFramework(project: MSBuildProject): Target
740739
return project.TargetFrameworks.find(tf => regexp.test(tf.ShortName));
741740
}
742741

742+
export function findNet5TargetFramework(project: MSBuildProject): TargetFramework {
743+
const targetFramework = project.TargetFrameworks.find(tf => tf.ShortName.startsWith('net5'));
744+
// Temprorary workaround until changes to support the net5.0 TFM is settled. Some NuGet
745+
// builds report the shortname as net50.
746+
if (targetFramework !== undefined) {
747+
targetFramework.ShortName = "net5.0";
748+
}
749+
return targetFramework;
750+
}
751+
743752
export function findNetCoreAppTargetFramework(project: MSBuildProject): TargetFramework {
744753
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netcoreapp'));
745754
}
@@ -749,7 +758,8 @@ export function findNetStandardTargetFramework(project: MSBuildProject): TargetF
749758
}
750759

751760
export function isDotNetCoreProject(project: MSBuildProject): Boolean {
752-
return findNetCoreAppTargetFramework(project) !== undefined ||
761+
return findNet5TargetFramework(project) !== undefined ||
762+
findNetCoreAppTargetFramework(project) !== undefined ||
753763
findNetStandardTargetFramework(project) !== undefined ||
754764
findNetFrameworkTargetFramework(project) !== undefined;
755765
}
@@ -792,7 +802,11 @@ export function findExecutableMSBuildProjects(projects: MSBuildProject[]) {
792802
let result: MSBuildProject[] = [];
793803

794804
projects.forEach(project => {
795-
if (project.IsExe && (findNetCoreAppTargetFramework(project) !== undefined || project.IsBlazorWebAssemblyStandalone)) {
805+
const projectIsNotNetFramework = findNetCoreAppTargetFramework(project) !== undefined
806+
|| findNet5TargetFramework(project) !== undefined
807+
|| project.IsBlazorWebAssemblyStandalone;
808+
809+
if (project.IsExe && projectIsNotNetFramework) {
796810
result.push(project);
797811
}
798812
});

test/featureTests/assets.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ suite("Asset generation: csproj", () => {
4444
generator.setStartupProject(0);
4545
let tasksJson = generator.createTasksConfiguration();
4646

47-
tasksJson.tasks.forEach(task=> task.args.should.contain("/consoleloggerparameters:NoSummary"));
47+
tasksJson.tasks.forEach(task => task.args.should.contain("/consoleloggerparameters:NoSummary"));
4848
});
4949

5050
test("Create tasks.json for nested project opened in workspace", () => {
@@ -73,6 +73,19 @@ suite("Asset generation: csproj", () => {
7373
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', 'netcoreapp1.0', 'testApp.dll']);
7474
});
7575

76+
test("Create launch.json for NET 5 project opened in workspace", () => {
77+
let rootPath = path.resolve('testRoot');
78+
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'testApp.csproj'), 'testApp', 'net5.0', /*isExe*/ true);
79+
let generator = new AssetGenerator(info, createMockWorkspaceFolder(rootPath));
80+
generator.setStartupProject(0);
81+
let launchJson = parse(generator.createLaunchJsonConfigurations(ProgramLaunchType.Console), undefined, { disallowComments: true });
82+
let programPath = launchJson[0].program;
83+
84+
// ${workspaceFolder}/bin/Debug/net5.0/testApp.dll
85+
let segments = programPath.split(path.posix.sep);
86+
segments.should.deep.equal(['${workspaceFolder}', 'bin', 'Debug', 'net5.0', 'testApp.dll']);
87+
});
88+
7689
test("Create launch.json for nested project opened in workspace", () => {
7790
let rootPath = path.resolve('testRoot');
7891
let info = createMSBuildWorkspaceInformation(path.join(rootPath, 'nested', 'testApp.csproj'), 'testApp', 'netcoreapp1.0');

0 commit comments

Comments
 (0)