Skip to content

Commit

Permalink
Add support for targeting .NET 9 (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
brantburnett authored Nov 29, 2024
1 parent ad35c08 commit 30cb61e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 26 deletions.
4 changes: 2 additions & 2 deletions scripts/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ for extension in "Yardarm.SystemTextJson" "Yardarm.NewtonsoftJson"; do
jsonext=src/artifacts/bin/$extension/release/$extension.dll

dotnet run --no-build --no-launch-profile -c Release --project src/main/Yardarm.CommandLine -- \
restore -n TestSTJ -x $jsonext $httpext -f netstandard2.0 net6.0 net8.0 --intermediate-dir ./obj/
restore -n TestSTJ -x $jsonext $httpext -f netstandard2.0 net6.0 net8.0 net9.0 --intermediate-dir ./obj/

dotnet run --no-build --no-launch-profile -c Release --project src/main/Yardarm.CommandLine -- \
generate --no-restore -n TestSTJ -x $jsonext $httpext -f netstandard2.0 net6.0 net8.0 --embed --intermediate-dir ./obj/ --nupkg ./bin/ -v 1.0.0 -i ./bin/mashtub.json
generate --no-restore -n TestSTJ -x $jsonext $httpext -f netstandard2.0 net6.0 net8.0 net9.0 --embed --intermediate-dir ./obj/ --nupkg ./bin/ -v 1.0.0 -i ./bin/mashtub.json
done
62 changes: 39 additions & 23 deletions src/main/Yardarm/GenerationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,52 +63,68 @@ private static HashSet<string> GetPreprocessorSymbols(NuGetFramework targetFrame
GetNetCoreAppPreprocessorSymbols(targetFramework.Version),
{ Framework: NuGetFrameworkConstants.NetCoreApp, Version.Major: >= 5 } =>
GetNetPreprocessorSymbols(targetFramework.Version),
_ => Enumerable.Empty<string>()
_ => []
});

private static readonly Version[] s_dotNetStandardVersions =
[
new(2, 0),
new(2, 1),
];

private static IEnumerable<string> GetNetStandardPreprocessorSymbols(Version frameworkVersion)
{
var result = new List<string> { "NETSTANDARD", $"NETSTANDARD{frameworkVersion.Major}_{frameworkVersion.Minor}" };
yield return "NETSTANDARD";
yield return $"NETSTANDARD{frameworkVersion.Major}_{frameworkVersion.Minor}";

foreach (var version in new Version[] { new(2, 0), new(2, 1) }
.Where(p => p <= frameworkVersion))
foreach (var version in s_dotNetStandardVersions.Where(p => p <= frameworkVersion))
{
result.Add($"NETSTANDARD{version.Major}_{version.Minor}_OR_GREATER");
yield return $"NETSTANDARD{version.Major}_{version.Minor}_OR_GREATER";
}

return result;
}

private static readonly Version[] s_dotNetCoreVersions =
[
new(2, 0),
new(2, 1),
new(3, 0),
new(3, 1),
];

private static IEnumerable<string> GetNetCoreAppPreprocessorSymbols(Version frameworkVersion)
{
var result = new List<string>
{
"NETCOREAPP", $"NETCOREAPP{frameworkVersion.Major}_{frameworkVersion.Minor}"
};
yield return "NETCOREAPP";
yield return $"NETCOREAPP{frameworkVersion.Major}_{frameworkVersion.Minor}";

foreach (var version in new Version[] { new(2, 0), new(2, 1), new(3, 0), new(3, 1) }
.Where(p => p <= frameworkVersion))
foreach (var version in s_dotNetCoreVersions.Where(p => p <= frameworkVersion))
{
result.Add($"NETCOREAPP{version.Major}_{version.Minor}_OR_GREATER");
yield return $"NETCOREAPP{version.Major}_{version.Minor}_OR_GREATER";
}

return result;
}

private static readonly Version[] s_dotNetVersions =
[
new(5, 0),
new(6, 0),
new(7, 0),
new(8, 0),
new(9, 0),
];

private static IEnumerable<string> GetNetPreprocessorSymbols(Version frameworkVersion)
{
var result = new List<string> { $"NET{frameworkVersion.Major}_{frameworkVersion.Minor}" };
yield return $"NET{frameworkVersion.Major}_{frameworkVersion.Minor}";

foreach (var version in new Version[] { new(5, 0), new(6, 0), new(7, 0), new(8, 0) }
.Where(p => p <= frameworkVersion))
foreach (var version in s_dotNetVersions.Where(p => p <= frameworkVersion))
{
result.Add($"NET{version.Major}_{version.Minor}_OR_GREATER");
yield return $"NET{version.Major}_{version.Minor}_OR_GREATER";
}

// Also include all .NET Core 3.1 symbols except NETCOREAPP3_1
result.AddRange(GetNetCoreAppPreprocessorSymbols(new Version(3, 1)).Except(new[] { "NETCOREAPP3_1" }));

return result;
foreach (string symbol in GetNetCoreAppPreprocessorSymbols(new Version(3, 1)).Except(["NETCOREAPP3_1"]))
{
yield return symbol;
}
}
}
}
2 changes: 1 addition & 1 deletion src/sdk/Yardarm.Sdk.Test/Yardarm.Sdk.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="../Yardarm.Sdk/Sdk/Sdk.props" />

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net8.0;net9.0</TargetFrameworks>
<KeyFile>..\..\Yardarm.snk</KeyFile>

<!-- Override these for local testing, get directly from build output -->
Expand Down

0 comments on commit 30cb61e

Please sign in to comment.