@@ -15,7 +15,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests;
15
15
16
16
public sealed class RunFileTests ( ITestOutputHelper log ) : SdkTest ( log )
17
17
{
18
- private static readonly string s_program = """
18
+ private static readonly string s_program = /* lang=C#-Test */ """
19
19
if (args.Length > 0)
20
20
{
21
21
Console.WriteLine("echo args:" + string.Join(";", args));
@@ -29,15 +29,15 @@ public sealed class RunFileTests(ITestOutputHelper log) : SdkTest(log)
29
29
#endif
30
30
""" ;
31
31
32
- private static readonly string s_programDependingOnUtil = """
32
+ private static readonly string s_programDependingOnUtil = /* lang=C#-Test */ """
33
33
if (args.Length > 0)
34
34
{
35
35
Console.WriteLine("echo args:" + string.Join(";", args));
36
36
}
37
37
Console.WriteLine("Hello, " + Util.GetMessage());
38
38
""" ;
39
39
40
- private static readonly string s_util = """
40
+ private static readonly string s_util = /* lang=C#-Test */ """
41
41
static class Util
42
42
{
43
43
public static string GetMessage()
@@ -47,6 +47,29 @@ public static string GetMessage()
47
47
}
48
48
""" ;
49
49
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
+
50
73
private static readonly string s_consoleProject = $ """
51
74
<Project Sdk="Microsoft.NET.Sdk">
52
75
<PropertyGroup>
@@ -1075,26 +1098,8 @@ public void BinaryLog_EvaluationData()
1075
1098
public void EmbeddedResource ( )
1076
1099
{
1077
1100
var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1078
- string code = """
1079
- using var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Program.Resources.resources");
1080
-
1081
- if (stream is null)
1082
- {
1083
- Console.WriteLine("Resource not found");
1084
- return;
1085
- }
1086
-
1087
- using var reader = new System.Resources.ResourceReader(stream);
1088
- Console.WriteLine(reader.Cast<System.Collections.DictionaryEntry>().Single());
1089
- """ ;
1090
- File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , code ) ;
1091
- File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , """
1092
- <root>
1093
- <data name="MyString">
1094
- <value>TestValue</value>
1095
- </data>
1096
- </root>
1097
- """ ) ;
1101
+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
1102
+ File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
1098
1103
1099
1104
new DotnetCommand ( Log , "run" , "Program.cs" )
1100
1105
. WithWorkingDirectory ( testInstance . Path )
@@ -1107,7 +1112,7 @@ public void EmbeddedResource()
1107
1112
// This behavior can be overridden.
1108
1113
File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , $ """
1109
1114
#:property EnableDefaultEmbeddedResourceItems=false
1110
- { code }
1115
+ { s_programReadingEmbeddedResource }
1111
1116
""" ) ;
1112
1117
1113
1118
new DotnetCommand ( Log , "run" , "Program.cs" )
@@ -1119,6 +1124,27 @@ Resource not found
1119
1124
""" ) ;
1120
1125
}
1121
1126
1127
+ /// <summary>
1128
+ /// Scripts in repo root should not include <c>.resx</c> files.
1129
+ /// Part of <see href="https://github.com/dotnet/sdk/issues/49826"/>.
1130
+ /// </summary>
1131
+ [ Theory , CombinatorialData ]
1132
+ public void EmbeddedResource_AlongsideProj ( [ CombinatorialValues ( "sln" , "slnx" , "csproj" , "vbproj" , "shproj" , "proj" ) ] string ext )
1133
+ {
1134
+ bool considered = ext is "sln" or "slnx" or "csproj" ;
1135
+
1136
+ var testInstance = _testAssetsManager . CreateTestDirectory ( ) ;
1137
+ File . WriteAllText ( Path . Join ( testInstance . Path , "Program.cs" ) , s_programReadingEmbeddedResource ) ;
1138
+ File . WriteAllText ( Path . Join ( testInstance . Path , "Resources.resx" ) , s_resx ) ;
1139
+ File . WriteAllText ( Path . Join ( testInstance . Path , $ "repo.{ ext } ") , "" ) ;
1140
+
1141
+ new DotnetCommand ( Log , "run" , "--file" , "Program.cs" )
1142
+ . WithWorkingDirectory ( testInstance . Path )
1143
+ . Execute ( )
1144
+ . Should ( ) . Pass ( )
1145
+ . And . HaveStdOut ( considered ? "Resource not found" : "[MyString, TestValue]" ) ;
1146
+ }
1147
+
1122
1148
[ Fact ]
1123
1149
public void NoRestore_01 ( )
1124
1150
{
@@ -2674,6 +2700,7 @@ public void Api()
2674
2700
<Nullable>enable</Nullable>
2675
2701
<PublishAot>true</PublishAot>
2676
2702
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2703
+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
2677
2704
<TargetFramework>net11.0</TargetFramework>
2678
2705
<LangVersion>preview</LangVersion>
2679
2706
<Features>$(Features);FileBasedProgram</Features>
@@ -2741,6 +2768,7 @@ public void Api_Diagnostic_01()
2741
2768
<Nullable>enable</Nullable>
2742
2769
<PublishAot>true</PublishAot>
2743
2770
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2771
+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
2744
2772
<Features>$(Features);FileBasedProgram</Features>
2745
2773
</PropertyGroup>
2746
2774
@@ -2805,6 +2833,7 @@ public void Api_Diagnostic_02()
2805
2833
<Nullable>enable</Nullable>
2806
2834
<PublishAot>true</PublishAot>
2807
2835
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
2836
+ <DisableDefaultItemsInProjectFolder>true</DisableDefaultItemsInProjectFolder>
2808
2837
<Features>$(Features);FileBasedProgram</Features>
2809
2838
</PropertyGroup>
2810
2839
0 commit comments