@@ -19,6 +19,8 @@ namespace BenchmarkDotNet.Toolchains.CsProj
1919 public class CsProjGenerator : DotNetCliGenerator , IEquatable < CsProjGenerator >
2020 {
2121 private const string DefaultSdkName = "Microsoft.NET.Sdk" ;
22+ private const string DllGathererProjectName = "DllGatherer.csproj" ;
23+ private const string AutogeneratedProjectName = "BenchmarkDotNet.Autogenerated.csproj" ;
2224
2325 private static readonly ImmutableArray < string > SettingsWeWantToCopy = new [ ]
2426 {
@@ -58,11 +60,32 @@ protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPar
5860 }
5961
6062 protected override string GetProjectFilePath ( string buildArtifactsDirectoryPath )
61- => Path . Combine ( buildArtifactsDirectoryPath , "BenchmarkDotNet.Autogenerated.csproj" ) ;
63+ => Path . Combine ( buildArtifactsDirectoryPath , AutogeneratedProjectName ) ;
6264
6365 protected override string GetBinariesDirectoryPath ( string buildArtifactsDirectoryPath , string configuration )
6466 => Path . Combine ( buildArtifactsDirectoryPath , "bin" , configuration , TargetFrameworkMoniker ) ;
6567
68+ protected override async ValueTask GenerateCustomBuildHooksAsync ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger , CancellationToken cancellationToken )
69+ {
70+ var benchmark = buildPartition . RepresentativeBenchmarkCase ;
71+ var benchmarkProjectFile = GetProjectFilePath ( benchmark . Descriptor . Type , logger ) ;
72+
73+ var propsPath = Path . Combine ( artifactsPaths . BuildArtifactsDirectoryPath , "BenchmarkDotNet.Build.props" ) ;
74+ var props = GetTemplateContent ( "BenchmarkDotNet.Build.props.txt" ) ;
75+ await File . WriteAllTextAsync ( propsPath , props . ToString ( ) , cancellationToken ) . ConfigureAwait ( false ) ;
76+
77+ var targetsPath = Path . Combine ( artifactsPaths . BuildArtifactsDirectoryPath , "BenchmarkDotNet.Build.targets" ) ;
78+ var targets = GetTemplateContent ( "BenchmarkDotNet.Build.targets.txt" ) ;
79+ await File . WriteAllTextAsync ( targetsPath , targets . ToString ( ) , cancellationToken ) . ConfigureAwait ( false ) ;
80+
81+ string GetTemplateContent ( string templateName )
82+ => new StringBuilder ( ResourceHelper . LoadTemplate ( templateName ) )
83+ . Replace ( "$BENCHMARK_PROJ$" , benchmarkProjectFile . Name )
84+ . Replace ( "$GATHERER_PROJ$" , DllGathererProjectName )
85+ . Replace ( "$AUTOGENERATED_PROJ$" , AutogeneratedProjectName )
86+ . ToString ( ) ;
87+ }
88+
6689 protected override ValueTask GenerateBuildScriptAsync ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , CancellationToken cancellationToken )
6790 {
6891 string projectFilePath = GetProjectFilePath ( buildPartition . RepresentativeBenchmarkCase . Descriptor . Type , NullLogger . Instance ) . FullName ;
@@ -115,7 +138,7 @@ private async ValueTask<string> GenerateBuildProject(BuildPartition buildPartiti
115138 }
116139
117140 private static string GetDllGathererPath ( string filePath )
118- => Path . Combine ( Path . GetDirectoryName ( filePath ) ! , $ "DllGatherer { Path . GetExtension ( filePath ) } ") ;
141+ => Path . Combine ( Path . GetDirectoryName ( filePath ) ! , $ "{ Path . GetFileNameWithoutExtension ( DllGathererProjectName ) } { Path . GetExtension ( filePath ) } ") ;
119142
120143 protected async ValueTask GatherReferencesAsync ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger , CancellationToken cancellationToken )
121144 {
0 commit comments