@@ -112,11 +112,12 @@ export default class TestManager extends AbstractProvider {
112112 vscode . workspace . saveAll ( /*includeUntitled*/ false ) ) ;
113113 }
114114
115- private _runTest ( fileName : string , testMethod : string , testFrameworkName : string ) : Promise < protocol . V2 . DotNetTestResult [ ] > {
115+ private _runTest ( fileName : string , testMethod : string , testFrameworkName : string , targetFrameworkVersion : string ) : Promise < protocol . V2 . DotNetTestResult [ ] > {
116116 const request : protocol . V2 . RunTestRequest = {
117117 FileName : fileName ,
118118 MethodName : testMethod ,
119- TestFrameworkName : testFrameworkName
119+ TestFrameworkName : testFrameworkName ,
120+ TargetFrameworkVersion : targetFrameworkVersion
120121 } ;
121122
122123 return serverUtils . runTest ( this . _server , request )
@@ -162,7 +163,23 @@ export default class TestManager extends AbstractProvider {
162163
163164 this . _saveDirtyFiles ( )
164165 . then ( _ => this . _recordRunRequest ( testFrameworkName ) )
165- . then ( _ => this . _runTest ( fileName , testMethod , testFrameworkName ) )
166+ . then ( _ => serverUtils . requestProjectInformation ( this . _server , { FileName : fileName } ) )
167+ . then ( projectInfo =>
168+ {
169+ let targetFrameworkVersion : string ;
170+
171+ if ( projectInfo . DotNetProject ) {
172+ targetFrameworkVersion = undefined ;
173+ }
174+ else if ( projectInfo . MsBuildProject ) {
175+ targetFrameworkVersion = projectInfo . MsBuildProject . TargetFramework ;
176+ }
177+ else {
178+ throw new Error ( 'Expected project.json or .csproj project.' ) ;
179+ }
180+
181+ return this . _runTest ( fileName , testMethod , testFrameworkName , targetFrameworkVersion ) ;
182+ } )
166183 . then ( results => this . _reportResults ( results ) )
167184 . then ( ( ) => listener . dispose ( ) )
168185 . catch ( reason => {
@@ -198,7 +215,7 @@ export default class TestManager extends AbstractProvider {
198215 return result ;
199216 }
200217
201- private _getLaunchConfigurationForVSTest ( fileName : string , testMethod : string , testFrameworkName : string , debugEventListener : DebugEventListener ) : Promise < any > {
218+ private _getLaunchConfigurationForVSTest ( fileName : string , testMethod : string , testFrameworkName : string , targetFrameworkVersion : string , debugEventListener : DebugEventListener ) : Promise < any > {
202219 const output = this . _getOutputChannel ( ) ;
203220
204221 // Listen for test messages while getting start info.
@@ -209,7 +226,8 @@ export default class TestManager extends AbstractProvider {
209226 const request : protocol . V2 . DebugTestGetStartInfoRequest = {
210227 FileName : fileName ,
211228 MethodName : testMethod ,
212- TestFrameworkName : testFrameworkName
229+ TestFrameworkName : testFrameworkName ,
230+ TargetFrameworkVersion : targetFrameworkVersion
213231 } ;
214232
215233 return serverUtils . debugTestGetStartInfo ( this . _server , request )
@@ -219,7 +237,7 @@ export default class TestManager extends AbstractProvider {
219237 } ) ;
220238 }
221239
222- private _getLaunchConfigurationForLegacy ( fileName : string , testMethod : string , testFrameworkName : string ) : Promise < any > {
240+ private _getLaunchConfigurationForLegacy ( fileName : string , testMethod : string , testFrameworkName : string , targetFrameworkVersion : string ) : Promise < any > {
223241 const output = this . _getOutputChannel ( ) ;
224242
225243 // Listen for test messages while getting start info.
@@ -230,7 +248,8 @@ export default class TestManager extends AbstractProvider {
230248 const request : protocol . V2 . GetTestStartInfoRequest = {
231249 FileName : fileName ,
232250 MethodName : testMethod ,
233- TestFrameworkName : testFrameworkName
251+ TestFrameworkName : testFrameworkName ,
252+ TargetFrameworkVersion : targetFrameworkVersion
234253 } ;
235254
236255 return serverUtils . getTestStartInfo ( this . _server , request )
@@ -240,12 +259,12 @@ export default class TestManager extends AbstractProvider {
240259 } ) ;
241260 }
242261
243- private _getLaunchConfiguration ( debugType : string , fileName : string , testMethod : string , testFrameworkName : string , debugEventListener : DebugEventListener ) : Promise < any > {
262+ private _getLaunchConfiguration ( debugType : string , fileName : string , testMethod : string , testFrameworkName : string , targetFrameworkVersion : string , debugEventListener : DebugEventListener ) : Promise < any > {
244263 switch ( debugType ) {
245264 case 'legacy' :
246- return this . _getLaunchConfigurationForLegacy ( fileName , testMethod , testFrameworkName ) ;
265+ return this . _getLaunchConfigurationForLegacy ( fileName , testMethod , testFrameworkName , targetFrameworkVersion ) ;
247266 case 'vstest' :
248- return this . _getLaunchConfigurationForVSTest ( fileName , testMethod , testFrameworkName , debugEventListener ) ;
267+ return this . _getLaunchConfigurationForVSTest ( fileName , testMethod , testFrameworkName , targetFrameworkVersion , debugEventListener ) ;
249268
250269 default :
251270 throw new Error ( `Unexpected debug type: ${ debugType } ` ) ;
@@ -257,6 +276,7 @@ export default class TestManager extends AbstractProvider {
257276 // using VS Test. These require a different level of communication.
258277 let debugType : string ;
259278 let debugEventListener : DebugEventListener = null ;
279+ let targetFrameworkVersion : string ;
260280
261281 const output = this . _getOutputChannel ( ) ;
262282
@@ -270,18 +290,20 @@ export default class TestManager extends AbstractProvider {
270290 . then ( projectInfo => {
271291 if ( projectInfo . DotNetProject ) {
272292 debugType = 'legacy' ;
293+ targetFrameworkVersion = '' ;
273294 return Promise . resolve ( ) ;
274295 }
275296 else if ( projectInfo . MsBuildProject ) {
276297 debugType = 'vstest' ;
298+ targetFrameworkVersion = projectInfo . MsBuildProject . TargetFramework ;
277299 debugEventListener = new DebugEventListener ( fileName , this . _server , output ) ;
278300 return debugEventListener . start ( ) ;
279301 }
280302 else {
281303 throw new Error ( 'Expected project.json or .csproj project.' ) ;
282304 }
283305 } )
284- . then ( ( ) => this . _getLaunchConfiguration ( debugType , fileName , testMethod , testFrameworkName , debugEventListener ) )
306+ . then ( ( ) => this . _getLaunchConfiguration ( debugType , fileName , testMethod , testFrameworkName , targetFrameworkVersion , debugEventListener ) )
285307 . then ( config => vscode . commands . executeCommand ( 'vscode.startDebug' , config ) )
286308 . catch ( reason => {
287309 vscode . window . showErrorMessage ( `Failed to start debugger: ${ reason } ` ) ;
0 commit comments