Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/BenchmarkDotNet/Templates/CsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,12 @@
<AssemblyName>$PROGRAMNAME$</AssemblyName>
<OutputType>Exe</OutputType>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<!-- Usage of System.Random can cause compilation errors if Code Analysis warnings are treated as Errors -->
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>false</MSBuildTreatWarningsAsErrors>
<!-- disabled due to https://github.com/dotnet/roslyn/issues/59421 -->
<DebugSymbols>false</DebugSymbols>
<UseSharedCompilation>false</UseSharedCompilation>
<CodeAnalysisRuleSet></CodeAnalysisRuleSet>
<RunAnalyzers>false</RunAnalyzers>
<Deterministic>true</Deterministic>
<!-- needed for custom build configurations (only "Release" builds are optimized by default) -->
<Optimize Condition=" '$(Configuration)' != 'Debug' ">true</Optimize>
<!-- fix for NETSDK1150: https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/5.0/referencing-executable-generates-error -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<!-- Suppress warning for nuget package used in old (unsupported) tfm. -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>
</PropertyGroup>

Expand Down
6 changes: 4 additions & 2 deletions src/BenchmarkDotNet/Templates/MonoAOTLLVMCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>false</MSBuildTreatWarningsAsErrors>
<RunAnalyzers>false</RunAnalyzers>
<TargetFrameworks>$TFM$</TargetFrameworks>
<MicrosoftNetCoreAppRuntimePackDir>$RUNTIMEPACK$</MicrosoftNetCoreAppRuntimePackDir>
<RuntimeIdentifier>$RUNTIMEIDENTIFIER$</RuntimeIdentifier>
<EnableTargetingPackDownload>false</EnableTargetingPackDownload>
<PublishTrimmed>false</PublishTrimmed>
<AssemblyName>$PROGRAMNAME$</AssemblyName>
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>
<SelfContained>true</SelfContained>
<!-- Suppress warning for nuget package used in old (unsupported) tfm. -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 1 addition & 9 deletions src/BenchmarkDotNet/Templates/R2RCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@
<AssemblyName>$PROGRAMNAME$</AssemblyName>
<OutputType>Exe</OutputType>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<!-- Usage of System.Random can cause compilation errors if Code Analysis warnings are treated as Errors -->
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>false</MSBuildTreatWarningsAsErrors>
<!-- disabled due to https://github.com/dotnet/roslyn/issues/59421 -->
<DebugSymbols>false</DebugSymbols>
<UseSharedCompilation>false</UseSharedCompilation>
<CodeAnalysisRuleSet></CodeAnalysisRuleSet>
<RunAnalyzers>false</RunAnalyzers>
<Deterministic>true</Deterministic>
<!-- needed for custom build configurations (only "Release" builds are optimized by default) -->
<Optimize Condition=" '$(Configuration)' != 'Debug' ">true</Optimize>
<!-- fix for NETSDK1150: https://docs.microsoft.com/en-us/dotnet/core/compatibility/sdk/5.0/referencing-executable-generates-error -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<!-- Suppress warning for nuget package used in old (unsupported) tfm. -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>
<!-- workaround for 'Found multiple publish output files with the same relative path.' error -->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
Expand Down
5 changes: 3 additions & 2 deletions src/BenchmarkDotNet/Templates/WasmCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
$CORECLR_OVERRIDES$
<PropertyGroup>
<OutputType>Exe</OutputType>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>false</MSBuildTreatWarningsAsErrors>
<RunAnalyzers>false</RunAnalyzers>
<RuntimeConfig>Release</RuntimeConfig>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TargetFrameworks>$TFM$</TargetFrameworks>
Expand All @@ -23,8 +26,6 @@ $CORECLR_OVERRIDES$
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<EnableDefaultWasmAssembliesToBundle>false</EnableDefaultWasmAssembliesToBundle>
<!-- Suppress warning for nuget package used in old (unsupported) tfm. -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>
</PropertyGroup>

Expand Down
13 changes: 11 additions & 2 deletions src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ public class CsProjGenerator : DotNetCliGenerator, IEquatable<CsProjGenerator>
"UserSecretsId",
"EnablePreviewFeatures",
"RuntimeHostConfigurationOption",
"WarningsAsErrors",
"Features",
"GarbageCollectionAdaptationMode" // TODO: Remove this setting after https://github.com/dotnet/runtime/pull/131069 issue is resolved, and backported to .NET 10.

"WarningsAsErrors",
"WarningsNotAsErrors",
"WarningLevel",
"NoWarn",
"MSBuildWarningsAsErrors",
"MSBuildWarningsNotAsErrors",
"MSBuildWarningsAsMessages",
"SuppressTfmSupportBuildWarnings",

