@@ -61,33 +61,60 @@ 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
67
70
[ 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" ) )
78
73
. Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
79
74
. Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
80
- . Replace ( "$CSPROJPATH$" , projectFile . FullName )
75
+ . Replace ( "$CSPROJPATH$" , projectFile )
81
76
. Replace ( "$TFM$" , TargetFrameworkMoniker )
82
77
. 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 ) )
84
79
. Replace ( "$COPIEDSETTINGS$" , customProperties )
85
80
. Replace ( "$SDKNAME$" , sdkName )
86
81
. ToString ( ) ;
87
82
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
+
88
95
File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
89
96
}
90
97
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
+
91
118
/// <summary>
92
119
/// returns an MSBuild string that defines Runtime settings
93
120
/// </summary>
0 commit comments