@@ -422,6 +422,66 @@ public void SelfContainedExecutableCannotBeReferencedByNonSelfContainedMTPTestPr
422
422
result . Should ( ) . HaveStdOutContaining ( "NETSDK1151" ) . And . ExitWith ( 1 ) ;
423
423
}
424
424
425
+ [ Theory ]
426
+ [ CombinatorialData ]
427
+ public void MTPNonSelfContainedExecutableCannotBeReferencedBySelfContained ( bool setIsTestingPlatformApplicationEarly )
428
+ {
429
+ // The setup of this test is as follows:
430
+ // ConsoleApp is a self-contained executable project, which references a non-self-contained MTP executable test project.
431
+ // Building ConsoleApp should fail because it references a non-self-contained MTP executable project.
432
+ // A non self-contained executable cannot be referenced by a self-contained executable.
433
+ var testConsoleProjectSelfContained = new TestProject ( "ConsoleApp" )
434
+ {
435
+ IsExe = true ,
436
+ TargetFrameworks = ToolsetInfo . CurrentTargetFramework ,
437
+ SelfContained = "true" ,
438
+ } ;
439
+
440
+ var testAssetSelfContained = _testAssetsManager . CreateTestProject ( testConsoleProjectSelfContained ) ;
441
+
442
+ var mtpNotSelfContained = new TestProject ( "MTPTestProject" )
443
+ {
444
+ TargetFrameworks = ToolsetInfo . CurrentTargetFramework ,
445
+ IsExe = true ,
446
+ IsTestProject = true ,
447
+ } ;
448
+
449
+ if ( setIsTestingPlatformApplicationEarly )
450
+ {
451
+ mtpNotSelfContained . IsTestingPlatformApplication = true ;
452
+ }
453
+
454
+ var testAssetMTP = _testAssetsManager . CreateTestProject ( mtpNotSelfContained ) ;
455
+
456
+ var mtpProjectDirectory = Path . Combine ( testAssetMTP . Path , mtpNotSelfContained . Name ) ;
457
+ Assert . True ( Directory . Exists ( mtpProjectDirectory ) , $ "Expected directory { mtpProjectDirectory } to exist.") ;
458
+ Assert . True ( File . Exists ( Path . Combine ( mtpProjectDirectory , "MTPTestProject.csproj" ) ) , $ "Expected file MTPTestProject.csproj to exist in { mtpProjectDirectory } .") ;
459
+
460
+ if ( ! setIsTestingPlatformApplicationEarly )
461
+ {
462
+ File . WriteAllText ( Path . Combine ( mtpProjectDirectory , "Directory.Build.targets" ) , """
463
+ <Project>
464
+ <PropertyGroup>
465
+ <IsTestingPlatformApplication>true</IsTestingPlatformApplication>
466
+ </PropertyGroup>
467
+ </Project>
468
+ """ ) ;
469
+ }
470
+
471
+ var consoleAppDirectory = Path . Combine ( testAssetSelfContained . Path , testConsoleProjectSelfContained . Name ) ;
472
+ Assert . True ( Directory . Exists ( consoleAppDirectory ) , $ "Expected directory { consoleAppDirectory } to exist.") ;
473
+ Assert . True ( File . Exists ( Path . Combine ( consoleAppDirectory , "ConsoleApp.csproj" ) ) , $ "Expected file ConsoleApp.csproj to exist in { consoleAppDirectory } .") ;
474
+
475
+ new DotnetCommand ( Log , "add" , "reference" , Path . Combine ( testAssetMTP . Path , mtpNotSelfContained . Name ) )
476
+ . WithWorkingDirectory ( consoleAppDirectory )
477
+ . Execute ( )
478
+ . Should ( )
479
+ . Pass ( ) ;
480
+
481
+ var result = new BuildCommand ( Log , mtpProjectDirectory ) . Execute ( ) ;
482
+ result . Should ( ) . HaveStdOutContaining ( "NETSDK1150" ) . And . ExitWith ( 1 ) ;
483
+ }
484
+
425
485
[ RequiresMSBuildVersionTheory ( "17.0.0.32901" ) ]
426
486
[ InlineData ( "xunit" ) ]
427
487
[ InlineData ( "mstest" ) ]
0 commit comments