Skip to content

Apply template updates: Polyfill, netstandard2.0, and net481 Windows test evidence#120

Merged
Malcolmnixon merged 10 commits intomainfrom
copilot/update-template-project
Feb 28, 2026
Merged

Apply template updates: Polyfill, netstandard2.0, and net481 Windows test evidence#120
Malcolmnixon merged 10 commits intomainfrom
copilot/update-template-project

Conversation

Copy link
Contributor

Copilot AI commented Feb 28, 2026

Syncs with TemplateDotNetLibrary, adds netstandard2.0 as a library target, and uses net481 on Windows CI as direct runtime evidence for that target.

Description

Template alignment

  • LangVersion: 12latest
  • SonarAnalyzer.CSharp10.20.0.135146, Microsoft.NET.Test.Sdk18.3.0
  • Added Polyfill 9.12.0 (PrivateAssets=All, PolyArgumentExceptions=true) to library
  • Added InternalsVisibleTo for test project

netstandard2.0 support

  • Added netstandard2.0 to library TargetFrameworks
  • System.Text.Json 10.0.3 referenced unconditionally
  • Microsoft.Bcl.HashCode 6.0.0 conditioned on netstandard2.0 for HashCode.Combine
  • [GeneratedRegex] in SpdxHelpers.cs guarded behind #if NET7_0_OR_GREATER with a static readonly Regex fallback

Windows net481 test target

  • Test project targets net481;net8.0;net9.0;net10.0 on Windows, net8.0;net9.0;net10.0 elsewhere
  • net481 provides direct runtime evidence that the netstandard2.0 library surface works on .NET Framework

Polyfill + InternalsVisibleTo interaction

  • Polyfill injects internal static partial class Polyfill into the library; InternalsVisibleTo exposes it to the test project without importing the namespace
  • Adding Polyfill directly to the test project caused CS0121 (ambiguous extension methods)
  • Fix: <Using Include="Polyfills" /> adds a global using — no duplicate package, .ReplaceLineEndings() resolves to the library's compiled copy on all targets including net481

Portable ArgumentException assertions

  • ArgumentException.Message format differs by runtime: .NET Framework appends \r\nParameter name: x; modern .NET appends (Parameter 'x')
  • Tests that asserted the full ex.Message string failed on net481
  • Fix: Assert.StartsWith(expectedBaseMessage, ex.Message) + Assert.AreEqual("relationship", ex.ParamName)

Requirements

  • REQ-PLAT-004 updated to use net481@ evidence

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code quality improvement

Pre-Submission Checklist

Build and Test

  • Code builds successfully: dotnet build --configuration Release
  • All unit tests pass: dotnet test --configuration Release
  • Code produces zero warnings

Code Quality

  • Code formatting is correct: dotnet format --verify-no-changes
  • New code has appropriate XML documentation comments
  • Static analyzer warnings have been addressed

Quality Checks

  • Spell checker passes: cspell "**/*.{md,cs}"
  • Markdown linter passes: markdownlint "**/*.md"
  • YAML linter passes: yamllint .

Testing

  • Added unit tests for new functionality
  • Updated existing tests if behavior changed
  • All tests follow the AAA (Arrange, Act, Assert) pattern
  • Test coverage is maintained or improved

Documentation

  • Updated README.md (if applicable)
  • Added code examples for new features (if applicable)
  • Updated requirements.yaml (if applicable)
  • Updated XML documentation comments for changed APIs

Additional Notes

net481 tests run only on Windows CI agents; Linux agents target net8.0;net9.0;net10.0. REQ-PLAT-004 remains unmet in reqstream until a Windows CI run produces net481 results.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits February 28, 2026 19:32
…tstandard2.0 support

