diff --git a/requirements.yaml b/requirements.yaml index 578681c..e816f79 100644 --- a/requirements.yaml +++ b/requirements.yaml @@ -314,3 +314,18 @@ sections: tests: - net10.0@Spdx2JsonDeserializer_Deserialize_ValidSpdx22JsonReturnsExpectedDocument - net10.0@Spdx2JsonSerializer_SerializeDocument_CorrectResults + + - id: REQ-PLAT-004 + title: The library shall support the .NET Standard 2.0 target framework. + tags: + - platform + justification: | + .NET Standard 2.0 is a widely-supported target framework that enables the library to + be used in MSBuild extensions and other tooling that requires .NET Standard compatibility. + Supporting this target framework ensures the library can be integrated into a broader + range of .NET projects, including those targeting .NET Framework and older .NET Core versions. + The net481 test target on Windows provides direct runtime evidence of .NET Standard 2.0 + compatibility, as .NET Framework 4.8.1 fully implements the .NET Standard 2.0 API surface. + tests: + - "net481@Spdx2JsonDeserializer_Deserialize_ValidSpdx22JsonReturnsExpectedDocument" + - "net481@Spdx2JsonSerializer_SerializeDocument_CorrectResults" diff --git a/src/DemaConsulting.SpdxModel/DemaConsulting.SpdxModel.csproj b/src/DemaConsulting.SpdxModel/DemaConsulting.SpdxModel.csproj index a191bcb..38c459d 100644 --- a/src/DemaConsulting.SpdxModel/DemaConsulting.SpdxModel.csproj +++ b/src/DemaConsulting.SpdxModel/DemaConsulting.SpdxModel.csproj @@ -1,8 +1,8 @@  - net8.0;net9.0;net10.0 - 12 + netstandard2.0;net8.0;net9.0;net10.0 + latest enable enable @@ -36,6 +36,9 @@ true latest + + true + true $(PackageId) @@ -43,20 +46,40 @@ Organization: $(Company) + - + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + diff --git a/src/DemaConsulting.SpdxModel/SpdxHelpers.cs b/src/DemaConsulting.SpdxModel/SpdxHelpers.cs index acb10a1..9d5d9cf 100644 --- a/src/DemaConsulting.SpdxModel/SpdxHelpers.cs +++ b/src/DemaConsulting.SpdxModel/SpdxHelpers.cs @@ -24,11 +24,25 @@ namespace DemaConsulting.SpdxModel; internal static partial class SpdxHelpers { +#if NET7_0_OR_GREATER /// - /// Regular expression for checking date/time formats + /// Regular expression for checking date/time formats (source-generated for .NET 7+) /// [GeneratedRegex(@"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$", RegexOptions.None, 100)] private static partial Regex DateTimeRegex(); +#else + /// + /// Cached regular expression instance for checking date/time formats (pre-.NET 7 fallback) + /// + private static readonly Regex DateTimeRegexInstance = + new Regex(@"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$", RegexOptions.None, TimeSpan.FromMilliseconds(100)); + + /// + /// Regular expression for checking date/time formats + /// + /// Compiled instance + private static Regex DateTimeRegex() => DateTimeRegexInstance; +#endif /// /// Test if a string is a valid SPDX date/time field (which include null/empty) diff --git a/test/DemaConsulting.SpdxModel.Tests/DemaConsulting.SpdxModel.Tests.csproj b/test/DemaConsulting.SpdxModel.Tests/DemaConsulting.SpdxModel.Tests.csproj index 912a018..4e50a1a 100644 --- a/test/DemaConsulting.SpdxModel.Tests/DemaConsulting.SpdxModel.Tests.csproj +++ b/test/DemaConsulting.SpdxModel.Tests/DemaConsulting.SpdxModel.Tests.csproj @@ -1,8 +1,9 @@  - net8.0;net9.0;net10.0 - 12 + net481;net8.0;net9.0;net10.0 + net8.0;net9.0;net10.0 + latest enable enable @@ -18,41 +19,57 @@ latest - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/DemaConsulting.SpdxModel.Tests/Transforms/SpdxRelationshipsTests.cs b/test/DemaConsulting.SpdxModel.Tests/Transforms/SpdxRelationshipsTests.cs index f240d37..930d7b1 100644 --- a/test/DemaConsulting.SpdxModel.Tests/Transforms/SpdxRelationshipsTests.cs +++ b/test/DemaConsulting.SpdxModel.Tests/Transforms/SpdxRelationshipsTests.cs @@ -69,8 +69,8 @@ public void SpdxRelationships_AddSingle_MissingId() }); // Assert: Verify the exception message and that no relationships were added - Assert.AreEqual("Element SPDXRef-Package-Missing not found in SPDX document (Parameter 'relationship')", - ex.Message); + Assert.StartsWith("Element SPDXRef-Package-Missing not found in SPDX document", ex.Message); + Assert.AreEqual("relationship", ex.ParamName); Assert.IsEmpty(document.Relationships); } @@ -97,8 +97,8 @@ public void SpdxRelationships_AddSingle_MissingRelatedElement() }); // Assert: Verify the exception message and that no relationships were added - Assert.AreEqual("Element SPDXRef-Package-Missing not found in SPDX document (Parameter 'relationship')", - ex.Message); + Assert.StartsWith("Element SPDXRef-Package-Missing not found in SPDX document", ex.Message); + Assert.AreEqual("relationship", ex.ParamName); Assert.IsEmpty(document.Relationships); }