Skip to content

Commit 44f0dc4

Browse files
authored
feat: Add custom MsBuild targets to remove unnecessary files from bin directory (#2737)
* feat: add custom msbuild target to remove unnecessary files * fix: simplify code based on review comment * fix: update code based on review comment
1 parent fb8bfd9 commit 44f0dc4

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/BenchmarkDotNet/BenchmarkDotNet.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<ItemGroup>
1515
<EmbeddedResource Include="Templates\*" Exclude="bin\**;obj\**;**\*.xproj;packages\**;@(EmbeddedResource)" />
1616
</ItemGroup>
17+
<ItemGroup>
18+
<None Include="BenchmarkDotNet.targets" Pack="true" PackagePath="buildTransitive" />
19+
</ItemGroup>
1720
<ItemGroup>
1821
<PackageReference Include="CommandLineParser" Version="2.9.1" />
1922
<PackageReference Include="Gee.External.Capstone" Version="2.3.0" />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Project>
2+
3+
<PropertyGroup>
4+
<!-- If the RuntimeIdentifier is explicitly specified. Use the specified target platform. -->
5+
<BenchmarkDotNetTargetPlatform>$(RuntimeIdentifier)</BenchmarkDotNetTargetPlatform>
6+
</PropertyGroup>
7+
8+
<PropertyGroup Condition="'$(BenchmarkDotNetTargetPlatform)' == ''">
9+
<!-- If RuntimeIdentifier is not specified Use current build platform -->
10+
<!-- List of runtimes supported by Gee.External.Capstone: https://github.com/9ee1/Capstone.NET/tree/master/Gee.External.Capstone/runtimes -->
11+
<BenchmarkDotNetTargetPlatform Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</BenchmarkDotNetTargetPlatform>
12+
<BenchmarkDotNetTargetPlatform Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</BenchmarkDotNetTargetPlatform>
13+
<BenchmarkDotNetTargetPlatform Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</BenchmarkDotNetTargetPlatform>
14+
15+
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X64'">$(BenchmarkDotNetTargetPlatform)-x64</BenchmarkDotNetTargetPlatform>
16+
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'X86'">$(BenchmarkDotNetTargetPlatform)-x86</BenchmarkDotNetTargetPlatform>
17+
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm'">$(BenchmarkDotNetTargetPlatform)-arm</BenchmarkDotNetTargetPlatform>
18+
<BenchmarkDotNetTargetPlatform Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">$(BenchmarkDotNetTargetPlatform)-arm64</BenchmarkDotNetTargetPlatform>
19+
</PropertyGroup>
20+
21+
<Target Name="FilterBenchmarkDotNetPackageAssets" AfterTargets="ResolvePackageAssets">
22+
<!-- Remove `runtimes/{RuntimeIdentifier}` files that is not matched to target platform. -->
23+
<ItemGroup Condition="'$(BenchmarkDotNetTargetPlatform)' != '' AND $(BenchmarkDotNetTargetPlatform) != 'all'">
24+
<RuntimeTargetsCopyLocalItems Remove="@(RuntimeTargetsCopyLocalItems)"
25+
Condition="'%(RuntimeTargetsCopyLocalItems.NuGetPackageId)' == 'Gee.External.Capstone' AND '%(RuntimeTargetsCopyLocalItems.RuntimeIdentifier)' != '$(BenchmarkDotNetTargetPlatform)'" />
26+
</ItemGroup>
27+
28+
<!-- Remove unnecessary satellite assemblies. -->
29+
<ItemGroup>
30+
<ResourceCopyLocalItems Remove="@(ResourceCopyLocalItems)"
31+
Condition="'%(ResourceCopyLocalItems.NuGetPackageId)' == 'Microsoft.CodeAnalysis.Common' OR '%(ResourceCopyLocalItems.NuGetPackageId)' == 'Microsoft.CodeAnalysis.CSharp'"/>
32+
</ItemGroup>
33+
</Target>
34+
</Project>

0 commit comments

Comments
 (0)