AppBaseCompilationAssemblyResolver shouldn't throw.
authorEric Erhardt <eric.erhardt@microsoft.com>
Tue, 23 May 2017 23:30:15 +0000 (18:30 -0500)
committerEric Erhardt <eric.erhardt@microsoft.com>
Tue, 23 May 2017 23:30:15 +0000 (18:30 -0500)
There are scenarios where a compilation assembly should be resolved from places outside of the appbase folder in a published app.  We shouldn't throw early and let the other resolvers do their job.

Fix dotnet/core-setup#2496

Commit migrated from https://github.com/dotnet/core-setup/commit/d878f8887e4c786d43c4e5e5d6ab77506609811a

src/installer/managed/Microsoft.Extensions.DependencyModel/Resolution/AppBaseCompilationAssemblyResolver.cs
src/installer/test/Microsoft.Extensions.DependencyModel.Tests/AppBaseResolverTests.cs

index 244d6c2..4500b42 100644 (file)
@@ -84,6 +84,8 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
                 directories.Add(sharedDirectory);
             }
 
+            var paths = new List<string>();
+
             foreach (var assembly in library.Assemblies)
             {
                 bool resolved = false;
@@ -93,7 +95,7 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
                     string fullName;
                     if (ResolverUtils.TryResolveAssemblyFile(_fileSystem, directory, assemblyFile, out fullName))
                     {
-                        assemblies.Add(fullName);
+                        paths.Add(fullName);
                         resolved = true;
                         break;
                     }
@@ -101,17 +103,12 @@ namespace Microsoft.Extensions.DependencyModel.Resolution
 
                 if (!resolved)
                 {
-                    // throw in case when we are published app and nothing found
-                    // because we cannot rely on nuget package cache in this case
-                    if (isPublished)
-                    {
-                    throw new InvalidOperationException(
-                        $"Cannot find assembly file {assemblyFile} at '{string.Join(",", directories)}'");
-                }
                     return false;
-            }
+                }
             }
 
+            // only modify the assemblies parameter if we've resolved all files
+            assemblies?.AddRange(paths);
             return true;
         }
     }
index f933627..0d3b8aa 100644 (file)
@@ -143,11 +143,8 @@ namespace Microsoft.Extensions.DependencyModel.Tests
             var resolver = CreateResolver(fileSystem);
             var assemblies = new List<string>();
 
-            var exception = Assert.Throws<InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));
-            exception.Message.Should()
-                .Contain(BasePath)
-                .And.Contain(BasePathRefs)
-                .And.Contain(TestLibraryFactory.SecondAssembly);
+            resolver.TryResolveAssemblyPaths(library, assemblies).Should().Be(false);
+            assemblies.Should().BeEmpty();
         }
 
         [Fact]
@@ -328,7 +325,7 @@ namespace Microsoft.Extensions.DependencyModel.Tests
         }
 
         [Fact]
-        public void ShouldThrowForNonResolvedInPublishedApps()
+        public void ShouldReturnFalseForNonResolvedInPublishedApps()
         {
             var fileSystem = FileSystemMockBuilder
                 .Create()
@@ -341,7 +338,8 @@ namespace Microsoft.Extensions.DependencyModel.Tests
             var resolver = CreateResolver(fileSystem);
             var assemblies = new List<string>();
 
-            Assert.Throws<InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));
+            resolver.TryResolveAssemblyPaths(library, assemblies).Should().Be(false);
+            assemblies.Should().BeEmpty();
         }
 
         [Fact]