Skip to content

feat: Add custom MsBuild targets to remove unnecessary files from bin directory #2737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

filzrev
Copy link
Contributor

@filzrev filzrev commented May 25, 2025

This PR intended to resolve #2736

What's changed in this PR

1. Add custom MSBuild targets file to nupkg.
This custom target is packed as buildTransitive/BenchmarkDotNet.targets file.
And it'sused by .NET SDK-Style projects. (It's ignored when referenced from .NET Framework non-SDK style project)

2. Details of custom MSBuild target process.
It try to set BenchmarkDotNetTargetPlatform property.
If target runtime is explicitly specified (e.g. --runtime) just use specified runtime.
Otherwise. try to use current build environment platform.

Then FilterBenchmarkDotNetPackageAssets custom target try to remove following files.

  1. runtime/* files that are copied from Gee.External.Capstone package
  2. Satellite assemblies that are copied from Microsoft.CodeAnalysis.* package

Breaking changes
This PR contains following breaking changes.

  1. runtimes\* files that not matched to current build environment are not copied to bin by default.
    When it need to use old behaviors. It need to set following MSBuild property on benchmark project.

    `all

  2. Roslyn's satellite assemblies are not copied to bin directory.

What's tested on my environment.

I've confirmed PR behaviors with following steps (On Windows/Ubuntu on WSL)

  1. Run following command to create nupkg for tests. (It need unique suffix to avoid caching issue)

    dotnet pack BenchmarkDotNet.sln --version-suffix develop-1 -o ./packages

  2. Create benchmark project that use packages directory as package source.
  3. Build benchmark project. And confirms followings.
    3.1. runtimes/* directory contains only current build environment's runtime only
    3.2. Satellite assembly directory is not copied to bin directory.
  4. Run benchmark with --keepFiles options. and confirm temporary project outputs.

Additionally, I've confirmed following behaviors.

  • non-SDK style .NET Framework project is not affected by this PR.
  • dotnet publish -r {runtimeIdentifier} command works as expected. (Satellite assembly is not copied)

@timcassell
Copy link
Collaborator

@adamsitnik Do you have any concerns with this change?

@filzrev
Copy link
Contributor Author

filzrev commented May 26, 2025

For additional confirmation:
Are these x86/x64 runtimes actually used by BenchmarkDotNet?
https://github.com/9ee1/Capstone.NET/tree/master/Gee.External.Capstone/runtimes

It seems x86/x64 disassembler is processed by Iced library.
And Capstone.NET is not used when targeting these architectures.

@filzrev
Copy link
Contributor Author

filzrev commented May 26, 2025

Additionally, currently ARM32 disassembler for linux-arm seems not supported by BenchmarkDotNet.
It failed on validation.

if (!(currentPlatform is Platform.X64 or Platform.X86 or Platform.Arm64))

And disassembler on maxOS seems also not supported by current BenchmarkDotNet version.

// when we add macOS support, RuntimeInformation.IsMacOS() needs to be added here
private static bool ShouldUseClrMdDisassembler(BenchmarkCase benchmarkCase)
=> !ShouldUseMonoDisassembler(benchmarkCase) && (OsDetector.IsWindows() || OsDetector.IsLinux());

Note: Latest version of ClrMD supports macOS. So I though it can add disassembler support for macOS.

@timcassell timcassell requested a review from adamsitnik May 28, 2025 12:00
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.

[Feature Request] Reduce output binary size of project build results
2 participants