Skip to content

Commit

Permalink
Fixed hostfxr use. All tests passed
Browse files Browse the repository at this point in the history
changed:
- tfm: TestGeneralFrameworkMonikerGood()
- tfm: GetPathToReferenceAssembliesDefaultLocation45()
- Skip L-157: TestOldNuget
  • Loading branch information
3F committed Feb 21, 2024
1 parent 01bac9d commit c150a40
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Build.OM.UnitTests/NugetRestoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public NugetRestoreTests(ITestOutputHelper output)
// NuGet version 4.1.0 was somewhat arbitrarily chosen. 3.5 breaks with an unrelated error, and 4.8.2 does not fail when a new dependency is introduced. This is a safe middle point.
#if !DEBUG
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp)]
[Fact]
[Fact(Skip = "IeXod. L-157")]
public void TestOldNuget()
{
string IeXodPath = BuildEnvironmentHelper.Instance.IeXodBinPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void TransportDelegate(INodePacket packet)
/// <summary>
/// Make sure shutdown will correctly null out the send data delegate
/// </summary>
[Fact]
[Fact(Skip = "IeXod. L-157")]
[Trait("Category", "mono-osx-failing")]
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp, "https://github.com/Microsoft/msbuild/issues/282")]
public void TestShutDown()
Expand Down
4 changes: 2 additions & 2 deletions src/Build.UnitTests/Evaluation/Expander_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1818,7 +1818,7 @@ public void TestItemSpecModiferEscaping()
[Trait("Category", "mono-osx-failing")]
public void TestGetPathToReferenceAssembliesAsFunction()
{
if (ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version45) == null)
if (ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version48) == null)
{
// if there aren't any reference assemblies installed on the machine in the first place, of course
// we're not going to find them. :)
Expand All @@ -1830,7 +1830,7 @@ public void TestGetPathToReferenceAssembliesAsFunction()
<PropertyGroup>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<TargetFrameworkProfile></TargetFrameworkProfile>
<TargetFrameworkMoniker>$(TargetFrameworkIdentifier),Version=$(TargetFrameworkVersion)</TargetFrameworkMoniker>
</PropertyGroup>
Expand Down
11 changes: 10 additions & 1 deletion src/Build/IeXod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
<None Include="..\..\.tools\hMSBuild.bat" Pack="true" PackagePath="lib/$([System.String]::Join(';lib/', '$(IeXodTFM.Split(`;`))'))">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<!-- after ResolveHostfxrCopyLocalContent -->
<hostfxrX64lib Include="$(OutputPath)\*\x64\hostfxr.dll" />
<hostfxrX86lib Include="$(OutputPath)\*\x86\hostfxr.dll" />
<None Include="@(hostfxrX64lib)" Pack="true" PackagePath="lib/">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="@(hostfxrX86lib)" Pack="true" PackagePath="lib/">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -45,7 +54,7 @@
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="$(SystemThreadingTasksDataflowVersion)" />
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />

<PackageReference Include="Conari" Version="$(ConariVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" Condition="'$(MonoBuild)' == 'true'" />
</ItemGroup>

Expand Down
53 changes: 52 additions & 1 deletion src/DotNet.Sdk/IeXod.MSBSdkResolver/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,37 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using net.r_eg.Conari;
using net.r_eg.Conari.Types;
using static net.r_eg.Conari.Static.Members;
using static net.r_eg.IeXod.Shared.FileSystem.WindowsNative;

namespace net.r_eg.IeXod
{
internal static partial class Interop
{
internal static readonly bool RunningOnWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

// FIXME: original hostfxr preload does not work for netcoreapp targets. Instead we apply Conari using its runtime features;
// Fix or refactor legacy code to its nromal use

private static readonly dynamic l;

static Interop()
{
l = new ConariX(Path.Combine(Path.GetDirectoryName(typeof(Interop).Assembly.Location), Is64bit ? "x64" : "x86", "hostfxr"));

#if IEXOD_SDKRSLV_INTEROP_LEGACY

if (RunningOnWindows)
{
PreloadWindowsLibrary("hostfxr.dll");
}
#endif
}

#if IEXOD_SDKRSLV_INTEROP_LEGACY

// MSBuild SDK resolvers are required to be AnyCPU, but we have a native dependency and .NETFramework does not
// have a built-in facility for dynamically loading user native dlls for the appropriate platform. We therefore
// preload the version with the correct architecture (from a corresponding sub-folder relative to us) on static
Expand All @@ -42,6 +57,7 @@ private static void PreloadWindowsLibrary(string dllFileName)
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern IntPtr LoadLibraryExW(string lpFileName, IntPtr hFile, int dwFlags);

#endif

[Flags]
internal enum hostfxr_resolve_sdk2_flags_t : int
Expand All @@ -57,6 +73,39 @@ internal enum hostfxr_resolve_sdk2_result_key_t : int

internal static class Windows
{
internal delegate void hostfxr_resolve_sdk2_result_fn
(
hostfxr_resolve_sdk2_result_key_t key,
[MarshalAs(UnmanagedType.LPWStr)] string value
);

internal static int hostfxr_resolve_sdk2
(
string exe_dir, string working_dir, hostfxr_resolve_sdk2_flags_t flags, hostfxr_resolve_sdk2_result_fn result
)
{ // FIXME: Conari 1.5 supports automatic marshaling and normally we don't need new NativeString here at all;
// but only Xunit host + IeXod keeps strange behaviour until WCharPtr. Need to review. L-161
using NativeString<WCharPtr> nExeDir = new(exe_dir);
using NativeString<WCharPtr> nWDir = new(working_dir);

return l.hostfxr_resolve_sdk2<int>(nExeDir, nWDir, flags, new hostfxr_resolve_sdk2_result_fn(result));
}

internal static int hostfxr_get_available_sdks(string exe_dir, hostfxr_get_available_sdks_result_fn result)
{
using NativeString<WCharPtr> nExeDir = new(exe_dir); // FIXME: ^
return l.hostfxr_get_available_sdks<int>(nExeDir, new hostfxr_get_available_sdks_result_fn(result));
}

internal delegate void hostfxr_get_available_sdks_result_fn
(
int sdk_count,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 0)] string[] sdk_dirs
);


#if IEXOD_SDKRSLV_INTEROP_LEGACY

private const CharSet UTF16 = CharSet.Unicode;

[UnmanagedFunctionPointer(CallingConvention.Cdecl, CharSet = UTF16)]
Expand All @@ -81,6 +130,8 @@ internal delegate void hostfxr_get_available_sdks_result_fn(
internal static extern int hostfxr_get_available_sdks(
string exe_dir,
hostfxr_get_available_sdks_result_fn result);
#endif

}

internal static class Unix
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.Sdk/IeXod.MSBSdkResolver/build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RuntimeIdentifiers Condition="'$(OS)' == 'Windows_NT'">win-x86;win-x64</RuntimeIdentifiers>
<EmbdSdkResolverResxName>MSBSdkResolver</EmbdSdkResolverResxName>

<EmitLegacyAssetsFileItems>true</EmitLegacyAssetsFileItems> <!-- L-76. Required for `ResolveHostfxrCopyLocalContent` target below -->
<EmitLegacyAssetsFileItems>true</EmitLegacyAssetsFileItems> <!-- ResolveHostfxrCopyLocalContent target below /L-76 -->
</PropertyGroup>

<ItemGroup>
Expand All @@ -17,7 +17,7 @@
<Reference Include="System.Core" />
</ItemGroup>

<Target Name="ResolveHostfxrCopyLocalContent" Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'" DependsOnTargets="RunResolvePackageDependencies" BeforeTargets="AssignTargetPaths">
<Target Name="ResolveHostfxrCopyLocalContent" DependsOnTargets="RunResolvePackageDependencies" BeforeTargets="AssignTargetPaths">
<ItemGroup>
<Content Include="@(FileDefinitions->'%(ResolvedPath)')" Condition="'%(FileDefinitions.Path)' == 'runtimes/win-x86/native/hostfxr.dll'">
<Link>x86/hostfxr.dll</Link>
Expand Down
2 changes: 1 addition & 1 deletion src/Tasks.UnitTests/GetReferencePaths_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sealed public class GetReferenceAssmeblyPath_Tests
[Fact]
public void TestGeneralFrameworkMonikerGood()
{
string targetFrameworkMoniker = ".NetFramework, Version=v4.5";
string targetFrameworkMoniker = ".NetFramework, Version=v4.8";
MockEngine engine = new MockEngine();
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
getReferencePaths.BuildEngine = engine;
Expand Down
8 changes: 4 additions & 4 deletions src/Utilities.UnitTests/ToolLocationHelper_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,17 +1967,17 @@ public void GetPathToReferenceAssembliesDefaultLocationNullFrameworkName()
/// </summary>
[Fact]
[Trait("Category", "mono-osx-failing")]
public void GetPathToReferenceAssembliesDefaultLocation45()
public void GetPathToReferenceAssembliesDefaultLocation48()
{
FrameworkNameVersioning frameworkName = null;
IList<string> directories = null;
if (ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version45) != null)
if (ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version48) != null)
{
frameworkName = new FrameworkNameVersioning(".NETFramework", new Version("4.5"));
frameworkName = new FrameworkNameVersioning(".NETFramework", new Version("4.8"));
directories = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkName);
directories.Count.ShouldBe(1); // "Expected the method to return one path."

string referenceAssemblyPath = ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version45);
string referenceAssemblyPath = ToolLocationHelper.GetPathToDotNetFrameworkReferenceAssemblies(TargetDotNetFrameworkVersion.Version48);
directories[0].ShouldBe(referenceAssemblyPath, StringCompareShould.IgnoreCase);
}
// else
Expand Down
1 change: 1 addition & 0 deletions src/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)com.github.3F.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<DelaySign>false</DelaySign>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions src/versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<!-- Packages -->
<PropertyGroup>
<ConariVersion>1.5.0</ConariVersion>
<XliffTasksVersion>1.0.0-beta.19253.1</XliffTasksVersion> <!-- https://github.com/dotnet/xliff-tasks -->
<SystemCollectionsImmutableVersion>1.7.1</SystemCollectionsImmutableVersion>
<SystemThreadingTasksDataflowVersion>4.11.1</SystemThreadingTasksDataflowVersion>
Expand Down

0 comments on commit c150a40

Please sign in to comment.