Skip to content

Commit

Permalink
GetReferenceAssemblyPaths: Add TargetFrameworkFallbackSearchPaths
Browse files Browse the repository at this point in the history
.. property. This specifies a list of ';' separated paths which are used
as fallback search paths, for looking up the target framework, if could
not be found in @rootpath.
  • Loading branch information
radical committed May 13, 2018
1 parent 3d34ef6 commit 06aea53
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 13 deletions.
39 changes: 39 additions & 0 deletions src/Tasks.UnitTests/GetReferencePaths_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,45 @@ public void TestGeneralFrameworkMonikerGoodWithInvalidCharInIncludePath()
}
}
}

/// <summary>
/// Test the case where there is a good target framework moniker passed in.
/// </summary>
[Fact]
public void TestGeneralFrameworkMonikerGoodWithFrameworkInFallbackPaths()
{
using (var env = TestEnvironment.Create())
{
string frameworkRootDir = Path.Combine(env.DefaultTestDirectory.FolderPath, "framework-root");
var framework41Directory = env.CreateFolder(Path.Combine(frameworkRootDir, Path.Combine("MyFramework", "v4.1") + Path.DirectorySeparatorChar));
var redistListDirectory = env.CreateFolder(Path.Combine(framework41Directory.FolderPath, "RedistList"));

string redistListContents =
"<FileList Redist='Microsoft-Windows-CLRCoreComp' Name='.NET Framework 4.1'>" +
"<File AssemblyName='System.Xml' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
"<File AssemblyName='Microsoft.Build.Engine' Version='2.0.0.0' PublicKeyToken='b03f5f7f11d50a3a' Culture='Neutral' FileVersion='2.0.50727.208' InGAC='true' />" +
"</FileList >";

env.CreateFile(redistListDirectory, "FrameworkList.xml", redistListContents);

string targetFrameworkMoniker = "MyFramework, Version=v4.1";
MockEngine engine = new MockEngine();
GetReferenceAssemblyPaths getReferencePaths = new GetReferenceAssemblyPaths();
getReferencePaths.BuildEngine = engine;
getReferencePaths.TargetFrameworkMoniker = targetFrameworkMoniker;
getReferencePaths.RootPath = env.CreateFolder().FolderPath;
getReferencePaths.RootPath = frameworkRootDir;
getReferencePaths.TargetFrameworkFallbackSearchPaths = $"/foo/bar;{frameworkRootDir}";
getReferencePaths.Execute();
string[] returnedPaths = getReferencePaths.ReferenceAssemblyPaths;
string displayName = getReferencePaths.TargetFrameworkMonikerDisplayName;
Assert.Equal(1, returnedPaths.Length);
Assert.True(returnedPaths[0].Equals(framework41Directory.FolderPath, StringComparison.OrdinalIgnoreCase));
Assert.Equal(0, engine.Log.Length); // "Expected the log to contain nothing"
Assert.True(displayName.Equals(".NET Framework 4.1", StringComparison.OrdinalIgnoreCase));
}
}

}
}
#endif
35 changes: 22 additions & 13 deletions src/Tasks/GetReferenceAssemblyPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ public class GetReferenceAssemblyPaths : TaskExtension
/// </summary>
private string _rootPath;

/// <summary>
/// Target frameworks are looked up in @RootPath. If it cannot be found
/// there, then paths in @TargetFrameworkFallbackSearchPaths
/// are used for the lookup, in order. This can have multiple paths, separated
/// by ';'
/// </summary>
public string TargetFrameworkFallbackSearchPaths
{
get;
set;
}

/// <summary>
/// By default GetReferenceAssemblyPaths performs simple checks
/// to ensure that certain runtime frameworks are installed depending on the
Expand Down Expand Up @@ -237,7 +249,7 @@ public override bool Execute()

try
{
_tfmPaths = GetPaths(_rootPath, moniker);
_tfmPaths = GetPaths(_rootPath, TargetFrameworkFallbackSearchPaths, moniker);

if (_tfmPaths != null && _tfmPaths.Count > 0)
{
Expand All @@ -248,7 +260,7 @@ public override bool Execute()
// There is no point in generating the full framework paths if profile path could not be found.
if (targetingProfile && _tfmPaths != null)
{
_tfmPathsNoProfile = GetPaths(_rootPath, monikerWithNoProfile);
_tfmPathsNoProfile = GetPaths(_rootPath, TargetFrameworkFallbackSearchPaths, monikerWithNoProfile);
}

// The path with out the profile is just the reference assembly paths.
Expand Down Expand Up @@ -278,18 +290,15 @@ public override bool Execute()
/// <summary>
/// Generate the set of chained reference assembly paths
/// </summary>
private IList<String> GetPaths(string rootPath, FrameworkNameVersioning frameworkmoniker)
/// FIXME: do we really need the new arg? or should we just use the property?
private IList<String> GetPaths(string rootPath, string targetFrameworkFallbackSearchPaths, FrameworkNameVersioning frameworkmoniker)
{
IList<String> pathsToReturn = null;

if (String.IsNullOrEmpty(rootPath))
{
pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(frameworkmoniker);
}
else
{
pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(rootPath, frameworkmoniker);
}
IList<String> pathsToReturn = ToolLocationHelper.GetPathToReferenceAssemblies(
frameworkmoniker.Identifier,
frameworkmoniker.Version.ToString(),
frameworkmoniker.Profile,
rootPath,
targetFrameworkFallbackSearchPaths);

if (!SuppressNotFoundError)
{
Expand Down

0 comments on commit 06aea53

Please sign in to comment.