Skip to content

Commit

Permalink
chore: Update agent projects to support and test .NET 8. (#2079)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaffinito authored Dec 4, 2023
1 parent a04873f commit b20ea3b
Show file tree
Hide file tree
Showing 60 changed files with 299 additions and 131 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ jobs:
with:
fetch-depth: 0

- name: Setup .NET Core
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
dotnet-version: 7.x
dotnet-quality: 'ga'

- name: Restore NuGet Packages
run: dotnet restore

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..'))" />
<PropertyGroup>
<NuGetAudit>false</NuGetAudit>
</PropertyGroup>
</Project>
8 changes: 7 additions & 1 deletion src/NewRelic.Core/DotnetVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum DotnetCoreVersion
net5,
net6,
net7,
net8,
Other
}

Expand Down Expand Up @@ -101,6 +102,11 @@ public static DotnetCoreVersion GetDotnetCoreVersion()
return DotnetCoreVersion.netcoreapp31;
}

if (envVer.Major == 8)
{
return DotnetCoreVersion.net8;
}

if (envVer.Major == 7)
{
return DotnetCoreVersion.net7;
Expand Down Expand Up @@ -130,7 +136,7 @@ public static bool IsUnsupportedDotnetCoreVersion(DotnetCoreVersion version)
// Newer versions of .net will be flagged as Other until we update our version checking logic.
// So we can either check against a supported list, or an unsupported list, but the supported list
// is smaller.
var supportedDotnetCoreVersions = new List<DotnetCoreVersion> { DotnetCoreVersion.net6, DotnetCoreVersion.net7, DotnetCoreVersion.Other };
var supportedDotnetCoreVersions = new List<DotnetCoreVersion> { DotnetCoreVersion.net6, DotnetCoreVersion.net7, DotnetCoreVersion.net8, DotnetCoreVersion.Other };
return !supportedDotnetCoreVersions.Contains(version);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ await context.Response.WriteAsync(JsonSerializer.Serialize(subscriptions,

AppLifecycleManager.WaitForTestCompletion(_port);

ct.Cancel();
await ct.CancelAsync();

await task;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
Expand All @@ -12,7 +12,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.1" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using ApplicationLifecycle;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.CodeAnalysis;

namespace SerilogSumologicApplication
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.8.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ public NewRelicConfigModifier EnableAspNetCore6PlusBrowserInjection(bool enableB
return this;
}

public NewRelicConfigModifier DisableEventListenerSamplers()
{
CommonUtils.SetConfigAppSetting(_configFilePath, "NewRelic.EventListenerSamplersEnabled", "false", "urn:newrelic-config");
return this;
}

public void EnableAuditLog(bool enableAuditLog)
{
CommonUtils.ModifyOrCreateXmlAttributeInNewRelicConfig(_configFilePath, new[] { "configuration", "log" }, "auditLog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public ConsoleDynamicMethodFixtureCore70() : base("net7.0")
}
}

public class ConsoleDynamicMethodFixtureCore80 : ConsoleDynamicMethodFixtureCoreSpecificVersion
{
public ConsoleDynamicMethodFixtureCore80() : base("net8.0")
{
}
}

/// <summary>
/// Use this fixture to test against the oldest supported .NET version.
/// If you need to test against a feature that belongs to a specific .net core version, then consider
Expand All @@ -108,39 +115,13 @@ public ConsoleDynamicMethodFixtureCoreOldest()
}
}

/// <summary>
/// Use this fixture for High Security Mode tests
/// </summary>
public class ConsoleDynamicMethodFixtureCoreOldestHSM : ConsoleDynamicMethodFixtureCore60
{
public override string TestSettingCategory { get { return "HSM"; } }
public ConsoleDynamicMethodFixtureCoreOldestHSM()
{
}

}

/// <summary>
/// Use this fixture for Configurable Security Policy tests
/// </summary>
public class ConsoleDynamicMethodFixtureCoreOldestCSP : ConsoleDynamicMethodFixtureCore60
{
public override string TestSettingCategory { get { return "CSP"; } }
public ConsoleDynamicMethodFixtureCoreOldestCSP()
{
}

}



/// <summary>
/// Use this fixture if you don't care about which .net core version the test application should use.
/// If you need to test against a feature that belongs to a specific .net core version, then consider
/// using one of the existing specific version fixtures, or create a new specific version.
/// When testing newer .net core preview releases, this targetFramework version should be updated.
/// </summary>
public class ConsoleDynamicMethodFixtureCoreLatest : ConsoleDynamicMethodFixtureCore70
public class ConsoleDynamicMethodFixtureCoreLatest : ConsoleDynamicMethodFixtureCore80
{
public ConsoleDynamicMethodFixtureCoreLatest()
{
Expand All @@ -150,7 +131,7 @@ public ConsoleDynamicMethodFixtureCoreLatest()
/// <summary>
/// Use this fixture for High Security Mode tests
/// </summary>
public class ConsoleDynamicMethodFixtureCoreLatestHSM : ConsoleDynamicMethodFixtureCore70
public class ConsoleDynamicMethodFixtureCoreLatestHSM : ConsoleDynamicMethodFixtureCore80
{
public override string TestSettingCategory { get { return "HSM"; } }
public ConsoleDynamicMethodFixtureCoreLatestHSM()
Expand All @@ -162,7 +143,7 @@ public ConsoleDynamicMethodFixtureCoreLatestHSM()
/// <summary>
/// Use this fixture for Configurable Security Policy tests
/// </summary>
public class ConsoleDynamicMethodFixtureCoreLatestCSP : ConsoleDynamicMethodFixtureCore70
public class ConsoleDynamicMethodFixtureCoreLatestCSP : ConsoleDynamicMethodFixtureCore80
{
public override string TestSettingCategory { get { return "CSP"; } }
public ConsoleDynamicMethodFixtureCoreLatestCSP()
Expand All @@ -180,7 +161,12 @@ public abstract class ConsoleDynamicMethodFixtureCoreSpecificVersion : ConsoleDy
/// Use this .ctor to specify a specific .net core version to target.
/// </summary>
/// <param name="targetFramework">The netcoreapp target use when publishing and running the application. This parameter must match one of the targetFramework values defined in ConsoleMultiFunctionApplicationCore.csproj </param>
public ConsoleDynamicMethodFixtureCoreSpecificVersion(string targetFramework) : base(ApplicationDirectoryName, ExecutableName, targetFramework, true, DefaultTimeout)
public ConsoleDynamicMethodFixtureCoreSpecificVersion(string targetFramework) :
base(ApplicationDirectoryName,
ExecutableName,
targetFramework,
true,
DefaultTimeout)
{
}
}
Expand Down Expand Up @@ -233,7 +219,14 @@ public ConsoleDynamicMethodFixture(string applicationDirectoryName, string execu

public override void ShutdownRemoteApplication()
{
RemoteApplication.WriteToStandardInput("exit");
try
{
RemoteApplication.WriteToStandardInput("exit");
}
catch (System.IO.IOException)
{
// Starting in .NET 8, writes to a closed pipe throw an IO exception. So we'll just eat it and continue.
}

base.ShutdownRemoteApplication();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public override void CopyToRemote()
{
if (IsCoreApp && _publishApp)
{
PublishWithDotnetExe(string.IsNullOrWhiteSpace(_targetFramework) ? "net7.0" : _targetFramework);
PublishWithDotnetExe(string.IsNullOrWhiteSpace(_targetFramework) ? "net8.0" : _targetFramework);
CopyNewRelicHomeCoreClrDirectoryToRemote();
}
else if (_publishApp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public InstrumentationLoaderTestsCore(RemoteServiceFixtures.ConsoleInstrumentati

configModifier.ForceTransactionTraces();
configModifier.SetLogLevel("finest");
configModifier.DisableEventListenerSamplers(); // Required for .NET 8 to pass.
},
exerciseApplication: () =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public CustomSpanNameApiTests(TFixture fixture, ITestOutputHelper output) : base
var configPath = fixture.DestinationNewRelicConfigFilePath;
var configModifier = new NewRelicConfigModifier(configPath);
configModifier.ForceTransactionTraces();
configModifier.DisableEventListenerSamplers(); // Required for .NET 8 to pass.
}
);

Expand Down
Loading

0 comments on commit b20ea3b

Please sign in to comment.