@@ -61,37 +61,64 @@ 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
protected override string GetIntermediateDirectoryPath ( string buildArtifactsDirectoryPath , string configuration )
68
71
=> Path . Combine ( buildArtifactsDirectoryPath , "obj" , configuration , TargetFrameworkMoniker ) ;
69
72
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" ) )
81
75
. Replace ( "$PLATFORM$" , buildPartition . Platform . ToConfig ( ) )
82
76
. Replace ( "$CODEFILENAME$" , Path . GetFileName ( artifactsPaths . ProgramCodePath ) )
83
- . Replace ( "$CSPROJPATH$" , projectFile . FullName )
77
+ . Replace ( "$CSPROJPATH$" , projectFile )
84
78
. Replace ( "$TFM$" , TargetFrameworkMoniker )
85
79
. 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 ) )
87
81
. Replace ( "$COPIEDSETTINGS$" , customProperties )
88
82
. Replace ( "$CONFIGURATIONNAME$" , buildPartition . BuildConfiguration )
89
83
. Replace ( "$SDKNAME$" , sdkName )
90
84
. ToString ( ) ;
91
85
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
+
92
99
File . WriteAllText ( artifactsPaths . ProjectFilePath , content ) ;
93
100
}
94
101
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
+
95
122
/// <summary>
96
123
/// returns an MSBuild string that defines Runtime settings
97
124
/// </summary>
0 commit comments