Skip to content

Conversation

@Ted-Jin-Lab
Copy link
Contributor

@Ted-Jin-Lab Ted-Jin-Lab commented Sep 20, 2025

Fixes #1619

Add new project NumberExtensionsCS14 to use the C#14 feature extension members for making 5.Meters work.

Please merge after C#14 is officially released.

@angularsen
Copy link
Owner

@claude Review this PR. In addition to the standard prompt, also comment on what target frameworks we should use for the two projects.

@claude
Copy link

claude bot commented Sep 21, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@angularsen
Copy link
Owner

@claude Review PR

@claude
Copy link

claude bot commented Sep 21, 2025

Claude encountered an error —— View job

Failed with exit code 128

I'll analyze this and get back to you.

@angularsen
Copy link
Owner

Seems Claude doesn't work for PRs from forks due to security:
anthropics/claude-code-action#339

@angularsen
Copy link
Owner

angularsen commented Sep 21, 2025

Local review by Claude:

PR Review: Add C# 14 Extension Members Support

Thank you for this contribution! The implementation of C# 14's extension members feature is well-structured and properly integrated into the code
generation pipeline. However, there are several issues that need to be addressed before merging.

🔴 Issues to Fix

  1. Package ID Conflict

    • The UnitsNet.NumberExtensions.CS14.csproj has <PackageId>UnitsNet.NumberExtensions</PackageId> which conflicts with the existing package
    • Fix: Change to <PackageId>UnitsNet.NumberExtensions.CS14</PackageId>
  2. Missing Documentation

    • No README updates or documentation explaining the new package
    • Users need to know:
      • How to use the new syntax (5.Meters vs Length.FromMeters(5))
      • C# 14 preview requirement
      • Differences from the existing NumberExtensions package
  3. Test Coverage Gap (wrong, they do test correct syntax)

    • While test files are generated, they don't actually test the extension member syntax
    • The tests use traditional syntax, not the new 5.Meters syntax
    • Consider adding integration tests that verify the extension syntax works correctly
  4. Typo in PR Title

    • "pakcage" → "package"

⚠️ Considerations

  1. C# 14 Status

    • C# 14 is not yet officially released
    • The project uses <LangVersion>preview</LangVersion> requiring preview compiler
    • As mentioned in the PR description, consider waiting for official C# 14 release
  2. Maintenance Burden

    • This adds another package to maintain
    • Generated code size increases significantly (260+ new files)
    • Consider if this should be a separate package or integrated into the main NumberExtensions package once C# 14 is stable

✅ Good Implementation

  • Properly integrated into the existing code generation pipeline
  • Follows project structure and patterns
  • Conditional compilation for different .NET versions
  • Code builds successfully
  • Strong naming and package metadata properly configured

📋 Checklist Before Merge

  • Fix PackageId to UnitsNet.NumberExtensions.CS14
  • Add documentation/README section explaining the new package
  • Add example usage in documentation showing 5.Meters syntax
  • Consider adding integration tests for extension member syntax
  • Fix typo in PR title
  • Confirm timeline - wait for C# 14 official release?

💡 Suggestion

Consider adding a simple example in the PR description or README:

// Old way (existing NumberExtensions)
using UnitsNet.NumberExtensions.NumberToLength;
var length = 5.Meters();

// New way (CS14 extension members)
using UnitsNet.NumberExtensions.NumberToLength;
var length = 5.Meters; // No parentheses needed!

Overall, this is a solid implementation that will be valuable once C# 14 is released. The issues above are mostly configuration and documentation
related, with the core implementation being sound.

This review provides clear, actionable feedback with specific issues to fix, formatted for easy reading on GitHub.

@angularsen angularsen changed the title 🎉Add new NumberExtensionsCS14 nuget pakcage 🎉Add new NumberExtensionsCS14 nuget package Sep 21, 2025
Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per Claude review:

  • Fix PackageId to UnitsNet.NumberExtensions.CS14
  • Add documentation/README section explaining the new package
  • Add example usage in documentation showing 5.Meters syntax
  • Fix typo in PR title
  • Confirm timeline - wait for C# 14 official release?

See inline comments above:
#1620 (review)

Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, build scripts must be updated to include new projects:

var extensionsOutputDir = $"{rootDir}/UnitsNet.NumberExtensions/GeneratedCode";
var extensionsTestOutputDir = $"{rootDir}/UnitsNet.NumberExtensions.Tests/GeneratedCode";
var extensionsCs14OutputDir = $"{rootDir}/UnitsNet.NumberExtensions.CS14/GeneratedCode";
var extensionsCs14TestOutputDir = $"{rootDir}/UnitsNet.NumberExtensions.CS14.Tests/GeneratedCode";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CS14 projects are NOT included in the build-functions.psm1 file. This means:

Build Script Issues Found

