Skip to content

Commit 9202503

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

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,7 +62,7 @@ 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);
@@ -71,8 +71,8 @@ protected override string GetIntermediateDirectoryPath(string buildArtifactsDire
7171
=> Path.Combine(buildArtifactsDirectoryPath, "obj", configuration, TargetFrameworkMoniker);
7272

7373
[SuppressMessage("ReSharper", "StringLiteralTypo")] // R# complains about $variables$
74-
private string LoadCsProj(string template, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
75-
=> new StringBuilder(ResourceHelper.LoadTemplate(template))
74+
private string LoadCsProj(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
75+
=> new StringBuilder(ResourceHelper.LoadTemplate("CsProj.txt"))
7676
.Replace("$PLATFORM$", buildPartition.Platform.ToConfig())
7777
.Replace("$CODEFILENAME$", Path.GetFileName(artifactsPaths.ProgramCodePath))
7878
.Replace("$CSPROJPATH$", projectFile)
@@ -88,35 +88,35 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
8888
{
8989
var projectFile = GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger);
9090

91-
GenerateBuildTraversalProject(artifactsPaths, projectFile.FullName);
92-
9391
var xmlDoc = new XmlDocument();
9492
xmlDoc.Load(projectFile.FullName);
9593
var (customProperties, sdkName) = GetSettingsThatNeedToBeCopied(xmlDoc, projectFile);
9694

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

10999
File.WriteAllText(artifactsPaths.ProjectFilePath, content);
110100
}
111101

112-
protected void GenerateBuildTraversalProject(ArtifactsPaths artifactsPaths, string projectFilePath)
102+
protected void GenerateBuildForReferencesProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, string projectFile, string customProperties, string sdkName)
113103
{
114-
var content = new StringBuilder(ResourceHelper.LoadTemplate("BuildTraversalProj.txt"))
115-
.Replace("$CSPROJPATH$", projectFilePath)
116-
.Replace("$TFM$", TargetFrameworkMoniker)
117-
.ToString();
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";
118118

119-
File.WriteAllText(artifactsPaths.BuildTraversalProjectFilePath, content);
119+
xmlDoc.Save(artifactsPaths.BuildForReferencesProjectFilePath);
120120
}
121121

122122
/// <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
@@ -101,8 +101,8 @@ protected override void CopyAllRequiredFiles(ArtifactsPaths artifactsPaths)
101101
protected override void GenerateBuildScript(BuildPartition buildPartition, ArtifactsPaths artifactsPaths)
102102
{
103103
var content = new StringBuilder(300)
104-
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath)}")
105-
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.BuildTraversalProjectFilePath)}")
104+
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath)}")
105+
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.BuildForReferencesProjectFilePath)}")
106106
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetRestoreCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath)}")
107107
.AppendLine($"call {CliPath ?? "dotnet"} {DotNetCliCommand.GetBuildCommand(artifactsPaths, buildPartition, artifactsPaths.ProjectFilePath)}")
108108
.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)