@@ -323,9 +323,10 @@ public void ReferencedExeCanRunWhenPublishedWithTrimming(bool referenceExeInCode
323
323
}
324
324
325
325
[ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
326
- [ InlineData ( "xunit" ) ]
327
- [ InlineData ( "mstest" ) ]
328
- public void TestProjectCanReferenceExe ( string testTemplateName )
326
+ [ CombinatorialData ]
327
+ public void TestProjectCanReferenceExe (
328
+ [ CombinatorialValues ( "xunit" , "mstest" ) ] string testTemplateName ,
329
+ bool setSelfContainedProperty )
329
330
{
330
331
var testConsoleProject = new TestProject ( "ConsoleApp" )
331
332
{
@@ -334,6 +335,11 @@ public void TestProjectCanReferenceExe(string testTemplateName)
334
335
RuntimeIdentifier = EnvironmentInfo . GetCompatibleRid ( )
335
336
} ;
336
337
338
+ if ( setSelfContainedProperty )
339
+ {
340
+ testConsoleProject . SelfContained = "true" ;
341
+ }
342
+
337
343
var testAsset = _testAssetsManager . CreateTestProject ( testConsoleProject , identifier : testTemplateName ) ;
338
344
339
345
var testProjectDirectory = Path . Combine ( testAsset . TestRoot , "TestProject" ) ;
@@ -359,6 +365,63 @@ public void TestProjectCanReferenceExe(string testTemplateName)
359
365
360
366
}
361
367
368
+ [ Theory ]
369
+ [ CombinatorialData ]
370
+ public void SelfContainedExecutableCannotBeReferencedByNonSelfContainedMTPTestProject ( bool setIsTestingPlatformApplicationEarly )
371
+ {
372
+ // The setup of this test is as follows:
373
+ // ConsoleApp is a self-contained executable project.
374
+ // MTPTestProject is an executable test project that references ConsoleApp.
375
+ // Building MTPTestProject should fail because it references a self-contained executable project.
376
+ // A self-contained executable cannot be referenced by a non self-contained executable.
377
+ var testConsoleProjectSelfContained = new TestProject ( "ConsoleApp" )
378
+ {
379
+ IsExe = true ,
380
+ TargetFrameworks = ToolsetInfo . CurrentTargetFramework ,
381
+ SelfContained = "true" ,
382
+ } ;
383
+
384
+ var testAssetSelfContained = _testAssetsManager . CreateTestProject ( testConsoleProjectSelfContained ) ;
385
+
386
+ var mtpNotSelfContained = new TestProject ( "MTPTestProject" )
387
+ {
388
+ TargetFrameworks = ToolsetInfo . CurrentTargetFramework ,
389
+ IsExe = true ,
390
+ IsTestProject = true ,
391
+ } ;
392
+
393
+ if ( setIsTestingPlatformApplicationEarly )
394
+ {
395
+ mtpNotSelfContained . IsTestingPlatformApplication = true ;
396
+ }
397
+
398
+ var testAssetMTP = _testAssetsManager . CreateTestProject ( mtpNotSelfContained ) ;
399
+
400
+ var mtpProjectDirectory = Path . Combine ( testAssetMTP . Path , "MTPTestProject" ) ;
401
+ Assert . True ( Directory . Exists ( mtpProjectDirectory ) , $ "Expected directory { mtpProjectDirectory } to exist.") ;
402
+ Assert . True ( File . Exists ( Path . Combine ( mtpProjectDirectory , "MTPTestProject.csproj" ) ) , $ "Expected file MTPTestProject.csproj to exist in { mtpProjectDirectory } .") ;
403
+
404
+ if ( ! setIsTestingPlatformApplicationEarly )
405
+ {
406
+ File . WriteAllText ( Path . Combine ( mtpProjectDirectory , "Directory.Build.targets" ) , """
407
+ <Project>
408
+ <PropertyGroup>
409
+ <IsTestingPlatformApplication>true</IsTestingPlatformApplication>
410
+ </PropertyGroup>
411
+ </Project>
412
+ """ ) ;
413
+ }
414
+
415
+ new DotnetCommand ( Log , "add" , "reference" , Path . Combine ( testAssetSelfContained . Path , testConsoleProjectSelfContained . Name ) )
416
+ . WithWorkingDirectory ( mtpProjectDirectory )
417
+ . Execute ( )
418
+ . Should ( )
419
+ . Pass ( ) ;
420
+
421
+ var result = new BuildCommand ( Log , mtpProjectDirectory ) . Execute ( ) ;
422
+ result . Should ( ) . HaveStdOutContaining ( "NETSDK1151" ) . And . ExitWith ( 1 ) ;
423
+ }
424
+
362
425
[ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
363
426
[ InlineData ( "xunit" ) ]
364
427
[ InlineData ( "mstest" ) ]
0 commit comments