Test against .NET 5.0 (#229)

* Finalize net 5.0 support

* leave net50 only for tests

* fix frameworks by feedback

* remove netstandard2.0 references

* Make dependency samples cross-platform
This commit is contained in:
Rasmus Kuusmann 2021-10-11 20:48:02 +03:00 committed by GitHub
parent f50ec99a07
commit 1cb8c5eded
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 53 additions and 61 deletions

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Extensions;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
@ -38,13 +39,17 @@ partial class Build
? new[] { MSBuildTargetPlatform.x64, MSBuildTargetPlatform.x86 }
: new[] { MSBuildTargetPlatform.x86 };
readonly IEnumerable<TargetFramework> TargetFrameworks = new[]
private static readonly IEnumerable<TargetFramework> TargetFrameworks = new[]
{
TargetFramework.NET461,
TargetFramework.NETSTANDARD2_0,
TargetFramework.NETCOREAPP3_1,
TargetFramework.NETCOREAPP3_1
};
private static readonly IEnumerable<TargetFramework> TestFrameworks = TargetFrameworks
.Concat(new[] {
TargetFramework.NET5_0
});
Target CreateRequiredDirectories => _ => _
.Unlisted()
.Executes(() =>
@ -221,8 +226,8 @@ partial class Build
{
// publish ClrProfilerManaged moc
var targetFrameworks = IsWin
? new[] { TargetFramework.NET461, TargetFramework.NETCOREAPP3_1 }
: new[] { TargetFramework.NETCOREAPP3_1 };
? TargetFrameworks
: TargetFrameworks.ExceptNetFramework();
DotNetPublish(s => s
.SetProject(Solution.GetProject(Projects.Mocks.ClrProfilerManagedMock))
@ -232,7 +237,7 @@ partial class Build
.EnableNoRestore()
.CombineWith(targetFrameworks, (p, framework) => p
.SetFramework(framework)
.SetOutput(TestsDirectory / Projects.Tests.ClrProfilerManagedLoaderTests / "bin" / BuildConfiguration / framework / "Profiler" / framework)));
.SetOutput(TestsDirectory / Projects.Tests.ClrProfilerManagedLoaderTests / "bin" / BuildConfiguration / "Profiler" / framework)));
});
Target CompileMocks => _ => _
@ -306,10 +311,11 @@ partial class Build
DotNetTest(config => config
.SetConfiguration(BuildConfiguration)
.SetTargetPlatform(Platform)
// TODO: Remove if NetFX works
.SetFramework(TargetFramework.NETCOREAPP3_1)
.EnableNoRestore()
.EnableNoBuild()
.CombineWith(TestFrameworks.ExceptNetFramework(), (s, fx) => s
.SetFramework(fx)
)
.CombineWith(integrationTests, (s, project) => s
.EnableTrxLogOutput(GetResultsDirectory(project))
.SetProjectFile(project)), degreeOfParallelism: 4);

View File

@ -0,0 +1,13 @@
using System.Collections.Generic;
using System.Linq;
namespace Extensions
{
public static class TargetFrameworksExtensions
{
public static IEnumerable<TargetFramework> ExceptNetFramework(this IEnumerable<TargetFramework> frameworks)
{
return frameworks.Except(TargetFramework.NetFramework);
}
}
}

View File

