Keep memory safety rules out of BenchmarkDotNet's generated project

Merged
BR
18d ago
+10-2

What

Directory.Build.props now applies LangVersion=preview and the updated-memory-safety-rules feature only when the project isn't BenchmarkDotNet.Autogenerated.

Why

Since #157, out-of-process benchmark runs have failed. Every row reports NA with:

error CS9377: The 'unsafe' modifier does not have any effect here under the current memory safety rules.

BenchmarkDotNet builds a generated BenchmarkDotNet.Autogenerated.csproj under artifacts/bin/Snappier.Benchmarks/.... That project sets ImportDirectoryBuildProps=false, but in the project body, after Sdk.props has already imported Directory.Build.props, so the setting has no effect. The generated project inherited the memory-safety settings, and its generated public unsafe class Runnable_0 fails under the new rules. A diagnostic build of the generated project confirmed it was getting Features = ;updated-memory-safety-rules and LangVersion = preview.

Reviewer notes

  • Snappier, Snappier.Tests and Snappier.Benchmarks still compile under the rules: all 11 compiler calls across their target frameworks pass -langversion:preview -features:updated-memory-safety-rules.
  • CheckEolTargetFramework and UseArtifactsOutput still apply to every project, including the generated one.

Testing

  • echo 5 | dotnet run -c Release -f net10.0 --project Snappier.Benchmarks -- --filter '*BlockDecompressHtml*' prints real timings out of process (Decompress | 9.836 us).
  • dotnet build -c Release: 0 warnings, 0 errors.
  • dotnet test --project Snappier.Tests -c Release: 1544 tests, all passed.

šŸ¤– Generated with Claude Code