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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/BenchmarkDotNet/BenchmarkDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<ItemGroup>
<EmbeddedResource Include="Templates\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
</ItemGroup>
<ItemGroup>
<None Include="BenchmarkDotNet.targets" Pack="true" PackagePath="buildTransitive" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Gee.External.Capstone" Version="2.3.0" />
Expand Down
34 changes: 34 additions & 0 deletions src/BenchmarkDotNet/BenchmarkDotNet.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Project>

<PropertyGroup>
<!-- If the RuntimeIdentifier is explicitly specified. Use the specified target platform. -->
<BenchmarkDotNetTargetPlatform>$(RuntimeIdentifier)</BenchmarkDotNetTargetPlatform>
</PropertyGroup>

<PropertyGroup Condition="'$(BenchmarkDotNetTargetPlatform)' == ''">
<!-- If RuntimeIdentifier is not specified Use current build platform -->
<!-- List of runtimes supported by Gee.External.Capstone: https://github.com/9ee1/Capstone.NET/tree/master/Gee.External.Capstone/runtimes -->
<BenchmarkDotNetTargetPlatform Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</BenchmarkDotNetTargetPlatform>
<BenchmarkDotNetTargetPlatform Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</BenchmarkDotNetTargetPlatform>
<BenchmarkDotNetTargetPlatform Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</BenchmarkDotNetTargetPlatform>

<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">$(BenchmarkDotNetTargetPlatform)-x64</BenchmarkDotNetTargetPlatform>
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">$(BenchmarkDotNetTargetPlatform)-x86</BenchmarkDotNetTargetPlatform>
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm'">$(BenchmarkDotNetTargetPlatform)-arm</BenchmarkDotNetTargetPlatform>
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">$(BenchmarkDotNetTargetPlatform)-arm64</BenchmarkDotNetTargetPlatform>
</PropertyGroup>

<Target Name="FilterBenchmarkDotNetPackageAssets" AfterTargets="ResolvePackageAssets">
<!-- Remove `runtimes/{RuntimeIdentifier}` files that is not matched to target platform. -->
<ItemGroup Condition="'$(BenchmarkDotNetTargetPlatform)' != '' AND $(BenchmarkDotNetTargetPlatform) != 'all'">
<RuntimeTargetsCopyLocalItems Remove="@(RuntimeTargetsCopyLocalItems)"
Condition="'%(RuntimeTargetsCopyLocalItems.NuGetPackageId)' == 'Gee.External.Capstone' AND '%(RuntimeTargetsCopyLocalItems.RuntimeIdentifier)' != '$(BenchmarkDotNetTargetPlatform)'" />
</ItemGroup>

<!-- Remove unnecessary satellite assemblies. -->
<ItemGroup>
<ResourceCopyLocalItems Remove="@(ResourceCopyLocalItems)"
Condition="'%(ResourceCopyLocalItems.NuGetPackageId)' == 'Microsoft.CodeAnalysis.Common' OR '%(ResourceCopyLocalItems.NuGetPackageId)' == 'Microsoft.CodeAnalysis.CSharp'"/>
</ItemGroup>
</Target>
</Project>