@ -9,11 +9,14 @@ using Nuke.Common.Tooling;
[TypeConverter(typeof(TargetFrameworkTypeConverter))]
public class TargetFramework : Enumeration
{
public static TargetFramework NET461 = new TargetFramework { Value = "net461" };
public static TargetFramework NETSTANDARD2_0 = new TargetFramework { Value = "netstandard2.0" };
public static TargetFramework NETCOREAPP2_1 = new TargetFramework { Value = "netcoreapp2.1" };
public static TargetFramework NETCOREAPP3_1 = new TargetFramework { Value = "netcoreapp3.1" };
public static TargetFramework NET5_0 = new TargetFramework { Value = "net5.0" };
public static readonly TargetFramework NET461 = new TargetFramework { Value = "net461" };
public static readonly TargetFramework NETCOREAPP3_1 = new TargetFramework { Value = "netcoreapp3.1" };
public static readonly TargetFramework NET5_0 = new TargetFramework { Value = "net5.0" };
public static readonly TargetFramework[] NetFramework = new[]
{
NET461
};
public static implicit operator string(TargetFramework framework)
{

View File

@ -15,7 +15,7 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc7" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc7" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet" Version="1.0.0-rc7" Condition="'$(TargetFramework)' == 'net461'" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc7" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc7" Condition="'$(TargetFramework)' != 'net461'" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.2.0-alpha1" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.1.0" />
<PackageReference Include="OpenTelemetry.Shims.OpenTracing" Version="1.0.0-rc7" />

View File

@ -2,7 +2,8 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- NuGet packages -->

View File

@ -14,17 +14,9 @@ namespace OpenTelemetry.ClrProfiler.Managed.Loader
private static string ResolveManagedProfilerDirectory()
{
string tracerFrameworkDirectory = "netstandard2.0";
string tracerFrameworkDirectory = "netcoreapp3.1";
string tracerHomeDirectory = ReadEnvironmentVariable("OTEL_DOTNET_TRACER_HOME") ?? string.Empty;
var version = Environment.Version;
// Old versions of .net core have a major version of 4
if ((version.Major == 3 && version.Minor >= 1) || version.Major >= 5)
{
tracerFrameworkDirectory = "netcoreapp3.1";
}
var tracerHomeDirectory = ReadEnvironmentVariable("OTEL_DOTNET_TRACER_HOME") ?? string.Empty;
return Path.Combine(tracerHomeDirectory, tracerFrameworkDirectory);
}

View File

@ -84,7 +84,7 @@ namespace OpenTelemetry.ClrProfiler.Managed
{
// try to get product version from assembly path
Match match = Regex.Match(
RootAssembly.CodeBase,
RootAssembly.Location,
@"/[^/]*microsoft\.netcore\.app/(\d+\.\d+\.\d+[^/]*)/",
RegexOptions.IgnoreCase);

View File

@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netcoreapp3.1</TargetFrameworks>
<Version>0.0.1</Version>
</PropertyGroup>
@ -12,21 +11,15 @@
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.0.0-rc7" />
<PackageReference Include="OpenTelemetry.Instrumentation.SqlClient" Version="1.0.0-rc7" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNet" Version="1.0.0-rc7" Condition="'$(TargetFramework)' == 'net461'" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc7" Condition="'$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.0.0-rc7" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
<PackageReference Include="OpenTelemetry.Exporter.Jaeger" Version="1.2.0-alpha2" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.2.0-alpha2" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.2.0-alpha2" />
<PackageReference Include="OpenTelemetry.Shims.OpenTracing" Version="1.0.0-rc7" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="6.0.0-preview.7.21377.19" />
</ItemGroup>
<!--DuckTyping-->
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
<PackageReference Include="System.Reflection.Emit.Lightweight" Version="4.7.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'netstandard2.0' AND '$(TargetFramework)' != 'netcoreapp3.1' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.Configuration" />
<Reference Include="System.Web" />
</ItemGroup>

View File

@ -3,8 +3,8 @@
<PropertyGroup>
<!-- only run .NET Framework tests on Windows -->
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1;net5.0</TargetFrameworks>
<!-- Hide warnings for EOL .NET Core targets (e.g. netcoreapp3.0) -->
<CheckEolTargetFramework>false</CheckEolTargetFramework>

View File

@ -1,12 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />

View File

@ -1,12 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1</TargetFrameworks>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />

View File

@ -11,17 +11,17 @@ namespace OpenTelemetry.ClrProfiler.Managed.Loader.Tests
public void Ctor_LoadsManagedAssembly()
{
var directory = Directory.GetCurrentDirectory();
Environment.SetEnvironmentVariable("OTEL_DOTNET_TRACER_HOME", $"{directory}/Profiler");
Console.WriteLine("Setting directory >> " + $"{directory}/Profiler");
Environment.SetEnvironmentVariable("OTEL_DOTNET_TRACER_HOME", Path.Combine(directory, "..", "Profiler"));
var exception = Record.Exception(() => Startup.ManagedProfilerDirectory);
// That means the assembly was loaded successfully and Initialize method was called.
Assert.Null(exception);
var clrProfilerManagedAssembly = AppDomain.CurrentDomain.GetAssemblies()
.Select(a => a.FullName)
.FirstOrDefault(n => n.StartsWith("OpenTelemetry.ClrProfiler.Managed,"));
Assert.NotNull(clrProfilerManagedAssembly);
}
}

View File

@ -50,7 +50,7 @@ TEST_F(CLRHelperTest, EnumeratesTypeDefs) {
}
TEST_F(CLRHelperTest, EnumeratesAssemblyRefs) {
std::vector<std::wstring> expected_assemblies = {L"netstandard"};
std::vector<std::wstring> expected_assemblies = {L"mscorlib"};
std::vector<std::wstring> actual_assemblies;
for (auto& ref : EnumAssemblyRefs(assembly_import_)) {
auto name = GetReferencedAssemblyMetadata(assembly_import_, ref).name;
@ -123,7 +123,7 @@ TEST_F(CLRHelperTest, FiltersIntegrationsByTarget) {
IntegrationMethod i3 = {
L"integration-3",
{{}, {L"netstandard", L"", L"", L"ReplaceTargetMethod", min_ver_, max_ver_, {}, empty_sig_type_}, {}}};
{{}, {L"mscorlib", L"", L"", L"ReplaceTargetMethod", min_ver_, max_ver_, {}, empty_sig_type_}, {}}};
std::vector<IntegrationMethod> all = {i1, i2, i3};
std::vector<IntegrationMethod> expected = {i1, i3};

View File

@ -1,8 +1,8 @@
<Project>
<PropertyGroup>
<!-- only run .NET Framework tests on Windows -->
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1;</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' == 'Windows_NT'">net461;netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp3.1;net5.0</TargetFrameworks>
<OutputType>Exe</OutputType>
<Platforms>x64;x86</Platforms>

View File

@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />

View File

@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />