Skip to content

chore: Modify csproj-based project build logics - #3235

Merged
timcassell merged 14 commits into
dotnet:masterfrom
filzrev:chore-fix-double-write-issue
Sep 16, 2026
Merged

timcassell merged 14 commits into
dotnet:masterfrom
filzrev:chore-fix-double-write-issue

Conversation

@filzrev

@filzrev filzrev commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR intended to fix #3191.

What's changed in this PR

1. Cherry picks other PR commits

Following PR contents are included

2. Remove DllGatherer related logics

After this PR changes, DllGatherer logics seems not be needed.
So I've removed DllGatherer related logics.

3. Add settings for Autogenerated project.

Modify BenchmarkDotNet.Build.props.txt template.
And enable following settings for Autogenerated project.

  • OutputPath
  • PublishDir

4. Cleanup DotNetCliCommand.cs logics.

Previously, --output and -p:PublishDir command line parameters are used.
These settings are handled as MSBuild Global property and that causing DoubleWrite Issues.

So this PR move these settings to Autogenerated.csproj level.
other projects build outputs are placed under .artifacts directory.

4. Other Changes

  1. Remove ErrorOnDuplicatePublishOutputFiles settings.
  2. Add XmlDocument.SaveAsync helper method for netstandard2.0

Test

Setting ForcedNoDependenciesForIntegrationTests: false version of CI. (InProgress)

@filzrev filzrev changed the title chore: fix double write issue chore: Modify csproj-based project build logics Aug 18, 2026
@filzrev

filzrev commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I've re-enable <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> setting for WASM project.

Because it cause following errors for xunit.runner.visualstudio package related DLLs.

NETSDK1152: Found multiple publish output files with the same relative path

It seems occurred because xunit.runner.visualstudio package reference has <PrivateAssets>all</PrivateAssets> setting.

@filzrev

filzrev commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Wasm related CI tests are still failed when using ForcedNoDependenciesForIntegrationTests: false setting.

@timcassell

Copy link
Copy Markdown
Collaborator

It seems that xUnit v2 is incompatible with wasm. It's probably fixed by #3232.

@filzrev

filzrev commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Wasm related CI tests are still failed when using ForcedNoDependenciesForIntegrationTests: false setting.

This issue is caused commit 7f18102 is not pushed to target CI branch.

And I've added following commits to avoid issue when using ForcedNoDependenciesForIntegrationTests=false

  • 75973bf (Increase timeout from 1 min to 5 min to avoid timeout)
  • 20fc0fe (Increase job timeout to 720 minutes to avoid job timeout(Default: 360 minutes))
    (This setting is not works on GitHub Actions hosted runner. and timeout at 360 min)

@filzrev
filzrev force-pushed the chore-fix-double-write-issue branch from 20fc0fe to 75973bf Compare August 23, 2026 02:50
@filzrev

filzrev commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

By changing some settings.
It pass CI with ForcedNoDependenciesForIntegrationTests=false setting.

CI: https://github.com/filzrev/BenchmarkDotNet/actions/runs/32571372114/workflow
(windows-latest CI is cancelled because it execution time overs 360 minutes (GitHub Actions hosted-runner limitation))

Output paths:

- --no-dependencies was widened to every autogenerated build via a filename
  check. The generated project keeps its ProjectReference, and RIDs
  propagate to exe references but not library ones, so the reference
  resolved to a RID-specific ref assembly that nothing produced. Reverted to
  the ForcedNoDependenciesForIntegrationTests gate.
- GetPublishDirectoryPath defaulted to <artifacts>/publish while the
  generators expect the executable in their binaries directory. That was
  masked while --output overrode PublishDir on the command line; once
  PublishDir became authoritative, publish wrote where BenchmarkDotNet never
  looks.
- OutputPath was derived by chopping TFM.Length + 1 characters off the
  binaries path, which is wrong wherever that path ends in the RID. The
  generated project sets AppendTargetFrameworkToOutputPath=false instead.
- The generated project sets OutDir as well as OutputPath. OutDir only falls
  back to OutputPath when it has not been set, so a Directory.Build.props in
  the benchmark project's tree that sets OutDir kept it, and the build went
  somewhere BenchmarkDotNet does not look. The command line arguments this
  replaces set both, which is why the case did not arise before.

Reference gathering:

The gatherer globbed *.dll out of the benchmark project's output, which
holds more than references: content files copied there, and native
libraries. A native library handed to MSBuild as an assembly is MSB3246. A
content file is published by the ProjectReference already, so referencing it
too puts the same file in the publish set twice, and crossgen2 rejects
duplicate inputs - the NETSDK1152 that R2R and Wasm were suppressing. And an
exe project has no dll beside its exe, so on .NET Framework the benchmark
assembly was never gathered at all. Asking MSBuild for @(ReferencePath)
avoids all three, so both suppressions go.

It also built DllGatherer.csproj, a copy of the generated project made from
the default template, which could not match what a toolchain had actually
generated. The gathering pass now builds the generated project itself with
SkipCompilerExecution, so it stops once MSBuild has resolved the references
and needs neither a second project, a stub entry point, nor the output-path
handshake between the two. Not running the compiler also keeps the pass from
writing a program built against incomplete references into the directory
BenchmarkDotNet reads the benchmark executable from.

The gathering pass no longer edits the project it just built either. It
writes what MSBuild resolved beside the project, and the project imports
that file when it exists, so the project is complete the moment it is
written.

NativeAot passed -r on the command line while its project already declared
the RuntimeIdentifier. Only the command line one reaches the referenced
projects, so the benchmark project was built once for gathering and again
for the real build, into two different pivots, and the references gathered
came from the pivot that was not used.

Project generation:

The generated project is composed as an XDocument rather than substituted
into a text template, so a path holding an XML character cannot corrupt it,
and a toolchain extends it by overriding AddEarlyProperties,
AddProjectContent or AddLateProperties instead of maintaining a near-copy of
the whole file. R2R, Wasm and NativeAot each kept their own template that
had drifted from the default one; they now share the parts they never meant
to differ on, which is also what puts the gathered references in front of
all four toolchains rather than only the default one.

That leaves nothing importing BenchmarkDotNet.Build.props or .targets, so
those and the three csproj templates are gone, along with the
GenerateCustomBuildHooksAsync hook added to write them.

Build invocations:

Publishing ran as three dotnet invocations - restore, then build, then
publish - when the publish command performs all three itself, so that step is
one invocation now. Restoring separately is still what the gathering pass
does, and what a toolchain that only builds does, since those are the passes
that have to do the restoring. A custom build configuration takes a single
invocation as well, a standalone restore having no way to be told which
configuration to use.

Building without dependencies now covers the publishing toolchains too. That
is only safe because no toolchain passes a runtime identifier on the command
line any more, where it is a global property and reaches the referenced
projects: a library has no runtime identifier to resolve against, and not
building it is what stops the sdk from negotiating one away. Mono was the
last to do so and declares SelfContained and the identifier in the project
instead, which leaves MonoPublisher with nothing to do and the helper that
built NativeAot's argument with no callers.

Publishing with --no-build is what raised NETSDK1085 on Wasm, and nothing
passes it any more, so that project no longer turns BuildProjectReferences
off to suppress it.

SDK requirement:

ArtifactsPath is set as a property rather than passed as --artifacts-path,
which is a .NET 8 SDK argument. An older SDK errors on the argument but
ignores the property, so nothing has to require that SDK: master's fallback
of building net7 and earlier one partition at a time already covers the
isolation those builds then go without.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@timcassell

Copy link
Copy Markdown
Collaborator

@filzrev I put up a PR against this branch. filzrev#16

@timcassell timcassell added this to the v0.16.0 milestone Sep 12, 2026
@filzrev

filzrev commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

@timcassell
Please feel free to use the content of this PR.
There is no need to keep a commit histories.

@timcassell
timcassell merged commit 36a5a06 into dotnet:master Sep 16, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DoubleWrites message is recorded when using --output parameter on dotnet command

2 participants