Skip to content

Commit

Permalink
Remove a few #if that are no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer committed Jun 28, 2023
1 parent 318ad85 commit d64e003
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 58 deletions.
17 changes: 16 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,22 @@
</ItemGroup>
</Target>

<!-- R9 common properties -->
<!-- Test configuration -->
<PropertyGroup>
<!-- Disable building Integration Test projects in LUT. -->
<BuildForLiveUnitTesting Condition="'$(BuildForLiveUnitTesting)' == '' and '$(IsIntegrationTestProject)' == 'true'">false</BuildForLiveUnitTesting>

<!-- Redirect test logs into a subfolder -->
<TestResultsLogDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsLogDir)', 'TestLogs'))</TestResultsLogDir>

<!--
Run tests with the VS Test Runner (dotnet test) instead of the XUnit Test runner (dotnet exec).
This is needed to produce Cobertura code coverage. See the targets file to more information.
-->
<UseVSTestRunner>true</UseVSTestRunner>
</PropertyGroup>

<!-- Common properties -->
<Import Project="$(MSBuildThisFileDirectory)\eng\MSBuild\Analyzers.props" />
<Import Project="$(MSBuildThisFileDirectory)\eng\MSBuild\Packaging.props" />
<Import Project="$(MSBuildThisFileDirectory)\eng\MSBuild\LegacySupport.props" />
Expand Down
22 changes: 4 additions & 18 deletions eng/Packages/TestOnly.props
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- Disable building Integration Test projects in LUT. -->
<BuildForLiveUnitTesting Condition="'$(BuildForLiveUnitTesting)' == '' and '$(IsIntegrationTestProject)' == 'true'">false</BuildForLiveUnitTesting>

<!-- Redirect test logs into a subfolder -->
<TestResultsLogDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsLogDir)', 'TestLogs'))</TestResultsLogDir>

<!--
Run tests with the VS Test Runner (dotnet test) instead of the XUnit Test runner (dotnet exec).
This is needed to produce Cobertura code coverage. See the targets file to more information.
-->
<UseVSTestRunner>true</UseVSTestRunner>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="AutoFixture.AutoMoq" Version="4.17.0" />
<PackageVersion Include="autofixture" Version="4.17.0" />
Expand All @@ -35,13 +21,13 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.22" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="3.1.22" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.32" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="3.1.32" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.19" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.19" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public static IStandardHedgingHandlerBuilder Configure(this IStandardHedgingHand
_ = builder.Services.Configure<HttpStandardHedgingResilienceOptions>(
builder.Name,
section,
#if NET6_0_OR_GREATER
o => o.ErrorOnUnknownConfiguration = true);
#else
_ => { });
#endif

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ public static IHttpStandardResilienceStrategyBuilder Configure(this IHttpStandar
_ = builder.Services.Configure<HttpStandardResilienceOptions>(
builder.StrategyName,
section,
#if NET6_0_OR_GREATER
o => o.ErrorOnUnknownConfiguration = true);
#else
_ => { });
#endif

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ namespace Microsoft.Extensions.Options.Contextual;
/// </summary>
/// <typeparam name="TOptions">The type of options being requested.</typeparam>
internal sealed class ContextualOptionsFactory<TOptions> : IContextualOptionsFactory<TOptions>
#if NET5_0_OR_GREATER
where TOptions : class
#else
where TOptions : class, new()
#endif
{
private readonly IOptionsFactory<TOptions> _baseFactory;
private readonly ILoadContextualOptions<TOptions>[] _loaders;
Expand Down Expand Up @@ -124,11 +120,7 @@ async ValueTask<TOptions> ConfigureOptions(TContext context)
if (result.Failed)
{
failures ??= new();
#if NETFRAMEWORK || NETSTANDARD2_0
failures.Add(result.FailureMessage);
#else
failures.AddRange(result.Failures);
#endif
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
#if NET6_0_OR_GREATER
using Microsoft.Extensions.Logging;
#endif
using Microsoft.Extensions.ObjectPool;
using Microsoft.Extensions.Telemetry.Enrichment;
using Microsoft.Shared.Diagnostics;
Expand Down Expand Up @@ -202,10 +200,8 @@ void IEnrichmentPropertyBag.Add(ReadOnlySpan<KeyValuePair<string, string>> prope
}
}

#if NET6_0_OR_GREATER
/// <summary>
/// Gets log define options configured to skip the log level enablement check.
/// </summary>
public static LogDefineOptions SkipEnabledCheckOptions { get; } = new() { SkipEnabledCheck = true };
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,11 @@ public Task WaitForMeasurementsAsync(int minCount, CancellationToken cancellatio
{
lock (_measurements)
{
_waiters.Remove(w);
_ = _waiters.Remove(w);
}
// trigger the task from outside the lock
#if NET6_0_OR_GREATER
w.TaskSource.TrySetCanceled(cancellationToken);
#else
w.TaskSource.TrySetCanceled();
#endif
_ = w.TaskSource.TrySetCanceled(cancellationToken);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ public async Task TestEmitter()
var sources = new List<string>();
foreach (var file in Directory.GetFiles("TestClasses"))
{
#if NETCOREAPP3_1_OR_GREATER
sources.Add("#define NETCOREAPP3_1_OR_GREATER\n" + File.ReadAllText(file));
#else
sources.Add(File.ReadAllText(file));
#endif
}

// try it without the frozen collections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,7 @@ public void SkipEnabledCheckTests()
SkipEnabledCheckTestExtensions.LoggerMethodWithFalseSkipEnabledCheck(logger, LogLevel.Information, "p1");
Assert.Equal(0, logger.Collector.Count);

#if NET8_0_OR_GREATER
// Whilst these API are marked as NET6_0_OR_GREATER we don't build .NET 6.0,
// and as such the API is available in .NET 8 onwards.
#if NET6_0_OR_GREATER
SkipEnabledCheckTestExtensions.LoggerMethodWithTrueSkipEnabledCheck(logger);
Assert.Equal(1, logger.Collector.Count);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,7 @@ public void AddStandardResilienceHandler_ConfigurationPropertyWithTypo_Throws(Me

AddStandardResilienceHandler(mode, builder, _invalidConfigurationSection, options => { });

#if NET8_0_OR_GREATER
// Whilst these API are marked as NET6_0_OR_GREATER we don't build .NET 6.0,
// and as such the API is available in .NET 8 onwards.
Assert.Throws<InvalidOperationException>(() => HttpClientBuilderExtensionsTests.GetStrategy(builder.Services, $"test-standard"));
#else
GetStrategy(builder.Services, $"test-standard").Should().NotBeNull();
#endif
}

[Fact]
Expand Down

0 comments on commit d64e003

Please sign in to comment.