@@ -61,37 +61,64 @@ 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 protected override string GetIntermediateDirectoryPath ( string buildArtifactsDirectoryPath , string configuration )
6871 => Path . Combine ( buildArtifactsDirectoryPath , "obj" , configuration , TargetFrameworkMoniker ) ;
6972
70- [ SuppressMessage ( "ReSharper" , "StringLiteralTypo" ) ] // R# complains about $variables$
71- protected override void GenerateProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
72- {
73- var benchmark = buildPartition . RepresentativeBenchmarkCase ;
74- var projectFile = GetProjectFilePath ( benchmark . Descriptor . Type , logger ) ;
75-
76- var xmlDoc = new XmlDocument ( ) ;
77- xmlDoc . Load ( projectFile . FullName ) ;
78- var ( customProperties , sdkName ) = GetSettingsThatNeedToBeCopied ( xmlDoc , projectFile ) ;
79-
80- var content = new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
73+ private string LoadCsProj ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , string projectFile , string customProperties , string sdkName )
74+ => new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
8175 . Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
8276 . Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
83- . Replace ( "$CSPROJPATH$" , projectFile . FullName )
77+ . Replace ( "$CSPROJPATH$" , projectFile )
8478 . Replace ( "$TFM$" , TargetFrameworkMoniker )
8579 . Replace ( "$PROGRAMNAME$" , artifactsPaths . ProgramName )
86- . Replace ( "$RUNTIMESETTINGS$" , GetRuntimeSettings ( benchmark . Job . Environment . Gc , buildPartition . Resolver ) )
80+ . Replace ( "$RUNTIMESETTINGS$" , GetRuntimeSettings ( buildPartition . RepresentativeBenchmarkCase . Job . Environment . Gc , buildPartition . Resolver ) )
8781 . Replace ( "$COPIEDSETTINGS$" , customProperties )
8882 . Replace ( "$CONFIGURATIONNAME$" , buildPartition . BuildConfiguration )
8983 . Replace ( "$SDKNAME$" , sdkName )
9084 . ToString ( ) ;
9185
86+ [ SuppressMessage ( "ReSharper" , "StringLiteralTypo" ) ] // R# complains about $variables$
87+ protected override void GenerateProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , ILogger logger )
88+ {
89+ var projectFile = GetProjectFilePath ( buildPartition . RepresentativeBenchmarkCase . Descriptor . Type , logger ) ;
90+
91+ var xmlDoc = new XmlDocument ( ) ;
92+ xmlDoc . Load ( projectFile . FullName ) ;
93+ var ( customProperties , sdkName ) = GetSettingsThatNeedToBeCopied ( xmlDoc , projectFile ) ;
94+
95+ GenerateBuildForReferencesProject ( buildPartition , artifactsPaths , projectFile . FullName , customProperties , sdkName ) ;
96+
97+ var content = LoadCsProj ( buildPartition , artifactsPaths , projectFile . FullName , customProperties , sdkName ) ;
98+
9299 File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
93100 }
94101
102+ protected void GenerateBuildForReferencesProject ( BuildPartition buildPartition , ArtifactsPaths artifactsPaths , string projectFile , string customProperties , string sdkName )
103+ {
104+ var content = LoadCsProj ( buildPartition , artifactsPaths , projectFile , customProperties , sdkName ) ;
105+
106+ // We don't include the generated .notcs file when building the reference dlls, only in the final build.
107+ var xmlDoc = new XmlDocument ( ) ;
108+ xmlDoc . Load ( new StringReader ( content ) ) ;
109+ XmlElement projectElement = xmlDoc . DocumentElement ;
110+ projectElement . RemoveChild ( projectElement . SelectSingleNode ( "ItemGroup/Compile" ) . ParentNode ) ;
111+
112+ var startupObjectElement = projectElement . SelectSingleNode ( "PropertyGroup/StartupObject" ) ;
113+ startupObjectElement . ParentNode . RemoveChild ( startupObjectElement ) ;
114+
115+ // We need to change the output type to library since we're only compiling for dlls.
116+ var outputTypeElement = projectElement . SelectSingleNode ( "PropertyGroup/OutputType" ) ;
117+ outputTypeElement . InnerText = "Library" ;
118+
119+ xmlDoc . Save ( artifactsPaths . BuildForReferencesProjectFilePath ) ;
120+ }
121+
95122 /// <summary>
96123 /// returns an MSBuild string that defines Runtime settings
97124 /// </summary>
0 commit comments