Skip to content

Commit d93490d

Browse files
authored
Rebuild .Net Framework projects (#2370)
* Added `CsProjWithRoslynFallbackToolchain` for .Net Framework projects to be able to be rebuilt per target framework. * Move manual tests to separate solution. * Test old frameworks and test that recompilation actually happens. * Removed ClassicNetFramework project. Moved manual test projects back to main sln. * Removed `CsProjWithRoslynFallbackToolchain`, default to `CsProjClassicNetToolchain` instead. * Use RoslynToolchain if dotnet SDK is not installed. * Fix test. * Revert xunit.runner.json. Implement feedback. * Try to fix json file * Removed redundant commented line.
1 parent 64d05c6 commit d93490d

File tree

6 files changed

+122
-8
lines changed

6 files changed

+122
-8
lines changed

BenchmarkDotNet.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{
4747
EndProject
4848
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Templates", "templates\BenchmarkDotNet.Templates.csproj", "{B620D10A-CD8E-4A34-8B27-FD6257E63AD0}"
4949
EndProject
50-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Diagnostics.dotTrace", "src\BenchmarkDotNet.Diagnostics.dotTrace\BenchmarkDotNet.Diagnostics.dotTrace.csproj", "{C5BDA61F-3A56-4B59-901D-0A17E78F4076}"
50+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.Diagnostics.dotTrace", "src\BenchmarkDotNet.Diagnostics.dotTrace\BenchmarkDotNet.Diagnostics.dotTrace.csproj", "{C5BDA61F-3A56-4B59-901D-0A17E78F4076}"
51+
EndProject
52+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks", "tests\BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks\BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks.csproj", "{AACA2C63-A85B-47AB-99FC-72C3FF408B14}"
5153
EndProject
5254
Global
5355
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -131,6 +133,10 @@ Global
131133
{C5BDA61F-3A56-4B59-901D-0A17E78F4076}.Debug|Any CPU.Build.0 = Debug|Any CPU
132134
{C5BDA61F-3A56-4B59-901D-0A17E78F4076}.Release|Any CPU.ActiveCfg = Release|Any CPU
133135
{C5BDA61F-3A56-4B59-901D-0A17E78F4076}.Release|Any CPU.Build.0 = Release|Any CPU
136+
{AACA2C63-A85B-47AB-99FC-72C3FF408B14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
137+
{AACA2C63-A85B-47AB-99FC-72C3FF408B14}.Debug|Any CPU.Build.0 = Debug|Any CPU
138+
{AACA2C63-A85B-47AB-99FC-72C3FF408B14}.Release|Any CPU.ActiveCfg = Release|Any CPU
139+
{AACA2C63-A85B-47AB-99FC-72C3FF408B14}.Release|Any CPU.Build.0 = Release|Any CPU
134140
EndGlobalSection
135141
GlobalSection(SolutionProperties) = preSolution
136142
HideSolutionNode = FALSE
@@ -155,6 +161,7 @@ Global
155161
{D9F5065B-6190-431B-850C-117E3D64AB33} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
156162
{B620D10A-CD8E-4A34-8B27-FD6257E63AD0} = {63B94FD6-3F3D-4E04-9727-48E86AC4384C}
157163
{C5BDA61F-3A56-4B59-901D-0A17E78F4076} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
164+
{AACA2C63-A85B-47AB-99FC-72C3FF408B14} = {14195214-591A-45B7-851A-19D3BA2413F9}
158165
EndGlobalSection
159166
GlobalSection(ExtensibilityGlobals) = postSolution
160167
SolutionGuid = {4D9AF12B-1F7F-45A7-9E8C-E4E46ADCBD1F}

src/BenchmarkDotNet/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
[assembly: InternalsVisibleTo("BenchmarkDotNet.Diagnostics.Windows,PublicKey=" + BenchmarkDotNetInfo.PublicKey)]
1616
[assembly: InternalsVisibleTo("BenchmarkDotNet.Diagnostics.dotTrace,PublicKey=" + BenchmarkDotNetInfo.PublicKey)]
1717
[assembly: InternalsVisibleTo("BenchmarkDotNet.IntegrationTests.ManualRunning,PublicKey=" + BenchmarkDotNetInfo.PublicKey)]
18+
[assembly: InternalsVisibleTo("BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks,PublicKey=" + BenchmarkDotNetInfo.PublicKey)]
1819
#else
1920
[assembly: InternalsVisibleTo("BenchmarkDotNet.Tests")]
2021
[assembly: InternalsVisibleTo("BenchmarkDotNet.IntegrationTests")]
2122
[assembly: InternalsVisibleTo("BenchmarkDotNet.Diagnostics.Windows")]
2223
[assembly: InternalsVisibleTo("BenchmarkDotNet.Diagnostics.dotTrace")]
2324
[assembly: InternalsVisibleTo("BenchmarkDotNet.IntegrationTests.ManualRunning")]
25+
[assembly: InternalsVisibleTo("BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks")]
2426
#endif

src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using BenchmarkDotNet.Environments;
33
using BenchmarkDotNet.Extensions;
4+
using BenchmarkDotNet.Helpers;
45
using BenchmarkDotNet.Jobs;
56
using BenchmarkDotNet.Portability;
67
using BenchmarkDotNet.Running;
@@ -34,12 +35,19 @@ internal static IToolchain GetToolchain(this Runtime runtime, Descriptor descrip
3435
switch (runtime)
3536
{
3637
case ClrRuntime clrRuntime:
37-
if (RuntimeInformation.IsNetCore || preferMsBuildToolchains)
38-
return clrRuntime.RuntimeMoniker != RuntimeMoniker.NotRecognized
39-
? GetToolchain(clrRuntime.RuntimeMoniker)
40-
: CsProjClassicNetToolchain.From(clrRuntime.MsBuildMoniker);
41-
42-
return RoslynToolchain.Instance;
38+
if (!preferMsBuildToolchains && RuntimeInformation.IsFullFramework &&
39+
// If dotnet SDK is not installed, we use RoslynToolchain.
40+
(!HostEnvironmentInfo.GetCurrent().IsDotNetCliInstalled()
41+
// Integration tests take too much time, because each benchmark run rebuilds the test suite and BenchmarkDotNet itself.
42+
// To reduce the total duration of the CI workflows, we just use RoslynToolchain.
43+
|| XUnitHelper.IsIntegrationTest.Value))
44+
{
45+
return RoslynToolchain.Instance;
46+
}
47+
48+
return clrRuntime.RuntimeMoniker != RuntimeMoniker.NotRecognized
49+
? GetToolchain(clrRuntime.RuntimeMoniker)
50+
: CsProjClassicNetToolchain.From(clrRuntime.MsBuildMoniker);
4351

4452
case MonoRuntime mono:
4553
if (RuntimeInformation.IsAndroid())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="..\..\build\common.props" />
3+
<PropertyGroup>
4+
<AssemblyTitle>BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks</AssemblyTitle>
5+
<!-- We test the oldest frameworks supported by BDN (net461 and netcoreapp2.0), as well as newer versions of those frameworks. -->
6+
<TargetFrameworks>net461;net48;netcoreapp2.0;net7.0</TargetFrameworks>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
<AssemblyName>BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks</AssemblyName>
9+
<PackageId>BenchmarkDotNet.IntegrationTests.ManualRunning.MultipleFrameworks</PackageId>
10+
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
11+
<GenerateDocumentationFile>false</GenerateDocumentationFile>
12+
<PlatformTarget>AnyCPU</PlatformTarget>
13+
<DebugSymbols>true</DebugSymbols>
14+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
15+
</PropertyGroup>
16+
<ItemGroup>
17+
<Compile Include="..\BenchmarkDotNet.IntegrationTests\BenchmarkTestExecutor.cs" Link="BenchmarkTestExecutor.cs" />
18+
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\MisconfiguredEnvironmentException.cs" Link="MisconfiguredEnvironmentException.cs" />
19+
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\Extensions.cs" Link="Extensions.cs" />
20+
<Compile Include="..\BenchmarkDotNet.IntegrationTests\TestConfigs.cs" Link="TestConfigs.cs" />
21+
<Compile Include="..\BenchmarkDotNet.Tests\Loggers\OutputLogger.cs" Link="OutputLogger.cs" />
22+
<Compile Include="..\BenchmarkDotNet.Tests\XUnit\SmartAssert.cs" Link="SmartAssert.cs" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.0" />
26+
<PackageReference Include="System.Memory" Version="4.5.5" />
27+
</ItemGroup>
28+
<ItemGroup>
29+
<Content Include="..\BenchmarkDotNet.IntegrationTests.ManualRunning\xunit.runner.json">
30+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
31+
</Content>
32+
</ItemGroup>
33+
<ItemGroup>
34+
<ProjectReference Include="..\..\src\BenchmarkDotNet.Annotations\BenchmarkDotNet.Annotations.csproj" />
35+
<ProjectReference Include="..\..\src\BenchmarkDotNet\BenchmarkDotNet.csproj" />
36+
</ItemGroup>
37+
<ItemGroup>
38+
<!-- Microsoft.NET.Test.Sdk breaks netcoreapp2.0 -->
39+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.3" Condition=" '$(TargetFramework)' != 'netcoreapp2.0' " />
40+
<PackageReference Include="xunit" Version="2.5.0" />
41+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
42+
<PrivateAssets>all</PrivateAssets>
43+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
44+
</PackageReference>
45+
</ItemGroup>
46+
</Project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using BenchmarkDotNet.Attributes;
3+
using BenchmarkDotNet.Configs;
4+
using BenchmarkDotNet.Extensions;
5+
using BenchmarkDotNet.Jobs;
6+
using Xunit;
7+
8+
namespace BenchmarkDotNet.IntegrationTests
9+
{
10+
public class MultipleFrameworksTest : BenchmarkTestExecutor
11+
{
12+
private const string TfmEnvVarName = "TfmEnvVarName";
13+
14+
[Theory]
15+
[InlineData(RuntimeMoniker.Net461)]
16+
[InlineData(RuntimeMoniker.Net48)]
17+
[InlineData(RuntimeMoniker.NetCoreApp20)]
18+
[InlineData(RuntimeMoniker.Net70)]
19+
public void EachFrameworkIsRebuilt(RuntimeMoniker runtime)
20+
{
21+
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(runtime.GetRuntime()).WithEnvironmentVariable(TfmEnvVarName, runtime.ToString()));
22+
CanExecute<ValuePerTfm>(config);
23+
}
24+
25+
public class ValuePerTfm
26+
{
27+
private const RuntimeMoniker moniker =
28+
#if NET461
29+
RuntimeMoniker.Net461;
30+
#elif NET48
31+
RuntimeMoniker.Net48;
32+
#elif NETCOREAPP2_0
33+
RuntimeMoniker.NetCoreApp20;
34+
#elif NET7_0
35+
RuntimeMoniker.Net70;
36+
#else
37+
RuntimeMoniker.NotRecognized;
38+
#endif
39+
40+
[Benchmark]
41+
public void ThrowWhenWrong()
42+
{
43+
if (Environment.GetEnvironmentVariable(TfmEnvVarName) != moniker.ToString())
44+
{
45+
throw new InvalidOperationException($"Has not been recompiled, the value was {Environment.GetEnvironmentVariable(TfmEnvVarName)}");
46+
}
47+
}
48+
}
49+
}
50+
}

tests/BenchmarkDotNet.IntegrationTests.ManualRunning/BenchmarkDotNet.IntegrationTests.ManualRunning.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\MisconfiguredEnvironmentException.cs" Link="MisconfiguredEnvironmentException.cs" />
1717
<Compile Include="..\BenchmarkDotNet.IntegrationTests\Xunit\Extensions.cs" Link="Extensions.cs" />
1818
<Compile Include="..\BenchmarkDotNet.IntegrationTests\TestConfigs.cs" Link="TestConfigs.cs" />
19+
<Compile Include="..\BenchmarkDotNet.Tests\Loggers\OutputLogger.cs" Link="OutputLogger.cs" />
20+
<Compile Include="..\BenchmarkDotNet.Tests\XUnit\*.cs" />
1921
</ItemGroup>
2022
<ItemGroup>
2123
<Content Include="xunit.runner.json">
@@ -25,7 +27,6 @@
2527
<ItemGroup>
2628
<ProjectReference Include="..\..\src\BenchmarkDotNet\BenchmarkDotNet.csproj" />
2729
<ProjectReference Include="..\..\src\BenchmarkDotNet.Diagnostics.Windows\BenchmarkDotNet.Diagnostics.Windows.csproj" />
28-
<ProjectReference Include="..\BenchmarkDotNet.Tests\BenchmarkDotNet.Tests.csproj" />
2930
</ItemGroup>
3031
<ItemGroup>
3132
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.2" />

0 commit comments

Comments
 (0)