From 25b5ce9c7781b627d33fdf63bea871c7672b3afb Mon Sep 17 00:00:00 2001 From: David Fowler Date: Fri, 4 Mar 2016 01:17:37 -0800 Subject: [PATCH] Tweak error handling a little bit - Handle unresolved projects better in build - Move unresolved package marking to the resolver - Added ToString to LibraryKey for easy diagnosis of errors --- .../PackageDescription.cs | 5 +++-- .../ProjectContextBuilder.cs | 12 +++++------- .../Resolution/PackageDependencyProvider.cs | 13 +++++++++---- .../dotnet-build/ProjectDependenciesFacade.cs | 2 +- .../LibraryExporterPackageTests.cs | 2 +- 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs b/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs index 5327a4896..fc75e998e 100644 --- a/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs +++ b/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs @@ -16,14 +16,15 @@ namespace Microsoft.DotNet.ProjectModel LockFilePackageLibrary package, LockFileTargetLibrary lockFileLibrary, IEnumerable dependencies, - bool compatible) + bool compatible, + bool resolved) : base( new LibraryIdentity(package.Name, package.Version, LibraryType.Package), "sha512-" + package.Sha512, path, dependencies: dependencies, framework: null, - resolved: compatible, + resolved: resolved, compatible: compatible) { Library = package; diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index 720e13dca..8d617df63 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -274,13 +274,6 @@ namespace Microsoft.DotNet.ProjectModel { var library = pair.Value; - if (Equals(library.Identity.Type, LibraryType.Package) && - !Directory.Exists(library.Path)) - { - // If the package path doesn't exist then mark this dependency as unresolved - library.Resolved = false; - } - // The System.* packages provide placeholders on any non netstandard platform // To make them work seamlessly on those platforms, we fill the gap with a reference // assembly (if available) @@ -469,6 +462,11 @@ namespace Microsoft.DotNet.ProjectModel return combiner.CombinedHash; } + + public override string ToString() + { + return Name + " " + LibraryType; + } } } } diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs index 611c2604b..df0bdf64f 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs @@ -41,17 +41,22 @@ namespace Microsoft.DotNet.ProjectModel.Resolution PopulateDependencies(dependencies, targetLibrary, targetFramework); var path = _packagePathResolver.GetInstallPath(package.Name, package.Version); + var exists = Directory.Exists(path); - // If the package's compile time assemblies is for a portable profile then, read the assembly metadata - // and turn System.* references into reference assembly dependencies - PopulateLegacyPortableDependencies(targetFramework, dependencies, path, targetLibrary); + if (exists) + { + // If the package's compile time assemblies is for a portable profile then, read the assembly metadata + // and turn System.* references into reference assembly dependencies + PopulateLegacyPortableDependencies(targetFramework, dependencies, path, targetLibrary); + } var packageDescription = new PackageDescription( path, package, targetLibrary, dependencies, - compatible); + compatible, + resolved: compatible && exists); return packageDescription; } diff --git a/src/dotnet/commands/dotnet-build/ProjectDependenciesFacade.cs b/src/dotnet/commands/dotnet-build/ProjectDependenciesFacade.cs index 770f7848f..cc5086404 100644 --- a/src/dotnet/commands/dotnet-build/ProjectDependenciesFacade.cs +++ b/src/dotnet/commands/dotnet-build/ProjectDependenciesFacade.cs @@ -27,7 +27,7 @@ namespace Microsoft.DotNet.Tools.Build { var projectDependency = dependency.Library as ProjectDescription; - if (projectDependency != null && projectDependency.Project.Files.SourceFiles.Any()) + if (projectDependency != null && projectDependency.Resolved && projectDependency.Project.Files.SourceFiles.Any()) { ProjectDependenciesWithSources[projectDependency.Identity.Name] = projectDependency; } diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs index 1fe4cbb7b..2b845545d 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/LibraryExporterPackageTests.cs @@ -50,7 +50,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests return new PackageDescription(PackagePath, package ?? new LockFilePackageLibrary(), target ?? new LockFileTargetLibrary(), - new List(), true); + new List(), compatible: true, resolved: true); } [Fact]