@@ -1364,7 +1364,7 @@ public void Verbosity_CompilationDiagnostics()
13641364 }
13651365
13661366 /// <summary>
1367- /// Default projects include embedded resources by default.
1367+ /// File-based projects using the default SDK do not include embedded resources by default.
13681368 /// </summary>
13691369 [ Fact ]
13701370 public void EmbeddedResource ( )
@@ -1373,6 +1373,21 @@ public void EmbeddedResource()
13731373 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
13741374 File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
13751375
1376+ // By default, with the default SDK, embedded resources are not included.
1377+ new DotnetCommand ( Log , "run" , "Program.cs" )
1378+ . WithWorkingDirectory ( testInstance . Path )
1379+ . Execute ( )
1380+ . Should ( ) . Pass ( )
1381+ . And . HaveStdOut ( """
1382+ Resource not found
1383+ """ ) ;
1384+
1385+ // This behavior can be overridden to enable embedded resources.
1386+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1387+ #:property EnableDefaultEmbeddedResourceItems=true
1388+ { s_programReadingEmbeddedResource }
1389+ """ ) ;
1390+
13761391 new DotnetCommand ( Log , "run" , "Program.cs" )
13771392 . WithWorkingDirectory ( testInstance . Path )
13781393 . Execute ( )
@@ -1381,9 +1396,23 @@ public void EmbeddedResource()
13811396 [MyString, TestValue]
13821397 """ ) ;
13831398
1384- // This behavior can be overridden .
1399+ // When using a non-default SDK, embedded resources are included by default .
13851400 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1386- #:property EnableDefaultEmbeddedResourceItems=false
1401+ #:sdk Microsoft.NET.Sdk.Web
1402+ { s_programReadingEmbeddedResource }
1403+ """ ) ;
1404+
1405+ new DotnetCommand ( Log , "run" , "Program.cs" )
1406+ . WithWorkingDirectory ( testInstance . Path )
1407+ . Execute ( )
1408+ . Should ( ) . Pass ( )
1409+ . And . HaveStdOut ( """
1410+ [MyString, TestValue]
1411+ """ ) ;
1412+
1413+ // When using the default SDK explicitly, embedded resources are not included.
1414+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1415+ #:sdk Microsoft.NET.Sdk
13871416 { s_programReadingEmbeddedResource }
13881417 """ ) ;
13891418
@@ -1406,7 +1435,10 @@ public void EmbeddedResource_AlongsideProj([CombinatorialValues("sln", "slnx", "
14061435 bool considered = ext is "sln" or "slnx" or "csproj" ;
14071436
14081437 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1409- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
1438+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1439+ #:property EnableDefaultEmbeddedResourceItems=true
1440+ { s_programReadingEmbeddedResource }
1441+ """ ) ;
14101442 File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
14111443 File . WriteAllText ( Path . Join ( testInstance . Path , $ "repo.{ ext } ") , "" ) ;
14121444
@@ -3152,6 +3184,7 @@ public void UpToDate_DefaultItems(bool optOut)
31523184 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
31533185 var code = $ """
31543186 { ( optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "" ) }
3187+ #:property EnableDefaultEmbeddedResourceItems=true
31553188 { s_programReadingEmbeddedResource }
31563189 """ ;
31573190 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
@@ -3172,50 +3205,20 @@ public void UpToDate_DefaultItems(bool optOut)
31723205 Build ( testInstance , BuildLevel . All , [ "--no-cache" ] , expectedOutput : "[MyString, UpdatedValue]" ) ;
31733206 }
31743207
3175- /// <summary>
3176- /// Combination of <see cref="UpToDate_DefaultItems"/> with <see cref="CscOnly"/> optimization.
3177- /// </summary>
3178- [ Theory , CombinatorialData ] // https://github.com/dotnet/sdk/issues/50912
3179- public void UpToDate_DefaultItems_CscOnly ( bool optOut )
3180- {
3181- var testInstance = _testAssetsManager . CreateTestDirectory ( baseDirectory : OutOfTreeBaseDirectory ) ;
3182- var code = $ """
3183- { ( optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "" ) }
3184- { s_programReadingEmbeddedResource }
3185- """ ;
3186- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
3187- File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
3188-
3189- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . Csc , expectedOutput : optOut ? "[MyString, TestValue]" : "Resource not found" ) ;
3190-
3191- // Update the RESX file.
3192- File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx . Replace ( "TestValue" , "UpdatedValue" ) ) ;
3193-
3194- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . None , expectedOutput : optOut ? "[MyString, UpdatedValue]" : "Resource not found" ) ;
3195-
3196- // Update the C# file.
3197- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , "//v2\n " + code ) ;
3198-
3199- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . Csc , expectedOutput : optOut ? "[MyString, UpdatedValue]" : "Resource not found" ) ;
3200-
3201- Build ( testInstance , BuildLevel . All , [ "--no-cache" ] , expectedOutput : "[MyString, UpdatedValue]" ) ;
3202-
3203- // Update the C# file.
3204- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , "//v3\n " + code ) ;
3205-
3206- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . Csc , expectedOutput : "[MyString, UpdatedValue]" ) ;
3207- }
3208-
32093208 /// <summary>
32103209 /// Combination of <see cref="UpToDate_DefaultItems"/> with <see cref="CscOnly_AfterMSBuild"/> optimization.
32113210 /// </summary>
3211+ /// <remarks>
3212+ /// Note: we cannot test <see cref="CscOnly"/> because that optimization doesn't support neither <c>#:property</c> nor <c>#:sdk</c> which we need to enable default items.
3213+ /// </remarks>
32123214 [ Theory , CombinatorialData ] // https://github.com/dotnet/sdk/issues/50912
32133215 public void UpToDate_DefaultItems_CscOnly_AfterMSBuild ( bool optOut )
32143216 {
32153217 var testInstance = _testAssetsManager . CreateTestDirectory ( baseDirectory : OutOfTreeBaseDirectory ) ;
32163218 var code = $ """
32173219 #:property Configuration=Release
32183220 { ( optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "" ) }
3221+ #:property EnableDefaultEmbeddedResourceItems=true
32193222 { s_programReadingEmbeddedResource }
32203223 """ ;
32213224 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
@@ -3897,6 +3900,8 @@ public void Api_Diagnostic_01()
38973900 <FileBasedProgram>true</FileBasedProgram>
38983901 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
38993902 <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3903+ <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
3904+ <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
39003905 <OutputType>Exe</OutputType>
39013906 <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
39023907 <ImplicitUsings>enable</ImplicitUsings>
@@ -3965,6 +3970,8 @@ public void Api_Diagnostic_02()
39653970 <FileBasedProgram>true</FileBasedProgram>
39663971 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
39673972 <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3973+ <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
3974+ <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
39683975 <OutputType>Exe</OutputType>
39693976 <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
39703977 <ImplicitUsings>enable</ImplicitUsings>
0 commit comments