Skip to content

Commit c7dc870

Browse files
committed
Revert "Use a build traversal project template instead of copying csproj template."
This reverts commit f1bc9fa.
1 parent 5a68440 commit c7dc870

File tree

13 files changed

+49
-49
lines changed

13 files changed

+49
-49
lines changed

src/BenchmarkDotNet/Templates/BuildTraversalProj.txt

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/BenchmarkDotNet/Toolchains/ArtifactsPaths.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ArtifactsPaths
1313
[PublicAPI] public string ProgramCodePath { get; }
1414
[PublicAPI] public string AppConfigPath { get; }
1515
[PublicAPI] public string NuGetConfigPath { get; }
16-
[PublicAPI] public string BuildTraversalProjectFilePath { get; }
16+
[PublicAPI] public string BuildForReferencesProjectFilePath { get; }
1717
[PublicAPI] public string ProjectFilePath { get; }
1818
[PublicAPI] public string BuildScriptFilePath { get; }
1919
[PublicAPI] public string ExecutablePath { get; }
@@ -28,7 +28,7 @@ public ArtifactsPaths(
2828
string programCodePath,
2929
string appConfigPath,
3030
string nuGetConfigPath,
31-
string buildTraversalProjectFilePath,
31+
string buildForReferencesProjectFilePath,
3232
string projectFilePath,
3333
string buildScriptFilePath,
3434
string executablePath,
@@ -42,7 +42,7 @@ public ArtifactsPaths(
4242
ProgramCodePath = programCodePath;
4343
AppConfigPath = appConfigPath;
4444
NuGetConfigPath = nuGetConfigPath;
45-
BuildTraversalProjectFilePath = buildTraversalProjectFilePath;
45+
BuildForReferencesProjectFilePath = buildForReferencesProjectFilePath;
4646
ProjectFilePath = projectFilePath;
4747
BuildScriptFilePath = buildScriptFilePath;
4848
ExecutablePath = executablePath;

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ protected override string GetProjectFilePath(string buildArtifactsDirectoryPath)
6262
=> Path.Combine(buildArtifactsDirectoryPath, "BenchmarkDotNet.Autogenerated.csproj");
6363

6464
protected override string GetProjectFilePathForReferences(string buildArtifactsDirectoryPath)
65-
=> Path.Combine(buildArtifactsDirectoryPath, "BuildTraversal.buildproj");
65+
=> Path.Combine(buildArtifactsDirectoryPath, "BenchmarkDotNet.Autogenerated.ForReferences.csproj");
6666

6767
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
6868
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker);
6969

7070
[SuppressMessage("ReSharper", "StringLiteralTypo")] // R# complains about $variables$
71-
private string LoadCsProj(string template, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
72-
=> new StringBuilder(ResourceHelper.LoadTemplate(template))
71+
private string LoadCsProj(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
72+
=> new StringBuilder(ResourceHelper.LoadTemplate("CsProj.txt"))
7373
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
7474
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
7575
.Replace("$CSPROJPATH$", projectFile)
@@ -84,35 +84,35 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
8484
{
8585
var projectFile = GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger);
8686

87-
GenerateBuildTraversalProject(artifactsPaths, projectFile.FullName);
88-
8987
var xmlDoc = new XmlDocument();
9088
xmlDoc.Load(projectFile.FullName);
9189
var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile);
9290

93-
var content = new StringBuilder(ResourceHelper.LoadTemplate("CsProj.txt"))
94-
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
95-
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
96-
.Replace("$CSPROJPATH$", projectFile.FullName)
97-
.Replace("$TFM$", TargetFrameworkMoniker)
98-
.Replace("$PROGRAMNAME$", artifactsPaths.ProgramName)
99-
.Replace("$RUNTIMESETTINGS$", GetRuntimeSettings(buildPartition.RepresentativeBenchmarkCase.Job.Environment.Gc, buildPartition.Resolver))
100-
.Replace("$COPIEDSETTINGS$", customProperties)
101-
.Replace("$CONFIGURATIONNAME$", buildPartition.BuildConfiguration)
102-
.Replace("$SDKNAME$", sdkName)
103-
.ToString();
91+
GenerateBuildForReferencesProject(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);
92+
93+
var content = LoadCsProj(buildPartition, artifactsPaths, projectFile.FullName, customProperties, sdkName);
10494

10595
File.WriteAllText(artifactsPaths.ProjectFilePath, content);
10696
}
10797

108-
protected void GenerateBuildTraversalProject(ArtifactsPaths artifactsPaths, string projectFilePath)
98+
protected void GenerateBuildForReferencesProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
10999
{
110-
var content = new StringBuilder(ResourceHelper.LoadTemplate("BuildTraversalProj.txt"))
111-
.Replace("$CSPROJPATH$", projectFilePath)
112-
.Replace("$TFM$", TargetFrameworkMoniker)
113-
.ToString();
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";
114114

115-
File.WriteAllText(artifactsPaths.BuildTraversalProjectFilePath, content);
115+
xmlDoc.Save(artifactsPaths.BuildForReferencesProjectFilePath);
116116
}
117117

118118
/// <summary>

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliBuilder.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public DotNetCliBuilder(string targetFrameworkMoniker, string? customDotNetCliPa
2828
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
2929
{
3030
var cliCommand = new DotNetCliCommand(
31-
generateResult.ArtifactsPaths.BuildTraversalProjectFilePath,
31+
generateResult.ArtifactsPaths.BuildForReferencesProjectFilePath,
3232
CustomDotNetCliPath,
3333
string.Empty,
3434
generateResult,
@@ -75,6 +75,11 @@ internal static void GatherReferences(ArtifactsPaths artifactsPaths)
7575
foreach (var assemblyFile in Directory.GetFiles(artifactsPaths.BinariesDirectoryPath, "*.dll"))
7676
{
7777
var assemblyName = Path.GetFileNameWithoutExtension(assemblyFile);
78+
// The dummy csproj was used to build the original project, but it also outputs a dll for itself which we need to ignore because it's not valid.
79+
if (assemblyName == artifactsPaths.ProgramName)
80+
{
81+
continue;
82+
}
7883
var referenceElement = xmlDoc.CreateElement("Reference");
7984
itemGroup.AppendChild(referenceElement);
8085
referenceElement.SetAttribute("Include", assemblyName);

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ protected override void CopyAllRequiredFiles(ArtifactsPaths artifactsPaths)
103103
protected override void GenerateBuildScript(BuildPartition buildPartition, ArtifactsPaths artifactsPaths)
104104
{
105105
var content = new StringBuilder(300)
106-
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath)}")
107-
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath)}")
106+
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath)}")
107+
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath)}")
108108
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath)}")
109109
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath)}")
110110
.ToString();

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public DotNetCliPublisher(
2727
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
2828
{
2929
var cliCommand = new DotNetCliCommand(
30-
generateResult.ArtifactsPaths.BuildTraversalProjectFilePath,
30+
generateResult.ArtifactsPaths.BuildForReferencesProjectFilePath,
3131
CustomDotNetCliPath,
3232
ExtraArguments,
3333
generateResult,

src/BenchmarkDotNet/Toolchains/GeneratorBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
150150
appConfigPath: $"{executablePath}.config",
151151
nuGetConfigPath: Path.Combine(buildArtifactsDirectoryPath, "NuGet.config"),
152152
projectFilePath: GetProjectFilePath(buildArtifactsDirectoryPath),
153-
buildTraversalProjectFilePath: GetProjectFilePathForReferences(buildArtifactsDirectoryPath),
153+
buildForReferencesProjectFilePath: GetProjectFilePathForReferences(buildArtifactsDirectoryPath),
154154
buildScriptFilePath: Path.Combine(buildArtifactsDirectoryPath, $"{programName}{OsDetector.ScriptFileExtension}"),
155155
executablePath: executablePath,
156156
programName: programName,

src/BenchmarkDotNet/Toolchains/InProcess/Emit/InProcessEmitArtifactsPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public InProcessEmitArtifactsPath(
1717
baseArtifacts.AppConfigPath,
1818
baseArtifacts.NuGetConfigPath,
1919
baseArtifacts.ProjectFilePath,
20-
baseArtifacts.BuildTraversalProjectFilePath,
20+
baseArtifacts.BuildForReferencesProjectFilePath,
2121
baseArtifacts.BuildScriptFilePath,
2222
baseArtifacts.ExecutablePath,
2323
baseArtifacts.ProgramName,

src/BenchmarkDotNet/Toolchains/InProcess/Emit/InProcessEmitGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
5252
appConfigPath: null,
5353
nuGetConfigPath: null,
5454
projectFilePath: null,
55-
buildTraversalProjectFilePath: null,
55+
buildForReferencesProjectFilePath: null,
5656
buildScriptFilePath: null,
5757
executablePath: executablePath,
5858
programName: programName,

src/BenchmarkDotNet/Toolchains/Mono/MonoPublisher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public MonoPublisher(string customDotNetCliPath)
2727
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger)
2828
{
2929
var cliCommand = new DotNetCliCommand(
30-
generateResult.ArtifactsPaths.BuildTraversalProjectFilePath,
30+
generateResult.ArtifactsPaths.BuildForReferencesProjectFilePath,
3131
CustomDotNetCliPath,
3232
string.Empty,
3333
generateResult,

0 commit comments

Comments
 (0)