@@ -61,33 +61,60 @@ protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPar
6161 protected override string GetProjectFilePath ( string buildArtifactsDirectoryPath )
6262 => Path . Combine ( buildArtifactsDirectoryPath , "BenchmarkDotNet.Autogenerated.csproj" ) ;
6363
64+ protected override string GetProjectFilePathForReferences ( string buildArtifactsDirectoryPath )
65+ => Path . Combine ( buildArtifactsDirectoryPath , "BenchmarkDotNet.Autogenerated.ForReferences.csproj" ) ;
66+
6467 protected override string GetBinariesDirectoryPath ( string buildArtifactsDirectoryPath , string configuration )
6568 => Path . Combine ( buildArtifactsDirectoryPath , "bin" , configuration , TargetFrameworkMoniker ) ;
6669
6770 [ SuppressMessage ( "ReSharper" , "StringLiteralTypo" ) ] // R# complains about $variables$
68- protected override void GenerateProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
69- {
70- var benchmark = buildPartition . RepresentativeBenchmarkCase ;
71- var projectFile = GetProjectFilePath ( benchmark . Descriptor . Type , logger ) ;
72-
73- var xmlDoc = new XmlDocument ( ) ;
74- xmlDoc . Load ( projectFile . FullName ) ;
75- var ( customProperties , sdkName ) = GetSettingsThatNeedToBeCopied ( xmlDoc , projectFile ) ;
76-
77- var content = new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
71+ private string LoadCsProj ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , string projectFile , string customProperties , string sdkName )
72+ => new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
7873 . Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
7974 . Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
80- . Replace ( "$CSPROJPATH$" , projectFile . FullName )
75+ . Replace ( "$CSPROJPATH$" , projectFile )
8176 . Replace ( "$TFM$" , TargetFrameworkMoniker )
8277 . Replace ( "$PROGRAMNAME$" , artifactsPaths . ProgramName )
83- . Replace ( "$RUNTIMESETTINGS$" , GetRuntimeSettings ( benchmark . Job . Environment . Gc , buildPartition . Resolver ) )
78+ . Replace ( "$RUNTIMESETTINGS$" , GetRuntimeSettings ( buildPartition . RepresentativeBenchmarkCase . Job . Environment . Gc , buildPartition . Resolver ) )
8479 . Replace ( "$COPIEDSETTINGS$" , customProperties )
8580 . Replace ( "$SDKNAME$" , sdkName )
8681 . ToString ( ) ;
8782
83+ protected override void GenerateProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
84+ {
85+ var projectFile = GetProjectFilePath ( buildPartition . RepresentativeBenchmarkCase . Descriptor . Type , logger ) ;
86+
87+ var xmlDoc = new XmlDocument ( ) ;
88+ xmlDoc . Load ( projectFile . FullName ) ;
89+ var ( customProperties , sdkName ) = GetSettingsThatNeedToBeCopied ( xmlDoc , projectFile ) ;
90+
91+ GenerateBuildForReferencesProject ( buildPartition , artifactsPaths , projectFile . FullName , customProperties , sdkName ) ;
92+
93+ var content = LoadCsProj ( buildPartition , artifactsPaths , projectFile . FullName , customProperties , sdkName ) ;
94+
8895 File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
8996 }
9097
98+ protected void GenerateBuildForReferencesProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , string projectFile , string customProperties , string sdkName )
99+ {
100+ var content = LoadCsProj ( buildPartition , artifactsPaths , projectFile , customProperties , sdkName ) ;
101+
102+ // We don't include the generated .notcs file when building the reference dlls, only in the final build.
103+ var xmlDoc = new XmlDocument ( ) ;
104+ xmlDoc . Load ( new StringReader ( content ) ) ;
105+ XmlElement projectElement = xmlDoc . DocumentElement ;
106+ projectElement . RemoveChild ( projectElement . SelectSingleNode ( "ItemGroup/Compile" ) . ParentNode ) ;
107+
108+ var startupObjectElement = projectElement . SelectSingleNode ( "PropertyGroup/StartupObject" ) ;
109+ startupObjectElement . ParentNode . RemoveChild ( startupObjectElement ) ;
110+
111+ // We need to change the output type to library since we're only compiling for dlls.
112+ var outputTypeElement = projectElement . SelectSingleNode ( "PropertyGroup/OutputType" ) ;
113+ outputTypeElement . InnerText = "Library" ;
114+
115+ xmlDoc . Save ( artifactsPaths . BuildForReferencesProjectFilePath ) ;
116+ }
117+
91118 /// <summary>
92119 /// returns an MSBuild string that defines Runtime settings
93120 /// </summary>
0 commit comments