- Add netstandard2.0 to TargetFrameworks in library project
- Add Polyfill 9.12.0 package with PolyArgumentExceptions=true
- Update LangVersion from 12 to latest in both projects
- Update SonarAnalyzer.CSharp from 10.19.0.132793 to 10.20.0.135146
- Update Microsoft.NET.Test.Sdk from 18.0.1 to 18.3.0
- Add System.Text.Json conditional references (9.0.5 for netstandard2.0, 10.0.3 for net8+)
- Add HashCodePolyfill.cs for System.HashCode on netstandard2.0
- Add #if NET7_0_OR_GREATER guard in SpdxHelpers.cs for [GeneratedRegex]
- Add InternalsVisibleTo for test project
- Reorganize ItemGroups with template-style section comments
- Add REQ-PLAT-004 for .NET Standard 2.0 target framework support
…evidence

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copilot AI changed the title [WIP] Run repo-consistency agent and apply updates Apply template updates: Polyfill, netstandard2.0, and net481 Windows test evidence Feb 28, 2026
…erateDocumentationFile

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon
Copy link
Contributor

@copilot I'm being told it's better to add Microsoft.Bcl.HashCode for HashCode.Combine rather than writing a custom polyfill. Additionally the code-quality lint checks failed.

…-check failures

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 28, 2026

@copilot I'm being told it's better to add Microsoft.Bcl.HashCode for HashCode.Combine rather than writing a custom polyfill. Additionally the code-quality lint checks failed.

Done in d4430a2 — removed the custom HashCodePolyfill.cs and added Microsoft.Bcl.HashCode 6.0.0 (conditioned on netstandard2.0). Also fixed the spell-check failures by removing netstandard from C# comments in SpdxHelpers.cs.

@Malcolmnixon
Copy link
Contributor

@copilot The Windows build is complaining of:

Error: D:\a\SpdxModel\SpdxModel\test\DemaConsulting.SpdxModel.Tests\TestHelpers.cs(44,35): error CS1061: 'string' does not contain a definition for 'ReplaceLineEndings' and no accessible extension method 'ReplaceLineEndings' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?) [D:\a\SpdxModel\SpdxModel\test\DemaConsulting.SpdxModel.Tests\DemaConsulting.SpdxModel.Tests.csproj::TargetFramework=net481]

However the PolyFill library looks like it does contain such a method - https://github.com/SimonCropp/Polyfill/blob/88aed47fd70637a830bed2f2747401d9e9a68786/src/Polyfill/Polyfill_String.cs#L167

What gives?

…n TestHelpers.cs

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 28, 2026

@copilot The Windows build is complaining of:

Error: D:\a\SpdxModel\SpdxModel\test\DemaConsulting.SpdxModel.Tests\TestHelpers.cs(44,35): error CS1061: 'string' does not contain...

Adding Polyfill to the test project caused ambiguity errors because the library's InternalsVisibleTo("DemaConsulting.SpdxModel.Tests") makes its internal Polyfill extension methods visible to the test project — so they'd be duplicated. Fixed in b7119eb by guarding the call in TestHelpers.cs behind #if NET6_0_OR_GREATER, falling back to .Replace("\r\n", "\n").Replace("\r", "\n") on net481.

…rd in TestHelpers.cs

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon
Copy link
Contributor

@copilot The Windows build still failed:

  Failed SpdxRelationships_AddSingle_MissingRelatedElement [214 ms]
  Error Message:
   Assert.AreEqual failed. Expected string length 85 but was 88. 'expected' expression: '"Element SPDXRef-Package-Missing not found in SPDX document (Parameter 'relationship')"', 'actual' expression: 'ex.Message'.
Expected: "...d in SPDX document (Parameter 'rela..."
But was:  "...d in SPDX document␍␊Parameter name:..."

…ramework and modern .NET

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 28, 2026

@copilot The Windows build still failed:

  Failed SpdxRelationships_AddSingle_MissingRelatedElement [214 ms]

...

Fixed in 2e2bab3. The root cause is that ArgumentException.Message appends the parameter name in a framework-specific format — .NET Framework uses \r\nParameter name: relationship while modern .NET uses (Parameter 'relationship'). The assertions now use StartsWith to check just the base message and assert ex.ParamName == "relationship" separately, which works correctly on all targets.

Co-authored-by: Malcolmnixon <1863707+Malcolmnixon@users.noreply.github.com>
@Malcolmnixon Malcolmnixon marked this pull request as ready for review February 28, 2026 20:36
@Malcolmnixon Malcolmnixon merged commit 26c80fe into main Feb 28, 2026
11 checks passed
@Malcolmnixon Malcolmnixon deleted the copilot/update-template-project branch February 28, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants