private JObject WritePortableTargetLibrary(RuntimeLibrary runtimeLibrary, CompilationLibrary compilationLibrary)
        {
            var libraryObject = new JObject();

            var dependencies = new HashSet <Dependency>();

            if (runtimeLibrary != null)
            {
                // Add runtime-agnostic assets
                AddAssets(libraryObject, DependencyContextStrings.RuntimeAssembliesKey, runtimeLibrary.RuntimeAssemblyGroups.GetDefaultGroup());
                AddAssets(libraryObject, DependencyContextStrings.NativeLibrariesKey, runtimeLibrary.NativeLibraryGroups.GetDefaultGroup());
                AddResourceAssemblies(libraryObject, runtimeLibrary.ResourceAssemblies);

                // Add runtime-specific assets
                var runtimeTargets = new JObject();
                AddRuntimeSpecificAssetGroups(runtimeTargets, DependencyContextStrings.RuntimeAssetType, runtimeLibrary.RuntimeAssemblyGroups);
                AddRuntimeSpecificAssetGroups(runtimeTargets, DependencyContextStrings.NativeAssetType, runtimeLibrary.NativeLibraryGroups);
                if (runtimeTargets.Count > 0)
                {
                    libraryObject.Add(DependencyContextStrings.RuntimeTargetsPropertyName, runtimeTargets);
                }

                dependencies.UnionWith(runtimeLibrary.Dependencies);
            }

            if (compilationLibrary != null)
            {
                AddCompilationAssemblies(libraryObject, compilationLibrary.Assemblies);

                dependencies.UnionWith(compilationLibrary.Dependencies);
            }

            AddDependencies(libraryObject, dependencies);
            return(libraryObject);
        }
Example #2
0
        private JObject WritePortableTargetLibrary(RuntimeLibrary runtimeLibrary, CompilationLibrary compilationLibrary)
        {
            var libraryObject = new JObject();

            var dependencies = new HashSet <Dependency>();

            if (runtimeLibrary != null)
            {
                if (runtimeLibrary.RuntimeTargets.Any())
                {
                    libraryObject.Add(new JProperty(
                                          DependencyContextStrings.RuntimeTargetsPropertyName,
                                          new JObject(runtimeLibrary.RuntimeTargets.SelectMany(WriteRuntimeTarget)))
                                      );
                }
                AddRuntimeAssemblies(libraryObject, runtimeLibrary.Assemblies);
                AddResourceAssemblies(libraryObject, runtimeLibrary.ResourceAssemblies);
                libraryObject.Add(DependencyContextStrings.NativeLibrariesKey, WriteAssetList(runtimeLibrary.NativeLibraries));

                dependencies.UnionWith(runtimeLibrary.Dependencies);
            }

            if (compilationLibrary != null)
            {
                AddCompilationAssemblies(libraryObject, compilationLibrary.Assemblies);

                dependencies.UnionWith(compilationLibrary.Dependencies);
            }

            AddDependencies(libraryObject, dependencies);
            return(libraryObject);
        }
Example #3
0
        public void PassesLibraryToAllResolvers()
        {
            var fail = new Mock<ICompilationAssemblyResolver>();
            var failTwo = new Mock<ICompilationAssemblyResolver>();
            var resolvers = new[]
            {
                fail.Object,
                failTwo.Object
            };

            var library = new CompilationLibrary(
                string.Empty,
                string.Empty,
                string.Empty,
                string.Empty,
                Enumerable.Empty<string>(),
                Enumerable.Empty<Dependency>(),
                false);

            var resolver = new CompositeCompilationAssemblyResolver(resolvers);
            var result = resolver.TryResolveAssemblyPaths(library, null);

            fail.Verify(r => r.TryResolveAssemblyPaths(library, null), Times.Once());
            failTwo.Verify(r => r.TryResolveAssemblyPaths(library, null), Times.Once());
        }
Example #4
0
        public void PopulatedAssemblies()
        {
            var fail = new Mock<ICompilationAssemblyResolver>();
            var success = new Mock<ICompilationAssemblyResolver>();
            success.Setup(r => r.TryResolveAssemblyPaths(It.IsAny<CompilationLibrary>(), It.IsAny<List<string>>()))
                .Returns(true)
                .Callback((CompilationLibrary l, List<string> a) =>
                {
                    a.Add("Assembly");
                });

            var resolvers = new[]
            {
                fail.Object,
                success.Object
            };

            var assemblies = new List<string>();
            var library = new CompilationLibrary(string.Empty, string.Empty, string.Empty, string.Empty, null, null, false);

            var resolver = new CompositeCompilationAssemblyResolver(resolvers);
            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            assemblies.Should().Contain("Assembly");
        }
Example #5
0
 public DependencyContext(string target, string runtime, CompilationOptions compilationOptions, CompilationLibrary[] compileLibraries, RuntimeLibrary[] runtimeLibraries)
 {
     Target = target;
     Runtime = runtime;
     CompilationOptions = compilationOptions;
     CompileLibraries = compileLibraries;
     RuntimeLibraries = runtimeLibraries;
 }
Example #6
0
 public IEnumerable<string> ResolveReferencePaths(CompilationLibrary compilationLibrary)
 {
     var assemblies = new List<string>();
     if (!DefaultResolver.TryResolveAssemblyPaths(compilationLibrary, assemblies))
     {
         throw new InvalidOperationException($"Can not find compilation library location for package '{PackageName}'");
     }
     return assemblies;
 }
        private void WritePortableTargetLibrary(string key, RuntimeLibrary runtimeLibrary, CompilationLibrary compilationLibrary, ref UnifiedJsonWriter jsonWriter)
        {
            jsonWriter.WriteStartObject(key);

            var dependencies = new HashSet <Dependency>();

            if (runtimeLibrary != null)
            {
                dependencies.UnionWith(runtimeLibrary.Dependencies);
            }

            if (compilationLibrary != null)
            {
                dependencies.UnionWith(compilationLibrary.Dependencies);
            }
            AddDependencies(dependencies, ref jsonWriter);


            if (runtimeLibrary != null)
            {
                // Add runtime-agnostic assets
                AddAssets(DependencyContextStrings.RuntimeAssembliesKey, runtimeLibrary.RuntimeAssemblyGroups.GetDefaultGroup(), ref jsonWriter);
                AddAssets(DependencyContextStrings.NativeLibrariesKey, runtimeLibrary.NativeLibraryGroups.GetDefaultGroup(), ref jsonWriter);
                AddResourceAssemblies(runtimeLibrary.ResourceAssemblies, ref jsonWriter);

                // Add runtime-specific assets
                bool wroteObjectStart = false;
                wroteObjectStart = AddRuntimeSpecificAssetGroups(DependencyContextStrings.RuntimeAssetType, runtimeLibrary.RuntimeAssemblyGroups, wroteObjectStart, ref jsonWriter);
                wroteObjectStart = AddRuntimeSpecificAssetGroups(DependencyContextStrings.NativeAssetType, runtimeLibrary.NativeLibraryGroups, wroteObjectStart, ref jsonWriter);

                if (wroteObjectStart)
                {
                    jsonWriter.WriteEndObject();
                }
            }

            if (compilationLibrary != null)
            {
                AddCompilationAssemblies(compilationLibrary.Assemblies, ref jsonWriter);
            }

            if (compilationLibrary != null && runtimeLibrary == null)
            {
                jsonWriter.WriteBoolean(DependencyContextStrings.CompilationOnlyPropertyName, true, escape: false);
            }

            jsonWriter.WriteEndObject();
        }