@@ -61,6 +61,9 @@ protected override string GetBuildArtifactsDirectoryPath(BuildPartition buildPar
61
61
protected override string GetProjectFilePath ( string buildArtifactsDirectoryPath )
62
62
=> Path . Combine ( buildArtifactsDirectoryPath , "BenchmarkDotNet.Autogenerated.csproj" ) ;
63
63
64
+ protected override string GetProjectFilePathForReferences ( string buildArtifactsDirectoryPath )
65
+ => Path . Combine ( buildArtifactsDirectoryPath , "BenchmarkDotNet.Autogenerated.ForReferences.csproj" ) ;
66
+
64
67
protected override string GetBinariesDirectoryPath ( string buildArtifactsDirectoryPath , string configuration )
65
68
=> Path . Combine ( buildArtifactsDirectoryPath , "bin" , configuration , TargetFrameworkMoniker ) ;
66
69
@@ -77,6 +80,8 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
77
80
xmlDoc . Load ( projectFile . FullName ) ;
78
81
var ( customProperties , sdkName ) = GetSettingsThatNeedToBeCopied ( xmlDoc , projectFile ) ;
79
82
83
+ GenerateBuildForReferencesProject ( buildPartition , artifactsPaths , projectFile . FullName , customProperties , sdkName ) ;
84
+
80
85
var content = new StringBuilder ( ResourceHelper . LoadTemplate ( "CsProj.txt" ) )
81
86
. Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
82
87
. Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
@@ -92,6 +97,36 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
92
97
File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
93
98
}
94
99
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
+
95
130
/// <summary>
96
131
/// returns an MSBuild string that defines Runtime settings
97
132
/// </summary>
0 commit comments