"GarbageCollectionAdaptationMode", // TODO: Remove this setting after https://github.com/dotnet/runtime/pull/131069 issue is resolved, and backported to .NET 10.
}.ToImmutableArray();

public string RuntimeFrameworkVersion { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.Results;
using JetBrains.Annotations;
using System.Collections.Immutable;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
Expand Down Expand Up @@ -56,9 +57,38 @@ public static async Task<DotNetCliCommandResult> ExecuteAsync(DotNetCliCommand p

parameters.Logger.WriteLineInfo($"// command took {stopwatch.Elapsed.TotalSeconds.ToInvariantString("0.##")} sec and exited with {process.ExitCode}");

return process.ExitCode <= 0
? DotNetCliCommandResult.Success(stopwatch.Elapsed, outputReader.GetOutputText())
: DotNetCliCommandResult.Failure(stopwatch.Elapsed, outputReader.GetOutputText(), outputReader.GetErrorText());
if (process.ExitCode != 0)
{
return DotNetCliCommandResult.Failure(stopwatch.Elapsed, outputReader.GetOutputText(), outputReader.GetErrorText());
}

// A successful build's output is otherwise discarded (see DotNetCliCommandResult.ToBuildResult), so
// build/restore warnings (e.g. NU1701, NU1702) would be invisible unless LogBuildOutput is set. When the
// full output isn't already being streamed, surface just the warning lines so they aren't silently lost.
if (!parameters.LogOutput)
LogBuildWarnings(parameters.Logger, outputReader.GetOutputLines());

return DotNetCliCommandResult.Success(stopwatch.Elapsed, outputReader.GetOutputText());
}

// Matches an MSBuild/NuGet warning line, e.g. "...csproj : warning NU1702: ..." or "...targets(1,5): warning NETSDK1138: ...".
private static readonly Regex BuildWarningRegex = new(@": warning [A-Za-z]+\d+:", RegexOptions.CultureInvariant | RegexOptions.Compiled);

// Surfaces just the warning lines from an otherwise-discarded successful build output, deduplicated
// (MSBuild repeats a warning per target framework and again in the summary).
private static void LogBuildWarnings(ILogger logger, ImmutableArray<string> outputLines)
{
HashSet<string>? seen = null;
foreach (var line in outputLines)
{
if (!BuildWarningRegex.IsMatch(line))
continue;

string warning = line.Trim();
seen ??= new HashSet<string>(StringComparer.Ordinal);
if (seen.Add(warning))
logger.WriteLineWarning($"// {warning}");
}
}

internal static string GetDotNetSdkVersion()
Expand Down
4 changes: 1 addition & 3 deletions src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ private string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartiti
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>{buildPartition.Platform.ToConfig()}</PlatformTarget>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<MSBuildTreatWarningsAsErrors>false</MSBuildTreatWarningsAsErrors>
<DebugSymbols>false</DebugSymbols>
<UseSharedCompilation>false</UseSharedCompilation>
<Deterministic>true</Deterministic>
<RunAnalyzers>false</RunAnalyzers>
<PublishAot Condition="$([MSBuild]::VersionGreaterThan('$(NETCoreSdkVersion)', '6.0'))">true</PublishAot>
<IlcOptimizationPreference>{ilcOptimizationPreference}</IlcOptimizationPreference>
Expand All @@ -160,7 +159,6 @@ private string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartiti
<EnsureNETCoreAppRuntime>false</EnsureNETCoreAppRuntime> <!-- workaround for 'This runtime may not be supported by.NET Core.' error -->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> <!-- workaround for 'Found multiple publish output files with the same relative path.' error -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings> <!-- Suppress warning for nuget package used in old (unsupported) tfm. -->
{GetInstructionSetSettings(buildPartition)}
</PropertyGroup>
{GetRuntimeSettings(buildPartition.RepresentativeBenchmarkCase.Job.Environment.Gc, buildPartition.Resolver)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public MultipleFrameworksTest(ITestOutputHelper output) : base(output)
}

[Theory]
[InlineData(RuntimeMoniker.Net461)]
[InlineData(RuntimeMoniker.Net462)]
[InlineData(RuntimeMoniker.Net48)]
[InlineData(RuntimeMoniker.NetCoreApp20)]
[InlineData(RuntimeMoniker.Net80)]
[InlineData(RuntimeMoniker.Net10_0)]
public void EachFrameworkIsRebuilt(RuntimeMoniker runtime)
{
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(runtime.GetRuntime()).WithEnvironmentVariable(TfmEnvVarName, runtime.ToString()));
Expand Down