@@ -59,7 +59,7 @@ export class AssetGenerator {
5959
6060 private hasProject : boolean ;
6161 private projectPath : string ;
62- private projectJsonPath : string ;
62+ private projectFilePath : string ;
6363 private targetFramework : string ;
6464 private executableName : string ;
6565 private configurationName : string ;
@@ -82,9 +82,29 @@ export class AssetGenerator {
8282 // this when we allow selecting configurations.
8383 const configurationName = 'Debug' ;
8484
85- const executableProjects = this . findExecutableProjects ( workspaceInfo . DotNet . Projects , configurationName ) ;
85+ // First, we'll check for .NET Core .csproj projects.
86+ if ( workspaceInfo . MsBuild && workspaceInfo . MsBuild . Projects ) {
87+ const executableMSBuildProjects = findExecutableMSBuildProjects ( workspaceInfo . MsBuild . Projects ) ;
8688
87- // TODO: We arbitrarily pick the first executable projec that we find. This will need
89+ const targetMSBuildProject = executableMSBuildProjects . length > 0
90+ ? executableMSBuildProjects [ 0 ]
91+ : undefined ;
92+
93+ if ( targetMSBuildProject ) {
94+ this . hasProject = true ;
95+ this . projectPath = path . dirname ( targetMSBuildProject . Path ) ;
96+ this . projectFilePath = targetMSBuildProject . Path ;
97+ this . targetFramework = findNetCoreAppTargetFramework ( targetMSBuildProject ) . ShortName ;
98+ this . executableName = targetMSBuildProject . AssemblyName + ".dll" ;
99+ this . configurationName = configurationName ;
100+ return ;
101+ }
102+ }
103+
104+ // Next, we'll try looking for project.json projects.
105+ const executableProjects = findExecutableProjectJsonProjects ( workspaceInfo . DotNet . Projects , configurationName ) ;
106+
107+ // TODO: We arbitrarily pick the first executable project that we find. This will need
88108 // revisiting when we project a "start up project" selector.
89109 const targetProject = executableProjects . length > 0
90110 ? executableProjects [ 0 ]
@@ -95,7 +115,7 @@ export class AssetGenerator {
95115 if ( config ) {
96116 this . hasProject = true ;
97117 this . projectPath = targetProject . Path ;
98- this . projectJsonPath = path . join ( targetProject . Path , 'project.json' ) ;
118+ this . projectFilePath = path . join ( targetProject . Path , 'project.json' ) ;
99119 this . targetFramework = targetProject . Frameworks [ 0 ] . ShortName ;
100120 this . executableName = path . basename ( config . CompilationOutputAssemblyFile ) ;
101121 this . configurationName = configurationName ;
@@ -105,28 +125,14 @@ export class AssetGenerator {
105125 return undefined ;
106126 }
107127
108- private findExecutableProjects ( projects : protocol . DotNetProject [ ] , configName : string ) {
109- let result : protocol . DotNetProject [ ] = [ ] ;
110-
111- projects . forEach ( project => {
112- project . Configurations . forEach ( configuration => {
113- if ( configuration . Name === configName && configuration . EmitEntryPoint === true ) {
114- if ( project . Frameworks . length > 0 ) {
115- result . push ( project ) ;
116- }
117- }
118- } ) ;
119- } ) ;
120-
121- return result ;
122- }
123-
124128 public hasWebServerDependency ( ) : boolean {
125- if ( ! this . projectJsonPath ) {
129+ // TODO: Update to handle .NET Core projects.
130+
131+ if ( ! this . projectFilePath || path . extname ( this . projectFilePath ) !== 'json' ) {
126132 return false ;
127133 }
128134
129- let projectJson = fs . readFileSync ( this . projectJsonPath , 'utf8' ) ;
135+ let projectJson = fs . readFileSync ( this . projectFilePath , 'utf8' ) ;
130136 projectJson = projectJson . replace ( / ^ \uFEFF / , '' ) ;
131137
132138 let projectJsonObject : any ;
@@ -253,7 +259,7 @@ export class AssetGenerator {
253259 private createBuildTaskDescription ( ) : tasks . TaskDescription {
254260 let buildPath = '' ;
255261 if ( this . hasProject ) {
256- buildPath = path . join ( '${workspaceRoot}' , path . relative ( this . rootPath , this . projectJsonPath ) ) ;
262+ buildPath = path . join ( '${workspaceRoot}' , path . relative ( this . rootPath , this . projectFilePath ) ) ;
257263 }
258264
259265 return {
@@ -275,6 +281,49 @@ export class AssetGenerator {
275281 }
276282}
277283
284+ function findNetCoreAppTargetFramework ( project : protocol . MSBuildProject ) {
285+ return project . TargetFrameworks . find ( tf => tf . ShortName . startsWith ( 'netcoreapp' ) ) ;
286+ }
287+
288+ function findExecutableMSBuildProjects ( projects : protocol . MSBuildProject [ ] ) {
289+ let result : protocol . MSBuildProject [ ] = [ ] ;
290+
291+ projects . forEach ( project => {
292+ if ( project . IsExe && findNetCoreAppTargetFramework ( project ) !== undefined ) {
293+ result . push ( project ) ;
294+ }
295+ } ) ;
296+
297+ return result ;
298+ }
299+
300+ function findExecutableProjectJsonProjects ( projects : protocol . DotNetProject [ ] , configurationName : string ) {
301+ let result : protocol . DotNetProject [ ] = [ ] ;
302+
303+ projects . forEach ( project => {
304+ project . Configurations . forEach ( configuration => {
305+ if ( configuration . Name === configurationName && configuration . EmitEntryPoint === true ) {
306+ if ( project . Frameworks . length > 0 ) {
307+ result . push ( project ) ;
308+ }
309+ }
310+ } ) ;
311+ } ) ;
312+
313+ return result ;
314+ }
315+
316+ function containsDotNetCoreProjects ( workspaceInfo : protocol . WorkspaceInformationResponse ) {
317+ if ( workspaceInfo . DotNet && findExecutableProjectJsonProjects ( workspaceInfo . DotNet . Projects , 'Debug' ) . length > 0 ) {
318+ return true ;
319+ }
320+
321+ if ( workspaceInfo . MsBuild && findExecutableMSBuildProjects ( workspaceInfo . MsBuild . Projects ) . length > 0 ) {
322+ return true ;
323+ }
324+ }
325+
326+
278327interface Operations {
279328 addTasksJson ?: boolean ;
280329 updateTasksJson ?: boolean ;
@@ -416,7 +465,7 @@ export function addAssetsIfNecessary(server: OmniSharpServer): Promise<AddAssetR
416465
417466 serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
418467 // If there are no .NET Core projects, we won't bother offering to add assets.
419- if ( info . DotNet && info . DotNet . Projects . length > 0 ) {
468+ if ( containsDotNetCoreProjects ( info ) ) {
420469 const generator = new AssetGenerator ( info ) ;
421470 return getOperations ( generator ) . then ( operations => {
422471 if ( ! hasOperations ( operations ) ) {
@@ -512,7 +561,7 @@ function shouldGenerateAssets(generator: AssetGenerator) {
512561
513562export function generateAssets ( server : OmniSharpServer ) {
514563 serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
515- if ( info . DotNet && info . DotNet . Projects . length > 0 ) {
564+ if ( containsDotNetCoreProjects ( info ) ) {
516565 const generator = new AssetGenerator ( info ) ;
517566 getOperations ( generator ) . then ( operations => {
518567 if ( hasOperations ( operations ) ) {
0 commit comments