Skip to content

Commit aea66e5

Browse files
committed
Don't write module if it's unnecessary.
Don't fail silently. Remove unused property. Embed the weaver into BenchmarkDotNet.Annotations package instead of another package dependency.
1 parent c431200 commit aea66e5

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<AssemblyTitle>Basic BenchmarkDotNet attributes that can be used to annotate your benchmarks</AssemblyTitle>
55
<TargetFrameworks>netstandard2.0</TargetFrameworks>
6-
<NoWarn>$(NoWarn);1701;1702;1705;1591;3005;NU1702;CA1825</NoWarn>
6+
<NoWarn>$(NoWarn);1701;1702;1705;1591;3005;NU1702;NU5100;CA1825</NoWarn>
77
<AssemblyName>BenchmarkDotNet.Annotations</AssemblyName>
88
<PackageId>BenchmarkDotNet.Annotations</PackageId>
99
<RootNamespace>BenchmarkDotNet</RootNamespace>
@@ -17,9 +17,10 @@
1717

1818
<Choose>
1919
<When Condition="'$(IsFullPack)' == 'true'">
20-
<!-- ProjectReference to ensure the nuget package has a dependency on BenchmarkDotNet.Weaver using the proper version. -->
2120
<ItemGroup>
22-
<ProjectReference Include="..\BenchmarkDotNet.Weaver\BenchmarkDotNet.Weaver.csproj" />
21+
<!-- Include the BenchmarkDotNet.Weaver dlls in tasks without making it an explicit dependency. -->
22+
<Content Include="$(MSBuildThisFileDirectory)..\BenchmarkDotNet.Weaver\bin\Release\$(TargetFramework)\**\*.dll" Pack="true" PackagePath="tasks/$(TargetFramework)" />
23+
<Content Include="$(MSBuildThisFileDirectory)buildTransitive\**\*.targets" Pack="true" PackagePath="buildTransitive" />
2324
</ItemGroup>
2425
</When>
2526
<Otherwise>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Reference Include="BenchmarkDotNet.Annotations">
5+
<HintPath>$(MSBuildThisFileDirectory)..\..\lib\netstandard2.0\BenchmarkDotNet.Annotations.dll</HintPath>
6+
</Reference>
7+
</ItemGroup>
8+
9+
<UsingTask TaskName="BenchmarkDotNet.Weaver.WeaveAssemblyTask" AssemblyFile="$(MSBuildThisFileDirectory)..\..\tasks\netstandard2.0\BenchmarkDotNet.Weaver.dll" />
10+
11+
<Target Name="WeaveAssemblies" AfterTargets="AfterBuild" >
12+
<WeaveAssemblyTask TargetAssembly="$(TargetDir)$(TargetFileName)" />
13+
</Target>
14+
</Project>

src/BenchmarkDotNet.Weaver/BenchmarkDotNet.Weaver.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ then run `build.cmd pack-weaver`.
1212
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1313
<IncludeBuildOutput>false</IncludeBuildOutput>
1414
<NoWarn>$(NoWarn);NU5100;NU5128</NoWarn>
15+
<!-- AsmResolver is not signed. -->
1516
<SignAssembly>false</SignAssembly>
1617
<DelaySign>false</DelaySign>
18+
<!-- Fix error NU5017: Cannot create a package that has no dependencies nor content. -->
19+
<IsPackable Condition="'$(IsFullPack)' == 'true'">false</IsPackable>
1720
</PropertyGroup>
1821

1922
<ItemGroup>

src/BenchmarkDotNet.Weaver/buildTransitive/netstandard2.0/BenchmarkDotNet.Weaver.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<UsingTask TaskName="BenchmarkDotNet.Weaver.WeaveAssemblyTask" AssemblyFile="$(MSBuildThisFileDirectory)..\..\tasks\netstandard2.0\BenchmarkDotNet.Weaver.dll" />
44

55
<Target Name="WeaveAssemblies" AfterTargets="AfterBuild" >
6-
<WeaveAssemblyTask TargetDir="$(TargetDir)" TargetAssembly="$(TargetDir)$(TargetFileName)" />
6+
<WeaveAssemblyTask TargetAssembly="$(TargetDir)$(TargetFileName)" />
77
</Target>
88
</Project>
Binary file not shown.

src/BenchmarkDotNet.Weaver/src/WeaveAssemblyTask.cs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@ namespace BenchmarkDotNet.Weaver;
1818
/// </summary>
1919
public sealed class WeaveAssemblyTask : Task
2020
{
21-
/// <summary>
22-
/// The directory of the output.
23-
/// </summary>
24-
[Required]
25-
public string TargetDir { get; set; }
26-
2721
/// <summary>
2822
/// The path of the target assembly.
2923
/// </summary>
@@ -42,12 +36,12 @@ public override bool Execute()
4236
return false;
4337
}
4438

45-
// Load the assembly using AsmResolver.
46-
var module = ModuleDefinition.FromFile(TargetAssembly);
4739

4840
bool benchmarkMethodsImplAdjusted = false;
4941
try
5042
{
43+
var module = ModuleDefinition.FromFile(TargetAssembly);
44+
5145
foreach (var type in module.GetAllTypes())
5246
{
5347
// We can skip non-public types as they are not valid for benchmarks.
@@ -68,16 +62,15 @@ public override bool Execute()
6862
}
6963
}
7064

71-
// Write the modified assembly to file.
72-
module.Write(TargetAssembly);
73-
}
74-
catch (Exception e)
75-
{
7665
if (benchmarkMethodsImplAdjusted)
7766
{
78-
Log.LogWarning($"Benchmark methods were found that require NoInlining, and assembly weaving failed.{Environment.NewLine}{e}");
67+
module.Write(TargetAssembly);
7968
}
8069
}
70+
catch (Exception e)
71+
{
72+
Log.LogWarning($"Assembly weaving failed. Benchmark methods found requiring NoInlining: {benchmarkMethodsImplAdjusted}. Error:{Environment.NewLine}{e}");
73+
}
8174
return true;
8275
}
8376

0 commit comments

Comments
 (0)