fix equality issue in DependencyContextLoader (#2379)

When checking if the provided assembly is the Entry Point Assembly, we
previously just checked if the AssemblyNames were equal, but it turns
out AssemblyName doesn't implement Equals, so it was using Reference
Equality, which fails. This change uses Assembly.Equals, which has an
Equals implementation that works.

Also adds some tests to ensure it's working.

This unblocks scenarios where the EntityFramework `dotnet-ef` command
was trying to read DependencyContext.Default but receiving a null
reference.
This commit is contained in:
Andrew Stanton-Nurse 2016-04-08 15:33:32 -07:00
parent 3d157d0ec8
commit 803fef6a8b
10 changed files with 260 additions and 96 deletions

View file

@ -25,137 +25,146 @@ namespace Microsoft.DotNet.Cli.Build
public static readonly dynamic[] Projects = new[]
{
new
{
Name = "dotnet-dependency-tool-invoker",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-tool-invoker",
IsApplicable = new Func<bool>(() => CurrentPlatform.IsWindows),
new
{
Name = "dotnet-dependency-context-test",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-context-test",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true
},
new
{
Name = "dotnet-desktop-and-portable",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-desktop-and-portable",
},
new
{
Name = "dotnet-dependency-tool-invoker",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-dependency-tool-invoker",
IsApplicable = new Func<bool>(() => CurrentPlatform.IsWindows),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true
},
new
{
Name = "dotnet-hello",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = string.Empty,
new
{
Name = "dotnet-desktop-and-portable",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-desktop-and-portable",
IsApplicable = new Func<bool>(() => CurrentPlatform.IsWindows),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true
},
new
{
Name = "dotnet-hello",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello",
},
new
{
Name = "dotnet-hello",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v1/dotnet-hello",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = string.Empty,
Clean = true
},
new
{
Name = "dotnet-portable",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-portable",
new
{
Name = "dotnet-hello",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-hello/v2/dotnet-hello",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = string.Empty,
Clean = true
},
new
{
Name = "Microsoft.DotNet.Cli.Utils",
IsTool = true,
Path = "src/Microsoft.DotNet.Cli.Utils",
new
{
Name = "dotnet-portable",
IsTool = true,
Path = "TestAssets/TestPackages/dotnet-portable",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = string.Empty,
Clean = true
},
new
{
Name = "Microsoft.DotNet.Cli.Utils",
IsTool = true,
Path = "src/Microsoft.DotNet.Cli.Utils",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.DotNet.ProjectModel",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel",
new
{
Name = "Microsoft.DotNet.ProjectModel",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.DotNet.ProjectModel.Loader",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Loader",
new
{
Name = "Microsoft.DotNet.ProjectModel.Loader",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Loader",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.DotNet.ProjectModel.Workspaces",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Workspaces",
new
{
Name = "Microsoft.DotNet.ProjectModel.Workspaces",
IsTool = true,
Path = "src/Microsoft.DotNet.ProjectModel.Workspaces",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.DotNet.InternalAbstractions",
IsTool = true,
Path = "src/Microsoft.DotNet.InternalAbstractions",
new
{
Name = "Microsoft.DotNet.InternalAbstractions",
IsTool = true,
Path = "src/Microsoft.DotNet.InternalAbstractions",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.Extensions.DependencyModel",
IsTool = true,
Path = "src/Microsoft.Extensions.DependencyModel",
new
{
Name = "Microsoft.Extensions.DependencyModel",
IsTool = true,
Path = "src/Microsoft.Extensions.DependencyModel",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.Extensions.Testing.Abstractions",
IsTool = true,
Path = "src/Microsoft.Extensions.Testing.Abstractions",
new
{
Name = "Microsoft.Extensions.Testing.Abstractions",
IsTool = true,
Path = "src/Microsoft.Extensions.Testing.Abstractions",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.DotNet.Compiler.Common",
IsTool = true,
Path = "src/Microsoft.DotNet.Compiler.Common",
new
{
Name = "Microsoft.DotNet.Compiler.Common",
IsTool = true,
Path = "src/Microsoft.DotNet.Compiler.Common",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "Microsoft.DotNet.Files",
IsTool = true,
Path = "src/Microsoft.DotNet.Files",
new
{
Name = "Microsoft.DotNet.Files",
IsTool = true,
Path = "src/Microsoft.DotNet.Files",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = false
},
new
{
Name = "dotnet-compile-fsc",
IsTool = true,
Path = "src/dotnet-compile-fsc",
new
{
Name = "dotnet-compile-fsc",
IsTool = true,
Path = "src/dotnet-compile-fsc",
IsApplicable = new Func<bool>(() => true),
VersionSuffix = s_testPackageBuildVersionSuffix,
Clean = true

View file

@ -37,17 +37,17 @@ namespace Microsoft.DotNet.Cli.Build
"dotnet-test.Tests",
"Kestrel.Tests"
};
public static readonly dynamic[] ConditionalTestAssets = new[]
{
new { Path = "AppWithDirectDependencyDesktopAndPortable", Skip = new Func<bool>(() => !CurrentPlatform.IsWindows) }
new { Path = "AppWithDirectDependencyDesktopAndPortable", Skip = new Func<bool>(() => !CurrentPlatform.IsWindows) }
};
[Target(
nameof(PrepareTargets.Init),
nameof(SetupTests),
nameof(RestoreTests),
nameof(BuildTests),
nameof(PrepareTargets.Init),
nameof(SetupTests),
nameof(RestoreTests),
nameof(BuildTests),
nameof(RunTests),
nameof(ValidateDependencies))]
public static BuildTargetResult Test(BuildTargetContext c) => c.Success();
@ -128,13 +128,13 @@ namespace Microsoft.DotNet.Cli.Build
{
var dotnet = DotNetCli.Stage2;
dotnet.Restore("--verbosity", "verbose",
dotnet.Restore("--verbosity", "verbose",
"--infer-runtimes",
"--fallbacksource", Dirs.TestPackages,
"--fallbacksource", Dirs.Corehost)
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "DesktopTestProjects"))
.Execute().EnsureSuccessful();
return c.Success();
}
@ -157,7 +157,7 @@ namespace Microsoft.DotNet.Cli.Build
{
versionSuffix = c.BuildContext.Get<BuildVersion>("BuildVersion").VersionSuffix;
}
var fullPath = Path.Combine(c.BuildContext.BuildDirectory, relativePath.Replace('/', Path.DirectorySeparatorChar));
c.Info($"Packing: {fullPath}");
@ -187,14 +187,14 @@ namespace Microsoft.DotNet.Cli.Build
var packBuildResult = DotNetCli.Stage1.Build(buildArgs.ToArray())
.Execute();
}
var projectJson = Path.Combine(fullPath, "project.json");
var dotnetPackArgs = new List<string> {
var dotnetPackArgs = new List<string> {
projectJson,
"--no-build",
"--build-base-path", Dirs.TestPackagesBuild,
"--output", Dirs.TestPackages
"--output", Dirs.TestPackages
};
if (!string.IsNullOrEmpty(versionSuffix))
@ -217,7 +217,7 @@ namespace Microsoft.DotNet.Cli.Build
foreach (var packageName in PackageTargets.ProjectsToPack)
{
Rmdir(Path.Combine(Dirs.NuGetPackages, packageName));
}
}
return c.Success();
}
@ -232,7 +232,7 @@ namespace Microsoft.DotNet.Cli.Build
{
Rmdir(Path.Combine(Dirs.NuGetPackages, ".tools", packageProject.Name));
}
}
}
return c.Success();
}