Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

#1688: When resolve assembly from GAC compare version #1699

Merged
merged 2 commits into from
May 7, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,25 @@ public LibraryDescription GetDescription(LibraryRange libraryRange, FrameworkNam
var version = libraryRange.VersionRange?.MinVersion;

string path;
if (!TryResolvePartialName(name, out path))
if (!TryResolvePartialName(name, version, out path))
{
return null;
}

SemanticVersion assemblyVersion = VersionUtility.GetAssemblyVersion(path);
_resolvedPaths[name] = path;

if (version == null || version == assemblyVersion)
return new LibraryDescription
{
_resolvedPaths[name] = path;

return new LibraryDescription
LibraryRange = libraryRange,
Identity = new Library
{
LibraryRange = libraryRange,
Identity = new Library
{
Name = name,
Version = assemblyVersion,
IsGacOrFrameworkReference = true
},
LoadableAssemblies = new[] { name },
Dependencies = Enumerable.Empty<LibraryDependency>()
};
}

return null;
Name = name,
Version = version,
IsGacOrFrameworkReference = true
},
LoadableAssemblies = new[] { name },
Dependencies = Enumerable.Empty<LibraryDependency>()
};
}

public void Initialize(IEnumerable<LibraryDescription> dependencies, FrameworkName targetFramework, string runtimeIdentifier)
Expand All @@ -99,7 +92,7 @@ public ILibraryExport GetLibraryExport(ILibraryKey target)
return null;
}

private bool TryResolvePartialName(string name, out string assemblyLocation)
private bool TryResolvePartialName(string name, SemanticVersion version, out string assemblyLocation)
{
foreach (var gacPath in GetGacSearchPaths())
{
Expand All @@ -110,13 +103,19 @@ private bool TryResolvePartialName(string name, out string assemblyLocation)
continue;
}

var match = di.EnumerateFiles("*.dll", SearchOption.AllDirectories)
.FirstOrDefault(d => Path.GetFileNameWithoutExtension(d.Name).Equals(name, StringComparison.OrdinalIgnoreCase));

if (match != null)
foreach (var assemblyFile in di.EnumerateFiles("*.dll", SearchOption.AllDirectories))
{
assemblyLocation = match.FullName;
return true;
if (!Path.GetFileNameWithoutExtension(assemblyFile.Name).Equals(name, StringComparison.OrdinalIgnoreCase))
{
continue;
}

SemanticVersion assemblyVersion = VersionUtility.GetAssemblyVersion(assemblyFile.FullName);
if (version == null || assemblyVersion == version)
{
assemblyLocation = assemblyFile.FullName;
return true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.AspNet.Testing.xunit;
using Microsoft.Framework.Runtime.Helpers;
using NuGet;
using Xunit;

namespace Microsoft.Framework.Runtime.Tests
{
public class GacDependencyResolverFacts
{
[ConditionalTheory]
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the other conditional?

[OSSkipCondition(OperatingSystems.Linux | OperatingSystems.MacOSX)]
[InlineData("mscorlib", "4.0.0.0", "dnx451", true)]
[InlineData("mscorlib", "1.0.0.0", "dnx451", false)]
[InlineData("mscorlib", "4.0.0.0", "dnxcore50", false)]
public void GetDescriptionReturnsCorrectResults(string name, string version, string framework, bool found)
{
var libraryRange = new LibraryRange()
{
Name = name,
VersionRange = VersionUtility.ParseVersionRange(version),
IsGacOrFrameworkReference = true
};

var frameworkName = FrameworkNameHelper.ParseFrameworkName(framework);
var resolver = new GacDependencyResolver();
var library = resolver.GetDescription(libraryRange, frameworkName);

if (found)
{
Assert.NotNull(library);
Assert.Equal(SemanticVersion.Parse(version), library.Identity.Version);
}
else
{
Assert.Null(library);
}
}
}
}
1 change: 1 addition & 0 deletions test/Microsoft.Framework.Runtime.Tests/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"dependencies": {
"Microsoft.Framework.Runtime": "1.0.0-*",
"Microsoft.Framework.Runtime.Abstractions": "1.0.0-*",
"Microsoft.AspNet.Testing": "1.0.0-*",
"xunit.runner.aspnet": "2.0.0-aspnet-*"
},
"frameworks": {
Expand Down