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
4 changes: 2 additions & 2 deletions build/scripts/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ module Build =
/// When running on Windows and not CI, also runs MSBuild Build on .NET Framework
let Build () =
// On Windows, pre-build this first to prevent a parallel build race condition: both
// Elastic.Apm.Profiler.Managed (net462 TFM) and AspNetFullFrameworkSampleApp reference
// Elastic.Apm.Profiler.Managed (net462 and net472 TFMs) and AspNetFullFrameworkSampleApp reference
// Elastic.Apm.AspNetFullFramework, so a parallel solution build can hit a file lock
// on the obj DLL. Pre-building ensures the output exists and incremental build skips it.
if isWindows then dotnet "build" aspNetFullFramework
Expand Down Expand Up @@ -320,7 +320,7 @@ module Build =
)

Directory.GetDirectories((Paths.BuildOutput "Elastic.Apm.Profiler.Managed"), "*", SearchOption.TopDirectoryOnly)
|> Array.filter (fun dir -> isWindows || not (dir.EndsWith("net462")))
|> Array.filter (fun dir -> isWindows || (not (dir.EndsWith("net462")) && not (dir.EndsWith("net472"))))
|> Seq.map DirectoryInfo
|> Seq.iter (fun sourceDir -> copyDllsAndPdbs (profilerDir.CreateSubdirectory(sourceDir.Name)) sourceDir)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,54 @@
using System;
using System.IO;
using System.Reflection;
using Microsoft.Win32;

namespace Elastic.Apm.Profiler.Managed.Loader
{
public partial class Startup
{
private static string ResolveDirectory()
{
var framework = "net462";
var directory = ReadEnvironmentVariable("ELASTIC_APM_PROFILER_HOME") ?? string.Empty;
return Path.Combine(directory, framework);

// Prefer the net472 build on .NET Framework 4.7.2+ — it supports VerifyServerCert and ServerCert
// via HttpClientHandler.ServerCertificateCustomValidationCallback (added in 4.7.1).
// Fall back to net462 if the net472 directory is absent (e.g. older profiler zip) so loading
// still succeeds rather than silently failing to resolve assemblies.
if (IsNet472OrHigher())
{
var net472Dir = Path.Combine(directory, "net472");
if (System.IO.Directory.Exists(net472Dir))
{
Logger.Log(LogLevel.Debug, "Resolving assemblies from {0}", net472Dir);
return net472Dir;
}

Logger.Log(LogLevel.Warning,
"Running on .NET Framework 4.7.2+ but net472 directory not found at {0}. "
+ "Falling back to net462: VerifyServerCert and ServerCert will have no effect.",
net472Dir);
}

var net462Dir = Path.Combine(directory, "net462");
Logger.Log(LogLevel.Debug, "Resolving assemblies from {0}", net462Dir);
return net462Dir;
}

private static bool IsNet472OrHigher()
{
try
{
using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full");
// Release value 461808 corresponds to .NET Framework 4.7.2 on Windows 10 1803+;
// 461814 is the value for all other OS versions. Checking >= 461808 covers both.
var release = Convert.ToInt32(key?.GetValue("Release") ?? 0);
return release >= 461808;
}
catch
{
return false;
}
}

private static Assembly ResolveDependencies(object sender, ResolveEventArgs args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<TargetFrameworks>net462;net472;netstandard2.0;netstandard2.1;net8.0</TargetFrameworks>
<IsPackable>false</IsPackable>
<DefineConstants>$(DefineConstants);PROFILER_MANAGED</DefineConstants>
</PropertyGroup>
Expand All @@ -12,26 +12,24 @@
<Compile Include="$(SolutionRoot)src/profiler/Elastic.Apm.Profiler.Managed.Loader/Logger.cs" />
</ItemGroup>


<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<ItemGroup Condition="'$(TargetFramework)' != 'net462' And '$(TargetFramework)' != 'net472'">
<PackageReference Include="System.Reflection.Emit" />
<PackageReference Include="System.Reflection.Emit.Lightweight" />
</ItemGroup>

<!-- ASP.NET integration -->
<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<!-- ASP.NET Full Framework integration (net462, net472) -->
<ItemGroup Condition="'$(TargetFramework)' == 'net462' Or '$(TargetFramework)' == 'net472'">
<ProjectReference Include="$(SrcIntegrations)\Elastic.Apm.AspNetFullFramework\Elastic.Apm.AspNetFullFramework.csproj" />
<Reference Include="System.Web" />
</ItemGroup>
<!-- ASP.NET Core integration -->
<ItemGroup Condition="'$(TargetFramework)' != 'net462'">
<!-- ASP.NET Core integration (netstandard, net8+) -->
<ItemGroup Condition="'$(TargetFramework)' != 'net462' And '$(TargetFramework)' != 'net472'">
<ProjectReference Include="$(SrcIntegrations)\Elastic.Apm.AspNetCore\Elastic.Apm.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Elastic.Apm.Profiler.Managed.Core\Elastic.Apm.Profiler.Managed.Core.csproj" />
<ProjectReference Include="..\..\Elastic.Apm\Elastic.Apm.csproj" />
<ProjectReference Include="$(SrcIntegrations)\Elastic.Apm.AspNetCore\Elastic.Apm.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading