@@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests;
1515
1616public sealed class RunFileTests ( ITestOutputHelper log ) : SdkTest ( log )
1717{
18- private static readonly string s_program = """
18+ private static readonly string s_program = /* lang=C#-Test */ """
1919 if (args.Length > 0)
2020 {
2121 Console.WriteLine("echo args:" + string.Join(";", args));
@@ -29,15 +29,15 @@ public sealed class RunFileTests(ITestOutputHelper log) : SdkTest(log)
2929 #endif
3030 """ ;
3131
32- private static readonly string s_programDependingOnUtil = """
32+ private static readonly string s_programDependingOnUtil = /* lang=C#-Test */ """
3333 if (args.Length > 0)
3434 {
3535 Console.WriteLine("echo args:" + string.Join(";", args));
3636 }
3737 Console.WriteLine("Hello, " + Util.GetMessage());
3838 """ ;
3939
40- private static readonly string s_util = """
40+ private static readonly string s_util = /* lang=C#-Test */ """
4141 static class Util
4242 {
4343 public static string GetMessage()
@@ -47,6 +47,29 @@ public static string GetMessage()
4747 }
4848 """ ;
4949
50+ private static readonly string s_programReadingEmbeddedResource = /* lang=C#-Test */ """
51+ var assembly = System.Reflection.Assembly.GetExecutingAssembly();
52+ var resourceName = assembly.GetManifestResourceNames().SingleOrDefault();
53+
54+ if (resourceName is null)
55+ {
56+ Console.WriteLine("Resource not found");
57+ return;
58+ }
59+
60+ using var stream = assembly.GetManifestResourceStream(resourceName)!;
61+ using var reader = new System.Resources.ResourceReader(stream);
62+ Console.WriteLine(reader.Cast<System.Collections.DictionaryEntry>().Single());
63+ """ ;
64+
65+ private static readonly string s_resx = """
66+ <root>
67+ <data name="MyString">
68+ <value>TestValue</value>
69+ </data>
70+ </root>
71+ """ ;
72+
5073 private static readonly string s_consoleProject = $ """
5174 <Project Sdk="Microsoft.NET.Sdk">
5275 <PropertyGroup>
@@ -1062,26 +1085,8 @@ public void BinaryLog_EvaluationData()
10621085 public void EmbeddedResource ( )
10631086 {
10641087 var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1065- string code = """
1066- using var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Program.Resources.resources");
1067-
1068- if (stream is null)
1069- {
1070- Console.WriteLine("Resource not found");
1071- return;
1072- }
1073-
1074- using var reader = new System.Resources.ResourceReader(stream);
1075- Console.WriteLine(reader.Cast<System.Collections.DictionaryEntry>().Single());
1076- """ ;
1077- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
1078- File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , """
1079- <root>
1080- <data name="MyString">
1081- <value>TestValue</value>
1082- </data>
1083- </root>
1084- """ ) ;
1088+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
1089+ File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
10851090
10861091 new DotnetCommand ( Log , "run" , "Program.cs" )
10871092 . WithWorkingDirectory ( testInstance . Path )
@@ -1094,7 +1099,7 @@ public void EmbeddedResource()
10941099 // This behavior can be overridden.
10951100 File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
10961101 #:property EnableDefaultEmbeddedResourceItems=false
1097- { code }
1102+ { s_programReadingEmbeddedResource }
10981103 """ ) ;
10991104
11001105 new DotnetCommand ( Log , "run" , "Program.cs" )
@@ -1106,6 +1111,27 @@ Resource not found
11061111 """ ) ;
11071112 }
11081113
1114+ /// <summary>
1115+ /// Scripts in repo root should not include <c>.resx</c> files.
1116+ /// Part of <see href="https://github.com/dotnet/sdk/issues/49826"/>.
1117+ /// </summary>
1118+ [ Fact ]
1119+ public void EmbeddedResource_AlongsideSln ( )
1120+ {
1121+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1122+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
1123+ File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
1124+ File . WriteAllText ( Path . Join ( testInstance . Path , "repo.sln" ) , "" ) ;
1125+
1126+ new DotnetCommand ( Log , "run" , "Program.cs" )
1127+ . WithWorkingDirectory ( testInstance . Path )
1128+ . Execute ( )
1129+ . Should ( ) . Pass ( )
1130+ . And . HaveStdOut ( """
1131+ Resource not found
1132+ """ ) ;
1133+ }
1134+
11091135 [ Fact ]
11101136 public void NoRestore_01 ( )
11111137 {
@@ -2660,6 +2686,7 @@ public void Api()
26602686 <Nullable>enable</Nullable>
26612687 <PublishAot>true</PublishAot>
26622688 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2689+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
26632690 <TargetFramework>net11.0</TargetFramework>
26642691 <LangVersion>preview</LangVersion>
26652692 <Features>$(Features);FileBasedProgram</Features>
@@ -2730,6 +2757,7 @@ public void Api_Diagnostic_01()
27302757 <Nullable>enable</Nullable>
27312758 <PublishAot>true</PublishAot>
27322759 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2760+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
27332761 <Features>$(Features);FileBasedProgram</Features>
27342762 </PropertyGroup>
27352763
@@ -2797,6 +2825,7 @@ public void Api_Diagnostic_02()
27972825 <Nullable>enable</Nullable>
27982826 <PublishAot>true</PublishAot>
27992827 <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2828+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
28002829 <Features>$(Features);FileBasedProgram</Features>
28012830 </PropertyGroup>
28022831
0 commit comments