Skip to content

Commit c0d1df5

Browse files
committed
Support .NET 10 single file projectless compile
1 parent 3483880 commit c0d1df5

File tree

6 files changed

+114
-18
lines changed

6 files changed

+114
-18
lines changed

snippets5000/PullRequestSimulations/PullRequestSimulations.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77

@@ -16,9 +16,9 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
20-
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
21-
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
19+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
20+
<PackageReference Include="MSTest.TestAdapter" Version="3.9.3" />
21+
<PackageReference Include="MSTest.TestFramework" Version="3.9.3" />
2222
</ItemGroup>
2323

2424
<ItemGroup>

snippets5000/PullRequestSimulations/data.json

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,21 @@
1414
// as there isn't a difference between them.
1515

1616
// GOOD items
17+
{
18+
"Name": "Edit - Single file no project - Compile",
19+
"ExpectedResults": [
20+
{
21+
"ResultCode": 0,
22+
"DiscoveredProject": "snippets/good/normal/single_code_file/Now.cs"
23+
}
24+
],
25+
"Items": [
26+
{
27+
"ItemType": "Edit",
28+
"Path": "snippets/good/normal/single_code_file/Now.cs"
29+
}
30+
]
31+
},
1732
{
1833
"Name": "Edit - Single file find project C#",
1934
"ExpectedResults": [
@@ -151,6 +166,21 @@
151166
}
152167
]
153168
},
169+
{
170+
"Name": "Delete - Single file find project C#",
171+
"ExpectedResults": [
172+
{
173+
"ResultCode": 0,
174+
"DiscoveredProject": "snippets/good/normal/csharp_project/app1.csproj"
175+
}
176+
],
177+
"Items": [
178+
{
179+
"ItemType": "Delete",
180+
"Path": "snippets/good/normal/csharp_project/DeletedFile.cs"
181+
}
182+
]
183+
},
154184
{
155185
"Name": "Delete - All files, artifact remains in folder",
156186
"ExpectedResults": [
@@ -285,7 +315,7 @@
285315
"Items": [
286316
{
287317
"ItemType": "Edit",
288-
"Path": "snippets/bad/nullablepatternmatching/Program.cs"
318+
"Path": "snippets/bad/nullablepatternmatching/childwithcode/Program.cs"
289319
}
290320
]
291321
},
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// <SnippetPatternMatchingNullable>
2+
int i = 5;
3+
PatternMatchingNullable(i);
4+
5+
int? j = null;
6+
PatternMatchingNullable(j);
7+
8+
double d = 9.78654;
9+
PatternMatchingNullable(d);
10+
11+
PatternMatchingSwitch(i);
12+
PatternMatchingSwitch(j);
13+
PatternMatchingSwitch(d);
14+
15+
static void PatternMatchingNullable(ValueType? val)
16+
{
17+
if (val is int j) // Nullable types are not allowed in patterns
18+
{
19+
Console.WriteLine(j);
20+
}
21+
else if (val is null) // If val is a nullable type with no value, this expression is true
22+
{
23+
Console.WriteLine("val is a nullable type with the null value");
24+
}
25+
else
26+
{
27+
Console.WriteLine("Could not convert " + val.ToString());
28+
}
29+
}
30+
31+
static void PatternMatchingSwitch(ValueType? val)
32+
{
33+
switch (val)
34+
{
35+
case int number:
36+
Console.WriteLine(number);
37+
break;
38+
case long number:
39+
Console.WriteLine(number);
40+
break;
41+
case decimal number:
42+
Console.WriteLine(number);
43+
break;
44+
case float number:
45+
Console.WriteLine(number);
46+
break;
47+
case double number:
48+
Console.WriteLine(number);
49+
break;
50+
case null:
51+
Console.WriteLine("val is a nullable type with the null value");
52+
break;
53+
default:
54+
Console.WriteLine("Could not convert " + val.ToString());
55+
break;
56+
}
57+
}
58+
// </SnippetPatternMatchingNullable>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/local/share/dotnet/dotnet run
2+
Console.WriteLine2("Now: " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

snippets5000/Snippets5000/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text.Json;
55
using static Snippets5000.SnippetsConfigFile;
66
using Log = DotNet.DocsTools.Utility.EchoLogging;
7+
using DotNet.DocsTools.Utility;
78

89
[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("PullRequestSimulations")]
910

@@ -337,6 +338,7 @@ void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) =>
337338
config.RunOutput = config.RunOutput.Trim();
338339
Log.Write(2, $"Output:");
339340
Log.Write(4, config.RunOutput.Replace("\n", $"\n{Log.Ind(4)}"));
341+
Log.Write(4, $"Exit code: {config.RunExitCode}");
340342
}
341343