The new CS14 projects are missing from the build pipeline:

  1. Not in test list (line 63-67): UnitsNet.NumberExtensions.CS14.Tests is not included in the Start-Tests function
  2. Not in NuGet pack list (line 102-106): UnitsNet.NumberExtensions.CS14 is not included in the Start-PackNugets function

This means:

  • ✅ The projects ARE in the solution file and will build with dotnet build
  • ❌ The tests won't run in CI/CD pipeline
  • ❌ The NuGet package won't be created in CI/CD pipeline

Here's the additional feedback to add to the PR review:

🔴 Build Pipeline Issue

The new CS14 projects are missing from the build pipeline configuration:

File: Build/build-functions.psm1

  1. Tests not running in CI - Add to line ~65:
$projectPaths = @(
    "UnitsNet.Tests\UnitsNet.Tests.csproj",
    "UnitsNet.NumberExtensions.Tests\UnitsNet.NumberExtensions.Tests.csproj",
    "UnitsNet.NumberExtensions.CS14.Tests\UnitsNet.NumberExtensions.CS14.Tests.csproj",  # ADD THIS
    "UnitsNet.Serialization.JsonNet.Tests\UnitsNet.Serialization.JsonNet.Tests.csproj"
)

2. NuGet package not created in CI - Add to line ~105:
$projectPaths = @(
    "UnitsNet\UnitsNet.csproj",
    "UnitsNet.Serialization.JsonNet\UnitsNet.Serialization.JsonNet.csproj",
    "UnitsNet.NumberExtensions\UnitsNet.NumberExtensions.csproj",
    "UnitsNet.NumberExtensions.CS14\UnitsNet.NumberExtensions.CS14.csproj"  # ADD THIS
)

Without these changes, the CS14 package won't be tested or published by the CI/CD pipeline.

This is a critical issue that would prevent the package from being properly tested and published.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could merge this earlier if we get the CI pipeline to build and run tests with .NET 10 SDK preview.

I pushed an attempt to fix this, let's see if the pipeline works now.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude happily fixed these issues, so I pushed a fix for the build scripts also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks. I didn't check the Package Id, description and the build script. Sorry about that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, that's what reviews are for 👍

angularsen and others added 14 commits September 21, 2025 17:32
- Add .NET 10 SDK preview installation to Azure Pipelines
- Include CS14 projects in build, test, and pack scripts
- Fix ID conflict (now UnitsNet.NumberExtensions.CS14)
- Update package title and description for clarity
- Document new UnitsNet.NumberExtensions.CS14 package
- Show examples of C# 14 extension members syntax (no parentheses)
- Compare with classic extension methods syntax
- Note requirements for C# 14 preview and .NET 10 SDK
- Ensures consistent SDK version across development environments
- Required for C# 14 extension members support
- Allows prerelease versions with rollForward to latest feature
The .NET 10 preview SDK doesn't include the .NET 9 runtime,
which is required to run the CodeGen project (targets net9.0).
Install both .NET 9 and .NET 10 SDKs to ensure all runtimes are available.
The ILLink analyzer throws InvalidCastException with C# 14 extension members
due to incompatibility with the preview syntax. Disable AOT until this is fixed.

This resolves the CSC error AD0001 during compilation.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

# Conflicts:
#	.claude/settings.local.json
The pipeline was missing .NET 8 SDK installation, causing test failures
when trying to run net8.0 targeted tests. Added .NET 8 SDK installation
to both azure-pipelines.yml and azure-pipelines-pr.yml.

Error was: "You must install or update .NET to run this application"
for the net8.0 test assemblies.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Changed global.json to require minimum .NET 9 SDK with rollForward
to latestMajor, allowing it to use .NET 10 preview when available
but fall back to .NET 9 on CI runners.

Previous setting required exact version 10.0.0 which didn't match
the installed 10.0.0-rc.1.x preview versions, causing build failures.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Configure global.json to allow both latest .NET 9 SDK and any .NET 10
preview SDKs:
- Minimum version: 9.0.0
- allowPrerelease: true (allows .NET 10 previews/RCs)
- rollForward: latestMajor (allows using newer major versions)

This ensures the project uses .NET 10 preview when available for C# 14
support, but gracefully falls back to .NET 9 on systems without it.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@angularsen
Copy link
Owner

Sorry for hijacking this, but Claude just went with it and decided to try and make it work with preview .NET10 SDK. Looks good in our PR and CI pipelines, so I'll merge this for now as it should no longer block anything.

@angularsen angularsen merged commit 5db5782 into angularsen:master Sep 21, 2025
@angularsen
Copy link
Owner

Nuget is out @ArchiDog1998
https://www.nuget.org/packages/UnitsNet.NumberExtensions.CS14/6.0.0-pre017

It's prerelease, as v6 currently is.

@Ted-Jin-Lab
Copy link
Contributor Author

image

Sadly, it doesn’t work right now. Maybe it will after C# 14 is officially released.

@angularsen
Copy link
Owner

Does it compile with dotnet build though and .NET 10 SDK?

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.

5.Meters instead of 5.Meters()

2 participants