@@ -9,6 +9,9 @@ import * as fs from 'fs-extra-promise';
99import * as path from 'path' ;
1010import * as vscode from 'vscode' ;
1111import * as tasks from 'vscode-tasks' ;
12+ import { OmnisharpServer } from './omnisharpServer' ;
13+ import * as serverUtils from './omnisharpUtils' ;
14+ import * as protocol from './protocol.ts'
1215
1316interface DebugConfiguration {
1417 name : string ,
@@ -125,26 +128,26 @@ function promptToAddAssets() {
125128 } ) ;
126129}
127130
128- function createLaunchConfiguration ( ) : ConsoleLaunchConfiguration {
131+ function createLaunchConfiguration ( targetFramework : string , executableName : string ) : ConsoleLaunchConfiguration {
129132 return {
130133 name : '.NET Core Launch (console)' ,
131134 type : 'coreclr' ,
132135 request : 'launch' ,
133136 preLaunchTask : 'build' ,
134- program : '${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>' ,
137+ program : '${workspaceRoot}/bin/Debug/' + targetFramework + '/' + executableName ,
135138 args : [ ] ,
136139 cwd : '${workspaceRoot}' ,
137140 stopAtEntry : false
138141 }
139142}
140143
141- function createWebLaunchConfiguration ( ) : WebLaunchConfiguration {
144+ function createWebLaunchConfiguration ( targetFramework : string , executableName : string ) : WebLaunchConfiguration {
142145 return {
143146 name : '.NET Core Launch (web)' ,
144147 type : 'coreclr' ,
145148 request : 'launch' ,
146149 preLaunchTask : 'build' ,
147- program : '${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>' ,
150+ program : '${workspaceRoot}/bin/Debug/' + targetFramework + '/' + executableName ,
148151 args : [ ] ,
149152 cwd : '${workspaceRoot}' ,
150153 stopAtEntry : false ,
@@ -167,19 +170,19 @@ function createWebLaunchConfiguration(): WebLaunchConfiguration {
167170
168171function createAttachConfiguration ( ) : AttachConfiguration {
169172 return {
170- name : '.NET Core Attack ' ,
173+ name : '.NET Core Attach ' ,
171174 type : 'coreclr' ,
172175 request : 'attach' ,
173176 processName : '<example>'
174177 }
175178}
176179
177- function createLaunchJson ( ) : any {
180+ function createLaunchJson ( targetFramework : string , executableName : string ) : any {
178181 return {
179182 version : '0.2.0' ,
180183 configurations : [
181- createLaunchConfiguration ( ) ,
182- createWebLaunchConfiguration ( ) ,
184+ createLaunchConfiguration ( targetFramework , executableName ) ,
185+ createWebLaunchConfiguration ( targetFramework , executableName ) ,
183186 createAttachConfiguration ( )
184187 ]
185188 }
@@ -204,7 +207,7 @@ function createTasksConfiguration(): tasks.TaskConfiguration {
204207 } ;
205208}
206209
207- function addTasksJsonIfNecessary ( paths : Paths , operations : Operations ) {
210+ function addTasksJsonIfNecessary ( info : protocol . DotNetWorkspaceInformation , paths : Paths , operations : Operations ) {
208211 return new Promise < void > ( ( resolve , reject ) => {
209212 if ( ! operations . addTasksJson ) {
210213 return resolve ( ) ;
@@ -217,66 +220,63 @@ function addTasksJsonIfNecessary(paths: Paths, operations: Operations) {
217220 } ) ;
218221}
219222
220- function updateTasksJsonIfNecesssary ( paths : Paths , operations : Operations ) {
223+ function addLaunchJsonIfNecessary ( info : protocol . DotNetWorkspaceInformation , paths : Paths , operations : Operations ) {
221224 return new Promise < void > ( ( resolve , reject ) => {
222- if ( ! operations . updateTasksJson ) {
225+ if ( ! operations . addLaunchJson ) {
223226 return resolve ( ) ;
224227 }
225228
226- return fs . readFileAsync ( paths . tasksJsonPath ) . then ( buffer => {
227- const bufferText = buffer . toString ( ) ;
228- const tasksJson : tasks . TaskConfiguration = JSON . parse ( bufferText ) ;
229- tasksJson . tasks . push ( createBuildTaskDescription ( ) ) ;
230- const tasksJsonText = JSON . stringify ( tasksJson , null , ' ' ) ;
231-
232- return fs . writeFileAsync ( paths . tasksJsonPath , tasksJsonText ) ;
233- } ) ;
234- } ) ;
235- }
229+ let targetFramework = '<target-framework>' ;
230+ let executableName = '<project-name.dll>' ;
231+
232+ let projectWithEntryPoint = info . Projects . find ( project => project . EmitEntryPoint === true ) ;
236233
237- function addLaunchJsonIfNecessary ( paths : Paths , operations : Operations ) {
238- return new Promise < void > ( ( resolve , reject ) => {
239- if ( ! operations . addLaunchJson ) {
240- return resolve ( ) ;
234+ if ( projectWithEntryPoint ) {
235+ targetFramework = projectWithEntryPoint . TargetFramework . ShortName ;
236+ executableName = path . basename ( projectWithEntryPoint . CompilationOutputAssemblyFile ) ;
241237 }
242238
243- const launchJson = createLaunchJson ( ) ;
239+ const launchJson = createLaunchJson ( targetFramework , executableName ) ;
244240 const launchJsonText = JSON . stringify ( launchJson , null , ' ' ) ;
245241
246242 return fs . writeFileAsync ( paths . launchJsonPath , launchJsonText ) ;
247243 } ) ;
248244}
249245
250- export function addAssetsIfNecessary ( ) {
246+ export function addAssetsIfNecessary ( server : OmnisharpServer ) {
251247 if ( ! vscode . workspace . rootPath ) {
252248 return ;
253249 }
254250
255- // If there is no project.json, we won't bother to prompt the user for tasks.json.
256- const projectJsonPath = path . join ( vscode . workspace . rootPath , 'project.json' ) ;
251+ // If there is no project.json, we won't bother to prompt the user for tasks.json.
252+ const projectJsonPath = path . join ( vscode . workspace . rootPath , 'project.json' ) ;
257253 if ( ! fs . existsSync ( projectJsonPath ) ) {
258254 return ;
259255 }
260-
261- return getOperations ( ) . then ( operations => {
262- if ( ! hasOperations ( operations ) ) {
263- return ;
264- }
265-
266- promptToAddAssets ( ) . then ( addAssets => {
267- if ( ! addAssets ) {
268- return ;
269- }
270-
271- const paths = getPaths ( ) ;
272-
273- return fs . ensureDirAsync ( paths . vscodeFolder ) . then ( ( ) => {
274- return Promise . all ( [
275- addTasksJsonIfNecessary ( paths , operations ) ,
276- updateTasksJsonIfNecesssary ( paths , operations ) ,
277- addLaunchJsonIfNecessary ( paths , operations )
278- ] ) ;
256+
257+ return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
258+ // If there are no .NET Core projects, we won't bother offering to add assets.
259+ if ( 'DotNet' in info && info . DotNet . Projects . length > 0 ) {
260+ return getOperations ( ) . then ( operations => {
261+ if ( ! hasOperations ( operations ) ) {
262+ return ;
263+ }
264+
265+ promptToAddAssets ( ) . then ( addAssets => {
266+ if ( ! addAssets ) {
267+ return ;
268+ }
269+
270+ const paths = getPaths ( ) ;
271+
272+ return fs . ensureDirAsync ( paths . vscodeFolder ) . then ( ( ) => {
273+ return Promise . all ( [
274+ addTasksJsonIfNecessary ( info . DotNet , paths , operations ) ,
275+ addLaunchJsonIfNecessary ( info . DotNet , paths , operations )
276+ ] ) ;
277+ } ) ;
278+ } ) ;
279279 } ) ;
280- } ) ;
280+ }
281281 } ) ;
282282}
0 commit comments