Skip to content

Commit 4ba9941

Browse files
Merge pull request #1176 from DustinCampbell/fix-dotnet-restore-command
.NET: Restore Packages command should work with .NET Core .csproj projects
2 parents 890360b + 214c6cd commit 4ba9941

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@
421421
{
422422
"command": "dotnet.restore",
423423
"title": "Restore Packages",
424-
"category": "dotnet"
424+
"category": ".NET"
425425
},
426426
{
427427
"command": "csharp.downloadDebugger",

src/assets.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class AssetGenerator {
9595
this.hasProject = true;
9696
this.projectPath = path.dirname(targetMSBuildProject.Path);
9797
this.projectFilePath = targetMSBuildProject.Path;
98-
this.targetFramework = findNetCoreAppTargetFramework(targetMSBuildProject).ShortName;
98+
this.targetFramework = protocol.findNetCoreAppTargetFramework(targetMSBuildProject).ShortName;
9999
this.executableName = targetMSBuildProject.AssemblyName + ".dll";
100100
this.configurationName = configurationName;
101101
return;
@@ -284,15 +284,11 @@ export class AssetGenerator {
284284
}
285285
}
286286

287-
function findNetCoreAppTargetFramework(project: protocol.MSBuildProject): protocol.TargetFramework {
288-
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netcoreapp'));
289-
}
290-
291287
function findExecutableMSBuildProjects(projects: protocol.MSBuildProject[]) {
292288
let result: protocol.MSBuildProject[] = [];
293289

294290
projects.forEach(project => {
295-
if (project.IsExe && findNetCoreAppTargetFramework(project) !== undefined) {
291+
if (project.IsExe && protocol.findNetCoreAppTargetFramework(project) !== undefined) {
296292
result.push(project);
297293
}
298294
});

src/features/commands.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ interface Command {
8383
execute(): Thenable<any>;
8484
}
8585

86-
function projectsToCommands(projects: protocol.DotNetProject[]): Promise<Command>[] {
86+
function projectsToCommands(projects: protocol.ProjectDescriptor[]): Promise<Command>[] {
8787
return projects.map(project => {
8888
let projectDirectory = project.Path;
8989

@@ -117,11 +117,13 @@ export function dotnetRestoreAllProjects(server: OmniSharpServer) {
117117

118118
return serverUtils.requestWorkspaceInformation(server).then(info => {
119119

120-
if (!info.DotNet || info.DotNet.Projects.length < 1) {
120+
let projectDescriptors = protocol.getDotNetCoreProjectDescriptors(info);
121+
122+
if (projectDescriptors.length === 0) {
121123
return Promise.reject("No .NET Core projects found");
122124
}
123125

124-
let commandPromises = projectsToCommands(info.DotNet.Projects);
126+
let commandPromises = projectsToCommands(projectDescriptors);
125127

126128
return Promise.all(commandPromises).then(commands => {
127129
return vscode.window.showQuickPick(commands);

src/omnisharp/protocol.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
'use strict';
77

8+
import * as path from 'path';
9+
810
export module Requests {
911
export const AddToProject = '/addtoproject';
1012
export const AutoComplete = '/autocomplete';
@@ -509,4 +511,38 @@ export namespace V2 {
509511
Failure: string;
510512
Pass: boolean;
511513
}
514+
}
515+
516+
export function findNetCoreAppTargetFramework(project: MSBuildProject): TargetFramework {
517+
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netcoreapp'));
518+
}
519+
520+
export function findNetStandardTargetFramework(project: MSBuildProject): TargetFramework {
521+
return project.TargetFrameworks.find(tf => tf.ShortName.startsWith('netstandard'));
522+
}
523+
524+
export interface ProjectDescriptor {
525+
Name: string;
526+
Path: string;
527+
}
528+
529+
export function getDotNetCoreProjectDescriptors(info: WorkspaceInformationResponse): ProjectDescriptor[] {
530+
let result = [];
531+
532+
if (info.DotNet && info.DotNet.Projects.length > 0) {
533+
for (let project of info.DotNet.Projects) {
534+
result.push({ Name: project.Name, Path: project.Path });
535+
}
536+
}
537+
538+
if (info.MsBuild && info.MsBuild.Projects.length > 0) {
539+
for (let project of info.MsBuild.Projects) {
540+
if (findNetCoreAppTargetFramework(project) !== undefined ||
541+
findNetStandardTargetFramework(project) !== undefined) {
542+
result.push({ Name: path.basename(project.Path), Path: project.Path });
543+
}
544+
}
545+
}
546+
547+
return result;
512548
}

0 commit comments

Comments
 (0)