Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Microsoft.NETCore.Platforms pack from CSProj #50468

Merged
merged 9 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
<RepositoryUrl>https://github.com/dotnet/$(GitHubRepositoryName)</RepositoryUrl>
<PackageProjectUrl>https://dot.net</PackageProjectUrl>
<Owners>microsoft,dotnetframework</Owners>
<RuntimeIdGraphDefinitionFile>$([MSBuild]::NormalizePath('$(LibrariesProjectRoot)', 'Microsoft.NETCore.Platforms', 'pkg', 'runtime.json'))</RuntimeIdGraphDefinitionFile>
<RuntimeIdGraphDefinitionFile>$([MSBuild]::NormalizePath('$(LibrariesProjectRoot)', 'Microsoft.NETCore.Platforms', 'src', 'runtime.json'))</RuntimeIdGraphDefinitionFile>
<LicenseFile>$(MSBuildThisFileDirectory)LICENSE.TXT</LicenseFile>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Copyright>$(CopyrightNetFoundation)</Copyright>
Expand Down
6 changes: 3 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,12 @@
These are used as reference assemblies only, so they must not take a ProdCon/source-build
version. Insert "RefOnly" to avoid assignment via PVP.
-->
<RefOnlyMicrosoftBuildVersion>15.7.179</RefOnlyMicrosoftBuildVersion>
<RefOnlyMicrosoftBuildVersion>16.8.0</RefOnlyMicrosoftBuildVersion>
<RefOnlyMicrosoftBuildFrameworkVersion>$(RefOnlyMicrosoftBuildVersion)</RefOnlyMicrosoftBuildFrameworkVersion>
<RefOnlyMicrosoftBuildTasksCoreVersion>$(RefOnlyMicrosoftBuildVersion)</RefOnlyMicrosoftBuildTasksCoreVersion>
<RefOnlyMicrosoftBuildUtilitiesCoreVersion>$(RefOnlyMicrosoftBuildVersion)</RefOnlyMicrosoftBuildUtilitiesCoreVersion>
<RefOnlyNugetProjectModelVersion>4.9.4</RefOnlyNugetProjectModelVersion>
<RefOnlyNugetPackagingVersion>4.9.4</RefOnlyNugetPackagingVersion>
<RefOnlyNugetProjectModelVersion>5.8.0</RefOnlyNugetProjectModelVersion>
<RefOnlyNugetPackagingVersion>5.8.0</RefOnlyNugetPackagingVersion>
<!-- Testing -->
<MicrosoftNETCoreCoreDisToolsVersion>1.0.1-prerelease-00006</MicrosoftNETCoreCoreDisToolsVersion>
<MicrosoftNETTestSdkVersion>16.9.0-preview-20201201-01</MicrosoftNETTestSdkVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<GeneratePlatformNotSupportedAssemblyHeaderFile>$(RepositoryEngineeringDir)LicenseHeader.txt</GeneratePlatformNotSupportedAssemblyHeaderFile>
</PropertyGroup>

<Import Sdk="Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk" Project="Sdk.props" />
<Import Sdk="Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk" Project="Sdk.props" Condition="'$(UseTargetFrameworkSDK)' != 'false'" />

<PropertyGroup>
<BuildTargetFramework Condition="'$(BuildTargetFramework)' == '' and '$(TargetFramework)' != ''">$([System.Text.RegularExpressions.Regex]::Replace('$(TargetFramework)', '(-[^;]+)', ''))</BuildTargetFramework>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<Import Project="$(RepositoryEngineeringDir)testing\coverage.targets" Condition="'$(EnableRunSettingsSupport)' == 'true' or '$(EnableCoverageSupport)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)slngen.targets" />

<Import Sdk="Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk" Project="Sdk.targets" />
<Import Sdk="Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk" Project="Sdk.targets" Condition="'$(UseTargetFrameworkSDK)' != 'false'" />
<Import Project="$(RepositoryEngineeringDir)restore\repoRestore.targets" Condition="'$(DisableProjectRestore)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)illink.targets" Condition="'$(IsSourceProject)' == 'true'" />
<Import Project="$(RepositoryEngineeringDir)AvoidRestoreCycleOnSelfReference.targets" Condition="'$(AvoidRestoreCycleOnSelfReference)' == 'true'" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31004.24
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NETCore.Platforms", "src\Microsoft.NETCore.Platforms.csproj", "{BFFF96CC-06AA-4291-9F93-3E77F23DBB11}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.NETCore.Platforms.Tests", "tests\Microsoft.NETCore.Platforms.Tests.csproj", "{0C60F372-5C73-4BFA-9B91-5659C88F9750}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BFFF96CC-06AA-4291-9F93-3E77F23DBB11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BFFF96CC-06AA-4291-9F93-3E77F23DBB11}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BFFF96CC-06AA-4291-9F93-3E77F23DBB11}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BFFF96CC-06AA-4291-9F93-3E77F23DBB11}.Release|Any CPU.Build.0 = Release|Any CPU
{0C60F372-5C73-4BFA-9B91-5659C88F9750}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0C60F372-5C73-4BFA-9B91-5659C88F9750}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C60F372-5C73-4BFA-9B91-5659C88F9750}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C60F372-5C73-4BFA-9B91-5659C88F9750}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E946A528-C3E7-48EC-AD6D-AE84ED2B11AC}
EndGlobalSection
EndGlobal

This file was deleted.

108 changes: 108 additions & 0 deletions src/libraries/Microsoft.NETCore.Platforms/src/AssemblyResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;

