Skip to content

Commit 3cf50ce

Browse files
authored
Move to .NET 10 SDK, add test coverage for net10 TFM (#1562)
1 parent 8e6314f commit 3cf50ce

15 files changed

Lines changed: 68 additions & 25 deletions

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
</PropertyGroup>
4848

4949
<PropertyGroup>
50-
<LangVersion Condition="'$(MSBuildProjectExtension)'=='.csproj'">13</LangVersion>
50+
<LangVersion Condition="'$(MSBuildProjectExtension)'=='.csproj'">14</LangVersion>
5151
<LangVersion Condition="'$(MSBuildProjectExtension)'=='.vbproj'">16.9</LangVersion>
5252
</PropertyGroup>
5353

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<WDKMetadataVersion>0.13.25-experimental</WDKMetadataVersion>
1111
<!-- <DiaMetadataVersion>0.2.185-preview-g7e1e6a442c</DiaMetadataVersion> -->
1212
<ApiDocsVersion>0.1.42-alpha</ApiDocsVersion>
13-
<CodeAnalysisVersion>4.14.0</CodeAnalysisVersion>
13+
<CodeAnalysisVersion>5.0.0</CodeAnalysisVersion>
1414
</PropertyGroup>
1515
<ItemGroup>
1616
<!-- We have to use the MessagePack version used by win32metadata (https://github.com/microsoft/CsWin32/issues/371) -->

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.306",
3+
"version": "10.0.100",
44
"rollForward": "patch",
55
"allowPrerelease": false
66
},

src/CsWin32Generator/CsWin32Generator.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<OutputType>Exe</OutputType>
66

77
<IsPackable>false</IsPackable>
8+
9+
<RollForward>Major</RollForward>
810
</PropertyGroup>
911

1012
<ItemGroup>

src/Microsoft.Windows.CsWin32/Generator.GeneratedCode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ internal GeneratedCode(GeneratedCode parent)
8282

8383
internal IEnumerable<MethodDeclarationSyntax> InlineArrayIndexerExtensions => this.inlineArrayIndexerExtensionsMembers;
8484

85-
internal IEnumerable<FieldDeclarationSyntax> TopLevelFields => from field in this.fieldsToSyntax.Values
86-
where field.FieldType is null || !this.types.ContainsKey((field.FieldType.Value, false))
87-
select field.FieldDeclaration;
85+
internal IEnumerable<FieldDeclarationSyntax> TopLevelFields => from @field in this.fieldsToSyntax.Values
86+
where @field.FieldType is null || !this.types.ContainsKey((@field.FieldType.Value, false))
87+
select @field.FieldDeclaration;
8888

8989
internal IEnumerable<IGrouping<string, MemberDeclarationSyntax>> MembersByModule
9090
{

src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,14 @@
4848
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" GeneratePathProperty="true" PrivateAssets="none" />
4949
<PackageReference Include="Microsoft.Windows.SDK.Win32Docs" GeneratePathProperty="true" PrivateAssets="none" />
5050
<PackageReference Include="Microsoft.Windows.WDK.Win32Metadata" GeneratePathProperty="true" PrivateAssets="none" />
51-
<PackageReference Include="System.Memory" PrivateAssets="none" />
5251
<PackageReference Include="System.Reflection.Metadata" />
5352
<PackageReference Include="System.Text.Encodings.Web" />
5453
<PackageReference Include="System.Text.Json" />
5554
</ItemGroup>
5655

56+
<ItemGroup Condition="'$(TargetFramework)'=='net472'">
57+
<PackageReference Include="System.Memory" PrivateAssets="none" />
58+
</ItemGroup>
59+
5760
<Import Project="$(MSBuildProjectName).targets" />
5861
</Project>

test/CsWin32Generator.Tests/CsWin32GeneratorTests.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,14 @@ private async Task VerifySignatureWorker(string api, string member, string signa
302302

303303
[Theory]
304304
[MemberData(nameof(TestApiData))]
305-
public async Task TestGenerateApi(string api, string purpose, TestOptions options = TestOptions.None, string? nativeMethodsJson = null)
305+
public async Task TestGenerateApiNet10(string api, string purpose, TestOptions options = TestOptions.None, string? nativeMethodsJson = null)
306+
{
307+
await this.TestGenerateApiWorker(api, purpose, options, "net10.0", nativeMethodsJson);
308+
}
309+
310+
[Theory]
311+
[MemberData(nameof(TestApiData))]
312+
public async Task TestGenerateApiNet9(string api, string purpose, TestOptions options = TestOptions.None, string? nativeMethodsJson = null)
306313
{
307314
await this.TestGenerateApiWorker(api, purpose, options, "net9.0", nativeMethodsJson);
308315
}
@@ -316,7 +323,13 @@ public async Task TestGenerateApiNet8(string api, string purpose, TestOptions op
316323

317324
private async Task TestGenerateApiWorker(string api, string purpose, TestOptions options, string tfm, string? nativeMethodsJson)
318325
{
319-
LanguageVersion langVersion = (tfm == "net8.0") ? LanguageVersion.CSharp12 : LanguageVersion.CSharp13;
326+
LanguageVersion langVersion = tfm switch
327+
{
328+
"net8.0" => LanguageVersion.CSharp12,
329+
"net9.0" => LanguageVersion.CSharp13,
330+
"net10.0" => LanguageVersion.CSharp14,
331+
_ => throw new InvalidOperationException(),
332+
};
320333

321334
this.tfm = tfm;
322335
this.compilation = this.starterCompilations[tfm];
@@ -553,7 +566,7 @@ public async Task VerifyOverloadPriorityAttributeInNet8(LanguageVersion langVers
553566
public async Task CrossWinMD_IInspectable(
554567
[CombinatorialValues([false, true])] bool allowMarshaling,
555568
[CombinatorialValues([null, "TestPInvoke"])] string pinvokeClassName,
556-
[CombinatorialValues(["net8.0", "net9.0"])] string tfm)
569+
[CombinatorialValues(["net8.0", "net9.0", "net10.0"])] string tfm)
557570
{
558571
this.compilation = this.starterCompilations[tfm];
559572
this.win32winmdPaths = [.. this.win32winmdPaths!, CustomIInspectableMetadataPath];

test/CsWin32Generator.Tests/CsWin32GeneratorTestsBase.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,7 @@ protected async Task CompileGeneratedFilesWithSourceGenerators(string outputPath
194194
syntaxTrees.Add(syntaxTree);
195195
}
196196

197-
bool canDisableRuntimeMarshalling = this.tfm is null ||
198-
this.tfm.StartsWith("net6.0", StringComparison.OrdinalIgnoreCase) ||
199-
this.tfm.StartsWith("net7.0", StringComparison.OrdinalIgnoreCase) ||
200-
this.tfm.StartsWith("net8.0", StringComparison.OrdinalIgnoreCase) ||
201-
this.tfm.StartsWith("net9.0", StringComparison.OrdinalIgnoreCase);
197+
bool canDisableRuntimeMarshalling = this.tfm is not "net472";
202198

203199
if (canDisableRuntimeMarshalling)
204200
{
@@ -268,14 +264,17 @@ protected async Task CompileGeneratedFilesWithSourceGenerators(string outputPath
268264
var analyzerDiagnostics = await compilationWithAnalyzers.GetAllDiagnosticsAsync();
269265

270266
var filteredAnalyzerDiagnostics = analyzerDiagnostics.Where(d =>
271-
d.Descriptor.Id switch {
267+
d.Descriptor.Id switch
268+
{
272269
"CA1016" or
273270
"SA1517" or
274271
"SA1633" or
275272
"CS1701" or
276273
"CA1418" or // Ignore bad platforms coming from win32metadata like "windowsserver2008"
277274
"CS0465" // IMFSinkWriterEx has a "Finalize" method
278-
=> false, _ => true, });
275+
=> false,
276+
_ => true,
277+
});
279278

280279
allDiagnostics.AddRange(filteredAnalyzerDiagnostics);
281280

test/CsWin32User.props

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
<ItemGroup>
1616
<PackageReference Include="Microsoft.Windows.SDK.Win32Metadata" GeneratePathProperty="true" PrivateAssets="none" />
1717
<!-- <PackageReference Include="Microsoft.Dia.Win32Metadata" PrivateAssets="none" /> -->
18-
<PackageReference Include="System.Memory" />
1918
</ItemGroup>
2019

20+
<ItemGroup Condition="'$(TargetFramework)'=='net472'">
21+
<PackageReference Include="System.Memory" />
22+
</ItemGroup>
23+
2124
</Project>

test/GenerationSandbox.BuildTask.Tests/GenerationSandbox.BuildTask.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>net9.0-windows10.0.22621.0</TargetFrameworks>
3+
<TargetFrameworks>net9.0-windows10.0.22621.0;net10.0-windows10.0.22621.0</TargetFrameworks>
44
</PropertyGroup>
55

66
<Import Project="..\GenerationSandbox.props" />
@@ -12,7 +12,7 @@
1212

1313
<!-- For browsing, add the .cs files as None items -->
1414
<ItemGroup>
15-
<None Include="$(IntermediateOutputPath)Generated\CsWin32\*.cs" LinkBase="Generated" />
16-
<None Include="$(IntermediateOutputPath)Generated\CsWin32\*.txt" LinkBase="Generated" />
15+
<None Include="$(IntermediateOutputPath)Generated\CsWin32\*.cs" LinkBase="Generated\$(TargetFramework)" />
16+
<None Include="$(IntermediateOutputPath)Generated\CsWin32\*.txt" LinkBase="Generated\$(TargetFramework)" />
1717
</ItemGroup>
1818
</Project>

0 commit comments

Comments
 (0)