From 3982b55504666cfdf4ac18e7fb2aa5511e276c95 Mon Sep 17 00:00:00 2001 From: Ivar Nesje Date: Mon, 6 Nov 2023 20:19:25 +0100 Subject: [PATCH] Update app-lib-dotnet to multi-target dotnet6 and dotnet8 with c# 12 Also include code that allows for unchecked use of `required` attributes in net6.0 --- .github/workflows/codeql.yml | 11 +++++++++++ .github/workflows/dotnet-test.yml | 2 +- .github/workflows/publish-release.yml | 2 ++ .github/workflows/test-and-analyze-fork.yml | 2 +- .github/workflows/test-and-analyze.yml | 2 +- src/Altinn.App.Api/Altinn.App.Api.csproj | 7 +++++-- src/Altinn.App.Core/Altinn.App.Core.csproj | 9 +++++++-- .../Helpers/RequiredNet6Hacks.cs | 18 ++++++++++++++++++ src/Directory.Build.props | 2 +- .../Altinn.App.Api.Tests.csproj | 2 +- .../Altinn.App.Common.Tests.csproj | 2 +- .../Altinn.App.Core.Tests.csproj | 4 ++-- .../Internal/App/FrontendFeaturesTest.cs | 2 +- 13 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 src/Altinn.App.Core/Helpers/RequiredNet6Hacks.cs diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index bc8594658..1e22b56be 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -26,6 +26,17 @@ jobs: # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support steps: + # The following step is required in order to use .NET 8 pre-release. + # We can remove if using an officially supported .NET version. + # See https://github.com/github/codeql-action/issues/757#issuecomment-977546999 + - name: Setup .NET + uses: actions/setup-dotnet@v3 + with: + dotnet-version: | + 6.0.x + 8.0.x + include-prerelease: true + - name: Checkout repository uses: actions/checkout@v4 diff --git a/.github/workflows/dotnet-test.yml b/.github/workflows/dotnet-test.yml index 050821296..bc7c45cbf 100644 --- a/.github/workflows/dotnet-test.yml +++ b/.github/workflows/dotnet-test.yml @@ -21,7 +21,7 @@ jobs: with: dotnet-version: | 6.0.x - 5.0.x + 8.0.x - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index cf7f351a4..28ca11ca3 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -19,6 +19,7 @@ jobs: with: dotnet-version: | 6.0.x + 8.0.x - name: Install deps run: | dotnet restore @@ -49,6 +50,7 @@ jobs: with: dotnet-version: | 6.0.x + 8.0.x - name: Build bundles run: | make bundles diff --git a/.github/workflows/test-and-analyze-fork.yml b/.github/workflows/test-and-analyze-fork.yml index df4ca1969..0fb72395b 100644 --- a/.github/workflows/test-and-analyze-fork.yml +++ b/.github/workflows/test-and-analyze-fork.yml @@ -14,7 +14,7 @@ jobs: with: dotnet-version: | 6.0.x - 5.0.x + 8.0.x - uses: actions/checkout@v4 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis diff --git a/.github/workflows/test-and-analyze.yml b/.github/workflows/test-and-analyze.yml index c3517dfaf..3c5354916 100644 --- a/.github/workflows/test-and-analyze.yml +++ b/.github/workflows/test-and-analyze.yml @@ -20,7 +20,7 @@ jobs: with: dotnet-version: | 6.0.x - 5.0.x + 8.0.x - name: Set up JDK 11 uses: actions/setup-java@v3 with: diff --git a/src/Altinn.App.Api/Altinn.App.Api.csproj b/src/Altinn.App.Api/Altinn.App.Api.csproj index 3bb643875..66625254e 100644 --- a/src/Altinn.App.Api/Altinn.App.Api.csproj +++ b/src/Altinn.App.Api/Altinn.App.Api.csproj @@ -1,7 +1,7 @@ - net6.0 + net6.0;net8.0 Library Altinn.App.Api Altinn;Studio;App;Api;Controllers @@ -22,7 +22,7 @@ - + @@ -47,5 +47,8 @@ true $(NoWarn);1591 + + $(NoWarn);8618 + diff --git a/src/Altinn.App.Core/Altinn.App.Core.csproj b/src/Altinn.App.Core/Altinn.App.Core.csproj index a4de15977..001e5df0c 100644 --- a/src/Altinn.App.Core/Altinn.App.Core.csproj +++ b/src/Altinn.App.Core/Altinn.App.Core.csproj @@ -1,9 +1,14 @@  - net6.0 + net6.0;net8.0 enable enable + + + $(NoWarn);8618 + + @@ -18,7 +23,7 @@ - + diff --git a/src/Altinn.App.Core/Helpers/RequiredNet6Hacks.cs b/src/Altinn.App.Core/Helpers/RequiredNet6Hacks.cs new file mode 100644 index 000000000..24f5ce000 --- /dev/null +++ b/src/Altinn.App.Core/Helpers/RequiredNet6Hacks.cs @@ -0,0 +1,18 @@ +// This file is a hack for required properties to work in net6.0 +// Should be removed when support for targeting net6.0 is removed + +#if NET6_0 +#pragma warning disable +namespace System.Runtime.CompilerServices; + +[AttributeUsage(AttributeTargets.Property)] +public class RequiredMemberAttribute : Attribute { } + +[AttributeUsage(AttributeTargets.All)] +public class CompilerFeatureRequiredAttribute : Attribute +{ + public CompilerFeatureRequiredAttribute(string name) { } +} +[System.AttributeUsage(System.AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)] +public sealed class SetsRequiredMembersAttribute : Attribute { } +#endif \ No newline at end of file diff --git a/src/Directory.Build.props b/src/Directory.Build.props index c8d35e391..b1f3f0a3c 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -10,7 +10,7 @@ preview.0 v true - 10.0 + 12 diff --git a/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj b/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj index ccfd2ce52..2ab57f388 100644 --- a/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj +++ b/test/Altinn.App.Api.Tests/Altinn.App.Api.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net6.0;net8.0 enable enable false diff --git a/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj b/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj index ca11a7812..07203dac8 100644 --- a/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj +++ b/test/Altinn.App.Common.Tests/Altinn.App.Common.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net6.0;net8.0 enable false diff --git a/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj b/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj index 90a88f825..43ca355e0 100644 --- a/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj +++ b/test/Altinn.App.Core.Tests/Altinn.App.Core.Tests.csproj @@ -1,7 +1,7 @@  - net6.0 + net8.0 false @@ -42,7 +42,7 @@ - + diff --git a/test/Altinn.App.Core.Tests/Internal/App/FrontendFeaturesTest.cs b/test/Altinn.App.Core.Tests/Internal/App/FrontendFeaturesTest.cs index c34a386c2..1efb76060 100644 --- a/test/Altinn.App.Core.Tests/Internal/App/FrontendFeaturesTest.cs +++ b/test/Altinn.App.Core.Tests/Internal/App/FrontendFeaturesTest.cs @@ -36,7 +36,7 @@ public async Task GetFeatures_returns_list_of_enabled_features_when_feature_flag { "jsonObjectInDataResponse", true }, }; var featureManagerMock = new Mock(); - featureManagerMock.Setup(f => f.IsEnabledAsync(FeatureFlags.JsonObjectInDataResponse, default)).ReturnsAsync(true); + featureManagerMock.Setup(f => f.IsEnabledAsync(FeatureFlags.JsonObjectInDataResponse)).ReturnsAsync(true); IFrontendFeatures frontendFeatures = new FrontendFeatures(featureManagerMock.Object); var actual = await frontendFeatures.GetFrontendFeatures(); actual.Should().BeEquivalentTo(expected);