namespace Microsoft.NETCore.Platforms.BuildTasks
{
/// <summary>
/// Used to enable app-local assembly unification.
/// </summary>
internal static class AssemblyResolver
{
static AssemblyResolver()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
}

/// <summary>
/// Call to enable the assembly resolver for the current AppDomain.
/// </summary>
public static void Enable()
{
// intentionally empty. This is just meant to ensure the static constructor
// has run.
}

private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
// apply any existing policy
AssemblyName referenceName = new AssemblyName(AppDomain.CurrentDomain.ApplyPolicy(args.Name));

string fileName = referenceName.Name + ".dll";
string assemblyPath = null;
string probingPath = null;
Assembly assm = null;

// look next to requesting assembly
assemblyPath = args.RequestingAssembly?.Location;
if (!string.IsNullOrEmpty(assemblyPath))
{
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);
Debug.WriteLine($"Considering {probingPath} based on RequestingAssembly");
if (Probe(probingPath, referenceName.Version, out assm))
{
return assm;
}
}

// look next to the executing assembly
assemblyPath = Assembly.GetExecutingAssembly().Location;
if (!string.IsNullOrEmpty(assemblyPath))
{
probingPath = Path.Combine(Path.GetDirectoryName(assemblyPath), fileName);

Debug.WriteLine($"Considering {probingPath} based on ExecutingAssembly");
if (Probe(probingPath, referenceName.Version, out assm))
{
return assm;
}
}

// look in AppDomain base directory
probingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName);
Debug.WriteLine($"Considering {probingPath} based on BaseDirectory");
if (Probe(probingPath, referenceName.Version, out assm))
{
return assm;
}

// look in current directory
Debug.WriteLine($"Considering {fileName}");
if (Probe(fileName, referenceName.Version, out assm))
{
return assm;
}

return null;
}

/// <summary>
/// Considers a path to load for satisfying an assembly ref and loads it
/// if the file exists and version is sufficient.
/// </summary>
/// <param name="filePath">Path to consider for load</param>
/// <param name="minimumVersion">Minimum version to consider</param>
/// <param name="assembly">loaded assembly</param>
/// <returns>true if assembly was loaded</returns>
private static bool Probe(string filePath, Version minimumVersion, out Assembly assembly)
{
if (File.Exists(filePath))
{
AssemblyName name = AssemblyName.GetAssemblyName(filePath);

if (name.Version >= minimumVersion)
{
assembly = Assembly.Load(name);
return true;
}
}

assembly = null;
return false;
}
}
}
13 changes: 13 additions & 0 deletions src/libraries/Microsoft.NETCore.Platforms/src/BuildTask.Desktop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.NETCore.Platforms.BuildTasks
{
public partial class BuildTask
{
static BuildTask()
{
AssemblyResolver.Enable();
}
}
}
151 changes: 151 additions & 0 deletions src/libraries/Microsoft.NETCore.Platforms/src/BuildTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using System;

namespace Microsoft.NETCore.Platforms.BuildTasks
{
public abstract partial class BuildTask : ITask
{
private Log _log;

internal Log Log
{
get { return _log ?? (_log = new Log(new TaskLoggingHelper(this))); }
}

public BuildTask()
{
}

public IBuildEngine BuildEngine
{
get;
set;
}

public ITaskHost HostObject
{
get;
set;
}

public abstract bool Execute();
}

internal class Log : ILog
{
private readonly TaskLoggingHelper _logger;
public Log(TaskLoggingHelper logger)
{
_logger = logger;
}

public void LogError(string message, params object[] messageArgs)
{
_logger.LogError(message, messageArgs);
}

public void LogErrorFromException(Exception exception, bool showStackTrace)
{
_logger.LogErrorFromException(exception, showStackTrace);
}

public void LogMessage(string message, params object[] messageArgs)
{
_logger.LogMessage(message, messageArgs);
}

public void LogMessage(LogImportance importance, string message, params object[] messageArgs)
{
_logger.LogMessage((MessageImportance)importance, message, messageArgs);
}

public void LogWarning(string message, params object[] messageArgs)
{
_logger.LogWarning(message, messageArgs);
}

public bool HasLoggedErrors { get { return _logger.HasLoggedErrors; } }
}

public enum LogImportance
{
Low = MessageImportance.Low,
Normal = MessageImportance.Normal,
High = MessageImportance.High
}


public interface ILog
{
//
// Summary:
// Logs an error with the specified message.
//
// Parameters:
// message:
// The message.
//
// messageArgs:
// Optional arguments for formatting the message string.
//
// Exceptions:
// T:System.ArgumentNullException:
// message is null.
void LogError(string message, params object[] messageArgs);

//
// Summary:
// Logs a message with the specified string.
//
// Parameters:
// message:
// The message.
//
// messageArgs:
// The arguments for formatting the message.
//
// Exceptions:
// T:System.ArgumentNullException:
// message is null.
void LogMessage(string message, params object[] messageArgs);

//
// Summary:
// Logs a message with the specified string and importance.
//
// Parameters:
// importance:
// One of the enumeration values that specifies the importance of the message.
//
// message:
// The message.
//
// messageArgs:
// The arguments for formatting the message.
//
// Exceptions:
// T:System.ArgumentNullException:
// message is null.
void LogMessage(LogImportance importance, string message, params object[] messageArgs);

//
// Summary:
// Logs a warning with the specified message.
//
// Parameters:
// message:
// The message.
//
// messageArgs:
// Optional arguments for formatting the message string.
//
// Exceptions:
// T:System.ArgumentNullException:
// message is null.
void LogWarning(string message, params object[] messageArgs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<PropertyGroup>
<UseTargetFrameworkSDK>false</UseTargetFrameworkSDK>
</PropertyGroup>
<Import Project="..\..\Directory.Build.props" />
</Project>
Loading