@@ -61,6 +61,9 @@ 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
@@ -77,6 +80,8 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
7780 xmlDoc . Load ( projectFile . FullName ) ;
7881 var ( customProperties , sdkName ) = GetSettingsThatNeedToBeCopied ( xmlDoc , projectFile ) ;
7982
83+ GenerateBuildForReferencesProject ( buildPartition , artifactsPaths , projectFile . FullName , customProperties , sdkName ) ;
84+
8085 var content = new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
8186 . Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
8287 . Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
@@ -92,6 +97,36 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
9297 File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
9398 }
9499
100+ protected void GenerateBuildForReferencesProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , string projectFile , string customProperties , string sdkName )
101+ {
102+ var content = new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
103+ . Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
104+ . Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
105+ . Replace ( "$CSPROJPATH$" , projectFile )
106+ . Replace ( "$TFM$" , TargetFrameworkMoniker )
107+ . Replace ( "$PROGRAMNAME$" , artifactsPaths . ProgramName )
108+ . Replace ( "$RUNTIMESETTINGS$" , GetRuntimeSettings ( buildPartition . RepresentativeBenchmarkCase . Job . Environment . Gc , buildPartition . Resolver ) )
109+ . Replace ( "$COPIEDSETTINGS$" , customProperties )
110+ . Replace ( "$CONFIGURATIONNAME$" , buildPartition . BuildConfiguration )
111+ . Replace ( "$SDKNAME$" , sdkName )
112+ . ToString ( ) ;
113+
114+ // We don't include the generated .notcs file when building the reference dlls, only in the final build.
115+ var xmlDoc = new XmlDocument ( ) ;
116+ xmlDoc . Load ( new StringReader ( content ) ) ;
117+ XmlElement projectElement = xmlDoc . DocumentElement ;
118+ projectElement . RemoveChild ( projectElement . SelectSingleNode ( "ItemGroup/Compile" ) . ParentNode ) ;
119+
120+ var startupObjectElement = projectElement . SelectSingleNode ( "PropertyGroup/StartupObject" ) ;
121+ startupObjectElement . ParentNode . RemoveChild ( startupObjectElement ) ;
122+
123+ // We need to change the output type to library since we're only compiling for dlls.
124+ var outputTypeElement = projectElement . SelectSingleNode ( "PropertyGroup/OutputType" ) ;
125+ outputTypeElement . InnerText = "Library" ;
126+
127+ xmlDoc . Save ( artifactsPaths . BuildForReferencesProjectFilePath ) ;
128+ }
129+
95130 /// <summary>
96131 /// returns an MSBuild string that defines Runtime settings
97132 /// </summary>
0 commit comments