Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
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
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);
}
}
46 changes: 46 additions & 0 deletions src/libraries/Microsoft.NETCore.Platforms/src/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Generic;
using System.Linq;
using Microsoft.Build.Framework;

namespace Microsoft.NETCore.Platforms.BuildTasks
{
public static class Extensions
{
public static string GetString(this ITaskItem taskItem, string metadataName)
{
var metadataValue = taskItem.GetMetadata(metadataName)?.Trim();
return string.IsNullOrEmpty(metadataValue) ? null : metadataValue;
}

public static bool GetBoolean(this ITaskItem taskItem, string metadataName, bool defaultValue = false)
{
bool result = false;
var metadataValue = taskItem.GetMetadata(metadataName);
if (!bool.TryParse(metadataValue, out result))
{
result = defaultValue;
}
return result;
}

public static IEnumerable<string> GetStrings(this ITaskItem taskItem, string metadataName)
{
var metadataValue = taskItem.GetMetadata(metadataName)?.Trim();
if (!string.IsNullOrEmpty(metadataValue))
{
return metadataValue.Split(';').Where(v => !string.IsNullOrEmpty(v.Trim())).ToArray();
}

return Enumerable.Empty<string>();
}

public static IEnumerable<T> NullAsEmpty<T>(this IEnumerable<T> source)
{
return source ?? Enumerable.Empty<T>();
}

}
}
Loading