@@ -1363,7 +1363,7 @@ public void Verbosity_CompilationDiagnostics()
13631363 }
13641364
13651365 /// <summary>
1366- /// Default projects include embedded resources by default.
1366+ /// File-based projects using the default SDK do not include embedded resources by default.
13671367 /// </summary>
13681368 [ Fact ]
13691369 public void EmbeddedResource ( )
@@ -1372,6 +1372,21 @@ public void EmbeddedResource()
13721372 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
13731373 File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
13741374
1375+ // By default, with the default SDK, embedded resources are not included.
1376+ new DotnetCommand ( Log , "run" , "Program.cs" )
1377+ . WithWorkingDirectory ( testInstance . Path )
1378+ . Execute ( )
1379+ . Should ( ) . Pass ( )
1380+ . And . HaveStdOut ( """
1381+ Resource not found
1382+ """ ) ;
1383+
1384+ // This behavior can be overridden to enable embedded resources.
1385+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1386+ #:property EnableDefaultEmbeddedResourceItems=true
1387+ { s_programReadingEmbeddedResource }
1388+ """ ) ;
1389+
13751390 new DotnetCommand ( Log , "run" , "Program.cs" )
13761391 . WithWorkingDirectory ( testInstance . Path )
13771392 . Execute ( )
@@ -1380,9 +1395,23 @@ public void EmbeddedResource()
13801395 [MyString, TestValue]
13811396 """ ) ;
13821397
1383- // This behavior can be overridden .
1398+ // When using a non-default SDK, embedded resources are included by default .
13841399 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1385- #:property EnableDefaultEmbeddedResourceItems=false
1400+ #:sdk Microsoft.NET.Sdk.Web
1401+ { s_programReadingEmbeddedResource }
1402+ """ ) ;
1403+
1404+ new DotnetCommand ( Log , "run" , "Program.cs" )
1405+ . WithWorkingDirectory ( testInstance . Path )
1406+ . Execute ( )
1407+ . Should ( ) . Pass ( )
1408+ . And . HaveStdOut ( """
1409+ [MyString, TestValue]
1410+ """ ) ;
1411+
1412+ // When using the default SDK explicitly, embedded resources are not included.
1413+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1414+ #:sdk Microsoft.NET.Sdk
13861415 { s_programReadingEmbeddedResource }
13871416 """ ) ;
13881417
@@ -1405,7 +1434,10 @@ public void EmbeddedResource_AlongsideProj([CombinatorialValues("sln", "slnx", "
14051434 bool considered = ext is "sln" or "slnx" or "csproj" ;
14061435
14071436 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1408- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
1437+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1438+ #:property EnableDefaultEmbeddedResourceItems=true
1439+ { s_programReadingEmbeddedResource }
1440+ """ ) ;
14091441 File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
14101442 File . WriteAllText ( Path . Join ( testInstance . Path , $ "repo.{ ext } ") , "" ) ;
14111443
@@ -3147,6 +3179,7 @@ public void UpToDate_DefaultItems(bool optOut)
31473179 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
31483180 var code = $ """
31493181 { ( optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "" ) }
3182+ #:property EnableDefaultEmbeddedResourceItems=true
31503183 { s_programReadingEmbeddedResource }
31513184 """ ;
31523185 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
@@ -3167,50 +3200,20 @@ public void UpToDate_DefaultItems(bool optOut)
31673200 Build ( testInstance , BuildLevel . All , [ "--no-cache" ] , expectedOutput : "[MyString, UpdatedValue]" ) ;
31683201 }
31693202
3170- /// <summary>
3171- /// Combination of <see cref="UpToDate_DefaultItems"/> with <see cref="CscOnly"/> optimization.
3172- /// </summary>
3173- [ Theory , CombinatorialData ] // https://github.com/dotnet/sdk/issues/50912
3174- public void UpToDate_DefaultItems_CscOnly ( bool optOut )
3175- {
3176- var testInstance = _testAssetsManager . CreateTestDirectory ( baseDirectory : OutOfTreeBaseDirectory ) ;
3177- var code = $ """
3178- { ( optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "" ) }
3179- { s_programReadingEmbeddedResource }
3180- """ ;
3181- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
3182- File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
3183-
3184- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . Csc , expectedOutput : optOut ? "[MyString, TestValue]" : "Resource not found" ) ;
3185-
3186- // Update the RESX file.
3187- File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx . Replace ( "TestValue" , "UpdatedValue" ) ) ;
3188-
3189- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . None , expectedOutput : optOut ? "[MyString, UpdatedValue]" : "Resource not found" ) ;
3190-
3191- // Update the C# file.
3192- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , "//v2\n " + code ) ;
3193-
3194- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . Csc , expectedOutput : optOut ? "[MyString, UpdatedValue]" : "Resource not found" ) ;
3195-
3196- Build ( testInstance , BuildLevel . All , [ "--no-cache" ] , expectedOutput : "[MyString, UpdatedValue]" ) ;
3197-
3198- // Update the C# file.
3199- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , "//v3\n " + code ) ;
3200-
3201- Build ( testInstance , optOut ? BuildLevel . All : BuildLevel . Csc , expectedOutput : "[MyString, UpdatedValue]" ) ;
3202- }
3203-
32043203 /// <summary>
32053204 /// Combination of <see cref="UpToDate_DefaultItems"/> with <see cref="CscOnly_AfterMSBuild"/> optimization.
32063205 /// </summary>
3206+ /// <remarks>
3207+ /// 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.
3208+ /// </remarks>
32073209 [ Theory , CombinatorialData ] // https://github.com/dotnet/sdk/issues/50912
32083210 public void UpToDate_DefaultItems_CscOnly_AfterMSBuild ( bool optOut )
32093211 {
32103212 var testInstance = _testAssetsManager . CreateTestDirectory ( baseDirectory : OutOfTreeBaseDirectory ) ;
32113213 var code = $ """
32123214 #:property Configuration=Release
32133215 { ( optOut ? "#:property FileBasedProgramCanSkipMSBuild=false" : "" ) }
3216+ #:property EnableDefaultEmbeddedResourceItems=true
32143217 { s_programReadingEmbeddedResource }
32153218 """ ;
32163219 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
@@ -3861,6 +3864,8 @@ public void Api_Diagnostic_01()
38613864 <FileBasedProgram>true</FileBasedProgram>
38623865 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
38633866 <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3867+ <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
3868+ <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
38643869 <OutputType>Exe</OutputType>
38653870 <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
38663871 <ImplicitUsings>enable</ImplicitUsings>
@@ -3929,6 +3934,8 @@ public void Api_Diagnostic_02()
39293934 <FileBasedProgram>true</FileBasedProgram>
39303935 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
39313936 <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
3937+ <EnableDefaultEmbeddedResourceItems>false</EnableDefaultEmbeddedResourceItems>
3938+ <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
39323939 <OutputType>Exe</OutputType>
39333940 <TargetFramework>{ ToolsetInfo . CurrentTargetFramework } </TargetFramework>
39343941 <ImplicitUsings>enable</ImplicitUsings>
0 commit comments