342344
Log.EndGroup();

snippets5000/Snippets5000/PullRequestProcessor.cs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,25 @@ private async IAsyncEnumerable<DiscoveryResult> FindAllSolutionsAndProjects(stri
116116
if (project != null)
117117
project = TransformPathToUnix(rootDir, project);
118118

119+
// If the file is a CSharp code file and it's running on .NET 10 or greater, support single file compilation
120+
bool isCSFile = item.EndsWith(".cs", StringComparison.OrdinalIgnoreCase);
121+
119122
// Process the condition checks to see if this item is valid or not
120-
return (project, countOfSln, countOfProjs, countOfCode, countOfSpecial, itemWasDeleted, allProjectsFoundInSln) switch
123+
return (project, countOfSln, countOfProjs, countOfCode, countOfSpecial, itemWasDeleted, allProjectsFoundInSln, isCSFile) switch
121124
{
122-
// Proj File, Sln#, Proj#, Code#, Spec#, Del, SlnHasPrj
123-
/* File del, no code/proj */ (null, 0, 0, 0, 0, true, _) => null,
124-
/* Too many solutions */ (not null, > 1, _, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_TOOMANY, item, project),
125-
/* Too many projs */ (not null, 0, > 1, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_TOOMANY, item, project),
126-
/* SLN found */ (not null, 1, > 0, _, _, _, true) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
127-
/* SLN found, missing proj */ (not null, 1, > 0, _, _, _, false) => new DiscoveryResult(DiscoveryResult.RETURN_SLN_PROJ_MISSING, item, project),
128-
/* SLN found no projs */ (not null, 1, 0, _, _, false, _) => new DiscoveryResult(DiscoveryResult.RETURN_SLN_NOPROJ, item, project),
129-
/* SLN found no projs, del */ (not null, 1, 0, _, _, true, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
130-
/* Project found */ (not null, 0, 1, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
131-
/* Code no proj */ (null, 0, 0, > 0, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, ""),
132-
/* Code no proj */ (null, 0, 0, _, > 0, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, ""),
133-
/* catch all */ _ => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, "CONDITION NOT FOUND"),
125+
// Proj File, Sln#, Proj#, Code#, Spec#, Del, SlnHasPrj, IsCSfile
126+
/* File del, no code/proj */ (null, 0, 0, 0, 0, true, _, _) => null,
127+
/* Too many solutions */ (not null, > 1, _, _, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_TOOMANY, item, project),
128+
/* Too many projs */ (not null, 0, > 1, _, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_TOOMANY, item, project),
129+
/* SLN found */ (not null, 1, > 0, _, _, _, true, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
130+
/* SLN found, missing proj */ (not null, 1, > 0, _, _, _, false, _) => new DiscoveryResult(DiscoveryResult.RETURN_SLN_PROJ_MISSING, item, project),
131+
/* SLN found no projs */ (not null, 1, 0, _, _, false, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_SLN_NOPROJ, item, project),
132+
/* SLN found no projs, del */ (not null, 1, 0, _, _, true, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
133+
/* Project found */ (not null, 0, 1, _, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, project),
134+
/* Single .cs file compile */ (null, 0, 0, 1, _, _, _, true) => new DiscoveryResult(DiscoveryResult.RETURN_GOOD, item, item),
135+
/* Code no proj */ (null, 0, 0, > 0, _, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, ""),
136+
/* Code no proj */ (null, 0, 0, _, > 0, _, _, _) => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, ""),
137+
/* catch all */ _ => new DiscoveryResult(DiscoveryResult.RETURN_NOPROJ, item, "CONDITION NOT FOUND"),
134138
};
135139
}
136140

0 commit comments

Comments
 (0)