public void GetCandidateLibraries_LibraryNameComparisonsAreCaseInsensitive()
        {
            // Arrange
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
                {
                     GetLibrary("Foo", "MICROSOFT.ASPNETCORE.MVC.CORE"),
                     GetLibrary("Bar", "microsoft.aspnetcore.mvc"),
                     GetLibrary("Qux", "Not.Mvc.Assembly", "Unofficial.Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Baz", "mIcRoSoFt.AsPnEtCoRe.MvC.aBsTrAcTiOnS"),
                     GetLibrary("Microsoft.AspNetCore.Mvc.Core"),
                     GetLibrary("LibraryA", "LIBRARYB"),
                     GetLibrary("LibraryB", "microsoft.aspnetcore.mvc"),
                     GetLibrary("Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Not.Mvc.Assembly"),
                     GetLibrary("Unofficial.Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
                },
                Enumerable.Empty<RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { "Foo", "Bar", "Baz", "LibraryA", "LibraryB" }, candidates.Select(a => a.Name));
        }
        public void MergeMergesRuntimeGraph()
        {
            var context = new DependencyContext(
                CreateTargetInfo(),
                CompilationOptions.Default,
                Enumerable.Empty<CompilationLibrary>(),
                Enumerable.Empty<RuntimeLibrary>(),
                new RuntimeFallbacks[]
                {
                    new RuntimeFallbacks("win8-x64", new [] { "win8" }),
                });

            var contextRedist = new DependencyContext(
                CreateTargetInfo(),
                CompilationOptions.Default,
                Enumerable.Empty<CompilationLibrary>(),
                Enumerable.Empty<RuntimeLibrary>(),
                new RuntimeFallbacks[]
                {
                    new RuntimeFallbacks("win8", new [] { "win7-x64", "win7-x86" }),
                });

            var result = context.Merge(contextRedist);
            result.RuntimeGraph.Should().Contain(g => g.Runtime == "win8-x64").
                Subject.Fallbacks.Should().BeEquivalentTo("win8");
            result.RuntimeGraph.Should().Contain(g => g.Runtime == "win8").
                Subject.Fallbacks.Should().BeEquivalentTo("win7-x64", "win7-x86");
        }
Exemplo n.º 3
0
 private JObject WriteTargets(DependencyContext context)
 {
     return new JObject(
         new JProperty(context.Target, WriteTarget(context.CompileLibraries, false)),
         new JProperty(context.Target + DependencyContextStrings.VersionSeperator + context.Runtime,
             WriteTarget(context.RuntimeLibraries, true))
         );
 }
Exemplo n.º 4
0
 private JObject Write(DependencyContext context)
 {
     return new JObject(
         new JProperty(DependencyContextStrings.CompilationOptionsPropertName, WriteCompilationOptions(context.CompilationOptions)),
         new JProperty(DependencyContextStrings.TargetsPropertyName, WriteTargets(context)),
         new JProperty(DependencyContextStrings.LibrariesPropertyName, WriteLibraries(context))
         );
 }
 public static IEnumerable<string> GetDefaultNativeAssets(this RuntimeLibrary self, DependencyContext context)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     return ResolveAssets(context, string.Empty, self.NativeLibraryGroups);
 }
        // Returns a list of libraries that references the assemblies in <see cref="ReferenceAssemblies"/>.
        // By default it returns all assemblies that reference any of the primary MVC assemblies
        // while ignoring MVC assemblies.
        // Internal for unit testing
        internal static IEnumerable<RuntimeLibrary> GetCandidateLibraries(DependencyContext dependencyContext)
        {
            if (ReferenceAssemblies == null)
            {
                return Enumerable.Empty<RuntimeLibrary>();
            }

            return dependencyContext.RuntimeLibraries.Where(IsCandidateLibrary);
        }
 private static IEnumerable<string> ResolveAssets(
     DependencyContext context, 
     string runtimeIdentifier, 
     IEnumerable<RuntimeAssetGroup> assets)
 {
     var fallbacks = context.RuntimeGraph.FirstOrDefault(f => f.Runtime == runtimeIdentifier);
     var rids = Enumerable.Concat(new[] { runtimeIdentifier }, fallbacks?.Fallbacks ?? Enumerable.Empty<string>());
     return SelectAssets(rids, assets);
 }
        public void MergeMergesLibraries()
        {
            var compilationLibraries = new[]
            {
                CreateCompilation("PackageA"),
                CreateCompilation("PackageB"),
            };

            var runtimeLibraries = new[]
            {
                CreateRuntime("PackageA"),
                CreateRuntime("PackageB"),
            };

            var compilationLibrariesRedist = new[]
            {
                CreateCompilation("PackageB"),
                CreateCompilation("PackageC"),
            };

            var runtimeLibrariesRedist = new[]
            {
                CreateRuntime("PackageB"),
                CreateRuntime("PackageC"),
            };

            var context = new DependencyContext(
                CreateTargetInfo(),
                CompilationOptions.Default,
                compilationLibraries,
                runtimeLibraries,
                new RuntimeFallbacks[] { });

            var contextRedist = new DependencyContext(
                CreateTargetInfo(),
                CompilationOptions.Default,
                compilationLibrariesRedist,
                runtimeLibrariesRedist,
                new RuntimeFallbacks[] { });

            var result = context.Merge(contextRedist);

            result.CompileLibraries.Should().BeEquivalentTo(new[]
            {
                compilationLibraries[0],
                compilationLibraries[1],
                compilationLibrariesRedist[1],
            });

            result.RuntimeLibraries.Should().BeEquivalentTo(new[]
            {
                runtimeLibraries[0],
                runtimeLibraries[1],
                runtimeLibrariesRedist[1],
            });
        }
        // Returns a list of libraries that references the assemblies in <see cref="ReferenceAssemblies"/>.
        // By default it returns all assemblies that reference any of the primary MVC assemblies
        // while ignoring MVC assemblies.
        // Internal for unit testing
        internal static IEnumerable<RuntimeLibrary> GetCandidateLibraries(DependencyContext dependencyContext)
        {
            if (ReferenceAssemblies == null)
            {
                return Enumerable.Empty<RuntimeLibrary>();
            }

            var candidatesResolver = new CandidateResolver(dependencyContext.RuntimeLibraries, ReferenceAssemblies);
            return candidatesResolver.GetCandidates();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Registers CQRS chunks into service container
        /// </summary>
        /// <param name="services">DI container</param>
        /// <param name="dependencyContext">Dependencies</param>
        /// <param name="filter">Predicate to filter types you would like to register</param>
        public static IServiceCollection AddCqrsSpirit(this IServiceCollection services, DependencyContext dependencyContext, Func<Type, bool> filter = null)
        {
            var assemblies = dependencyContext.RuntimeLibraries
                .Where(library => library.Dependencies.Any(dependency => dependency.Name.StartsWith(CurrentAssembly.GetName().Name, StringComparison.OrdinalIgnoreCase)))
                .SelectMany(library => library.GetDefaultAssemblyNames(dependencyContext))
                .Select(Assembly.Load)
                .ToArray();

            return AddCqrsSpirit(services, assemblies, filter);
        }
Exemplo n.º 11
0
 public void Write(DependencyContext context, Stream stream)
 {
     using (var writer = new StreamWriter(stream))
     {
         using (var jsonWriter = new JsonTextWriter(writer))
         {
             Write(context).WriteTo(jsonWriter);
         }
     }
 }
 public static IEnumerable<AssemblyName> GetDefaultAssemblyNames(this RuntimeLibrary self, DependencyContext context)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     return ResolveAssets(context, string.Empty, self.RuntimeAssemblyGroups).Select(GetAssemblyName);
 }
        internal static IEnumerable<Assembly> GetCandidateAssemblies(Assembly entryAssembly, DependencyContext dependencyContext)
        {
            if (dependencyContext == null)
            {
                // Use the entry assembly as the sole candidate.
                return new[] { entryAssembly };
            }

            return GetCandidateLibraries(dependencyContext)
                .SelectMany(library => library.GetDefaultAssemblyNames(dependencyContext))
                .Select(Assembly.Load);
        }
 public static IEnumerable<string> GetRuntimeNativeAssets(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (runtimeIdentifier == null)
     {
         throw new ArgumentNullException(nameof(runtimeIdentifier));
     }
     return ResolveAssets(context, runtimeIdentifier, self.NativeLibraryGroups);
 }
        // Internal for unit testing
        internal DefaultRoslynCompilationService(
            DependencyContext dependencyContext,
            RazorViewEngineOptions viewEngineOptions,
            IRazorViewEngineFileProviderAccessor fileProviderAccessor,
            ILoggerFactory loggerFactory)
        {
            _dependencyContext = dependencyContext;
            _applicationReferences = new Lazy<List<MetadataReference>>(GetApplicationReferences);
            _fileProvider = fileProviderAccessor.FileProvider;
            _compilationCallback = viewEngineOptions.CompilationCallback;
            _parseOptions = viewEngineOptions.ParseOptions;
            _compilationOptions = viewEngineOptions.CompilationOptions;
            _logger = loggerFactory.CreateLogger<DefaultRoslynCompilationService>();

#if NETSTANDARD1_5
            _razorLoadContext = new RazorLoadContext();
#endif
        }
Exemplo n.º 16
0
        public string GetCommandPathFromDependencyContext(string commandName, DependencyContext dependencyContext)
        {
            var commandCandidates = new List<CommandCandidate>();

            var assemblyCommandCandidates = GetCommandCandidates(
                commandName,
                dependencyContext,
                CommandCandidateType.RuntimeCommandCandidate);
            var nativeCommandCandidates = GetCommandCandidates(
                commandName,
                dependencyContext,
                CommandCandidateType.NativeCommandCandidate);

            commandCandidates.AddRange(assemblyCommandCandidates);
            commandCandidates.AddRange(nativeCommandCandidates);

            var command = ChooseCommandCandidate(commandCandidates);

            return command?.GetAbsoluteCommandPath(_nugetPackageRoot);
        }
Exemplo n.º 17
0
 public void Write(DependencyContext context, Stream stream)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (stream == null)
     {
         throw new ArgumentNullException(nameof(stream));
     }
     using (var writer = new StreamWriter(stream))
     {
         using (var jsonWriter = new JsonTextWriter(writer)
         {
             Formatting = Formatting.Indented
         })
         {
             Write(context).WriteTo(jsonWriter);
         }
     }
 }
        public void GetCandidateLibraries_ReturnsLibrariesReferencingAnyMvcAssembly()
        {
            // Arrange
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
                {
                     GetLibrary("Foo", "Microsoft.AspNetCore.Mvc.Core"),
                     GetLibrary("Bar", "Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Qux", "Not.Mvc.Assembly", "Unofficial.Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Baz", "Microsoft.AspNetCore.Mvc.Abstractions"),
                },
                Enumerable.Empty<RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { "Foo", "Bar", "Baz" }, candidates.Select(a => a.Name));
        }
        public void GetCandidateLibraries_IgnoresMvcAssemblies()
        {
            // Arrange
            var expected = GetLibrary("SomeRandomAssembly", "Microsoft.AspNetCore.Mvc.Abstractions");
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
                {
                     GetLibrary("Microsoft.AspNetCore.Mvc.Core"),
                     GetLibrary("Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
                     expected,
                },
                Enumerable.Empty<RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { expected }, candidates);
        }
 public void Write(DependencyContext context, Stream stream)
 {
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (stream == null)
     {
         throw new ArgumentNullException(nameof(stream));
     }
     using (var bufferWriter = new ArrayBufferWriter())
     {
         // Custom encoder is required to fix https://github.com/dotnet/core-setup/issues/7137
         // Since the JSON is only written to a file that is read by the SDK (and not transmitted over the wire),
         // it is safe to skip escaping certain characters in this scenario
         // (that would otherwise be escaped, by default, as part of defense-in-depth, such as +).
         var options = new JsonWriterOptions {
             Indented = true, Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping
         };
         var jsonWriter = new Utf8JsonWriter(bufferWriter, options);
         WriteCore(context, new UnifiedJsonWriter(jsonWriter));
         bufferWriter.CopyTo(stream);
     }
 }
        public void Compile_ThrowsIfDependencyContextReturnsNoReferencesAndTheApplicationFailsToCompile()
        {
            // Arrange
            var content = "public class MyTestType  {}";
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                Extensions.DependencyModel.CompilationOptions.Default,
                new CompilationLibrary[0],
                new RuntimeLibrary[0],
                Enumerable.Empty<RuntimeFallbacks>());
            var compilationService = new DefaultRoslynCompilationService(
                dependencyContext: dependencyContext,
                viewEngineOptions: GetOptions(),
                fileProviderAccessor: GetFileProviderAccessor(),
                loggerFactory: NullLoggerFactory.Instance);

            var relativeFileInfo = new RelativeFileInfo(
                new TestFileInfo { PhysicalPath = "SomePath" },
                "some-relative-path.cshtml");

            var expected = "The Razor page 'some-relative-path.cshtml' failed to compile. Ensure that your "
                 + "application's project.json sets the 'preserveCompilationContext' compilation property.";

            // Act and Assert
            var ex = Assert.Throws<InvalidOperationException>(() =>
                compilationService.Compile(relativeFileInfo, content));
            Assert.Equal(expected, ex.Message);
        }
Exemplo n.º 22
0
 public static IEnumerable<AssemblyName> GetRuntimeAssemblyNames(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     return ResolveAssets(context, runtimeIdentifier, self.RuntimeAssemblyGroups).Select(GetAssemblyName);
 }
Exemplo n.º 23
0
        private IEnumerable<CommandCandidate> GetCommandCandidates(
            string commandName, 
            DependencyContext dependencyContext,
            CommandCandidateType commandCandidateType)
        {
            var commandCandidates = new List<CommandCandidate>();

            foreach (var runtimeLibrary in dependencyContext.RuntimeLibraries)
            {
                IEnumerable<RuntimeAssetGroup> runtimeAssetGroups = null;

                if (commandCandidateType == CommandCandidateType.NativeCommandCandidate)
                {
                    runtimeAssetGroups = runtimeLibrary.NativeLibraryGroups;
                }
                else if (commandCandidateType == CommandCandidateType.RuntimeCommandCandidate)
                {
                    runtimeAssetGroups = runtimeLibrary.RuntimeAssemblyGroups;
                }

                commandCandidates.AddRange(GetCommandCandidatesFromRuntimeAssetGroups(
                                    commandName,
                                    runtimeAssetGroups,
                                    runtimeLibrary.Name,
                                    runtimeLibrary.Version));            
            }

            return commandCandidates;
        }
Exemplo n.º 24
0
 private JObject WriteRuntimeGraph(DependencyContext context)
 {
     return(new JObject(
                context.RuntimeGraph.Select(g => new JProperty(g.Runtime, new JArray(g.Fallbacks)))
                ));
 }
 public DefaultAssemblyLocator(IHostingEnvironment environment)
 {
     _entryAssembly = Assembly.Load(new AssemblyName(environment.ApplicationName));
     _dependencyContext = DependencyContext.Load(_entryAssembly);
 }
Exemplo n.º 26
0
 public void Write(DependencyContext context !!, Stream stream !!)
Exemplo n.º 27
0
 public static IEnumerable <string> GetRuntimeNativeAssets(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     return(ResolveAssets(context, runtimeIdentifier, self.NativeLibraryGroups));
 }
        public static IEnumerable <AssemblyName> GetDefaultAssemblyNames(this DependencyContext self)
        {
            ThrowHelper.ThrowIfNull(self);

            return(self.RuntimeLibraries.SelectMany(library => library.GetDefaultAssemblyNames(self)));
        }
        public static IEnumerable <RuntimeFile> GetRuntimeNativeRuntimeFileAssets(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
        {
            ThrowHelper.ThrowIfNull(self);
            ThrowHelper.ThrowIfNull(context);
            ThrowHelper.ThrowIfNull(runtimeIdentifier);

            return(ResolveRuntimeFiles(context, runtimeIdentifier, self.NativeLibraryGroups));
        }
        internal static void LoadPlugins(DependencyContext dependencyContext)
        {
            var testFrameworkAssemblies = dependencyContext
                .GetRuntimeAssemblyNames(RuntimeEnvironment.GetRuntimeIdentifier())
                .Where(l => l.Name.StartsWith(TestFrameworkName))
                .ToArray();

            if (testFrameworkAssemblies.Length == 7 && testFrameworkAssemblies.Any(t => t.Name == $"{TestFrameworkName}.Lite"))
            {
                TestCounter.SkipValidation = true;
            }

            var plugins = testFrameworkAssemblies
                .Select(l => Assembly.Load(new AssemblyName(l.Name)).GetType($"{TestFrameworkName}.Plugins.{l.Name.Replace(TestFrameworkName, string.Empty).Trim('.')}TestPlugin"))
                .Where(p => p != null)
                .ToArray();

            if (!plugins.Any())
            {
                throw new InvalidOperationException("Test plugins could not be loaded. Depending on your project's configuration you may need to set the 'preserveCompilationContext' property under 'buildOptions' to 'true' in the test assembly's 'project.json' file and/or may need to call '.StartsFrom<TStartup>().WithTestAssembly(this)'.");
            }

            plugins.ForEach(t =>
            {
                var plugin = Activator.CreateInstance(t);

                var defaultRegistrationPlugin = plugin as IDefaultRegistrationPlugin;
                if (defaultRegistrationPlugin != null)
                {
                    DefaultRegistrationPlugins.Add(defaultRegistrationPlugin);
                }

                var servicePlugin = plugin as IServiceRegistrationPlugin;
                if (servicePlugin != null)
                {
                    ServiceRegistrationPlugins.Add(servicePlugin);
                }

                var routingServicePlugin = plugin as IRoutingServiceRegistrationPlugin;
                if (routingServicePlugin != null)
                {
                    RoutingServiceRegistrationPlugins.Add(routingServicePlugin);
                }

                var initializationPlugin = plugin as IInitializationPlugin;
                if (initializationPlugin != null)
                {
                    InitializationPlugins.Add(initializationPlugin);
                }

                var httpFeatureRegistrationPlugin = plugin as IHttpFeatureRegistrationPlugin;
                if (httpFeatureRegistrationPlugin != null)
                {
                    TestHelper.HttpFeatureRegistrationPlugins.Add(httpFeatureRegistrationPlugin);
                }

                var shouldPassForPlugin = plugin as IShouldPassForPlugin;
                if (shouldPassForPlugin != null)
                {
                    TestHelper.ShouldPassForPlugins.Add(shouldPassForPlugin);
                }
            });
        }
Exemplo n.º 31
0
 public static IEnumerable<string> GetDefaultNativeAssets(this RuntimeLibrary self, DependencyContext context)
 {
     return ResolveAssets(context, string.Empty, self.NativeLibraryGroups);
 }
Exemplo n.º 32
0
 public static IEnumerable<string> GetRuntimeNativeAssets(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     return ResolveAssets(context, runtimeIdentifier, self.NativeLibraryGroups);
 }
Exemplo n.º 33
0
 public static IEnumerable <AssemblyName> GetRuntimeAssemblyNames(this DependencyContext self, string runtimeIdentifier)
 {
     return(self.RuntimeLibraries.SelectMany(library => library.GetRuntimeAssemblyNames(self, runtimeIdentifier)));
 }
        public static IEnumerable <AssemblyName> GetDefaultAssemblyNames(this RuntimeLibrary self, DependencyContext context)
        {
            ThrowHelper.ThrowIfNull(self);
            ThrowHelper.ThrowIfNull(context);

            return(ResolveAssets(context, string.Empty, self.RuntimeAssemblyGroups).Select(GetAssemblyName));
        }
Exemplo n.º 35
0
        private JObject WriteLibraries(DependencyContext context)
        {
            var allLibraries =
                context.RuntimeLibraries.Concat(context.CompileLibraries)
                    .GroupBy(library => library.PackageName + DependencyContextStrings.VersionSeperator + library.Version);

            return new JObject(allLibraries.Select(libraries=> new JProperty(libraries.Key, WriteLibrary(libraries.First()))));
        }
Exemplo n.º 36
0
        public static int Main(string[] args)
        {
            DebugHelper.HandleDebugSwitch(ref args);

            string projectDirectory = null;
            string depsFile = null;
            IReadOnlyList<string> runtimes = null;
            try
            {
                ArgumentSyntax.Parse(args, syntax =>
                {
                    syntax.ApplicationName = "Runtime GraphGenerator";

                    syntax.HandleHelp = false;
                    syntax.HandleErrors = false;

                    syntax.DefineOption("p|project", ref projectDirectory, "Project location");
                    syntax.DefineOption("d|deps", ref depsFile, "Deps file path");

                    syntax.DefineParameterList("runtimes", ref runtimes, "Runtimes");
                });
            }
            catch (ArgumentSyntaxException exception)
            {
                Console.Error.WriteLine(exception.Message);
                return 1;
            }

            if (runtimes == null || runtimes.Count == 0)
            {
                Reporter.Error.WriteLine("No runtimes specified");
                return 1;
            }
            if (!File.Exists(depsFile))
            {
                Reporter.Error.WriteLine($"Deps file not found: {depsFile}");
                return 1;
            }
            if (!Directory.Exists(projectDirectory))
            {
                Reporter.Error.WriteLine($"Project directory not found: {projectDirectory}");
                return 1;
            }

            try
            {
                DependencyContext context;
                using (var depsStream = File.OpenRead(depsFile))
                {
                    context = new DependencyContextJsonReader().Read(depsStream);
                }
                var framework = NuGetFramework.Parse(context.Target.Framework);
                var projectContext = ProjectContext.Create(projectDirectory, framework);

                // Configuration is used only for P2P dependencies so were don't care
                var exporter = projectContext.CreateExporter("Debug");
                var manager = new RuntimeGraphManager();
                var graph = manager.Collect(exporter.GetDependencies(LibraryType.Package));
                var expandedGraph = manager.Expand(graph, runtimes);

                context = new DependencyContext(
                    context.Target,
                    context.CompilationOptions,
                    context.CompileLibraries,
                    context.RuntimeLibraries,
                    expandedGraph
                    );

                using (var depsStream = File.Create(depsFile))
                {
                    new DependencyContextWriter().Write(context, depsStream);
                }

                return 0;
            }
            catch (Exception ex)
            {
#if DEBUG
                Reporter.Error.WriteLine(ex.ToString());
#else
                Reporter.Error.WriteLine(ex.Message);
#endif
                return 1;
            }
        }
Exemplo n.º 37
0
 public static IEnumerable <string> GetDefaultNativeAssets(this RuntimeLibrary self, DependencyContext context)
 {
     return(ResolveAssets(context, string.Empty, self.NativeLibraryGroups));
 }
Exemplo n.º 38
0
 public static IEnumerable <AssemblyName> GetRuntimeAssemblyNames(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     return(ResolveAssets(context, runtimeIdentifier, self.RuntimeAssemblyGroups).Select(GetAssemblyName));
 }
Exemplo n.º 39
0
 public static IEnumerable <string> GetDefaultNativeAssets(this DependencyContext self)
 {
     return(self.RuntimeLibraries.SelectMany(library => library.GetDefaultNativeAssets(self)));
 }
Exemplo n.º 40
0
 public static IEnumerable <AssemblyName> GetRuntimeAssemblyNames(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (runtimeIdentifier == null)
     {
         throw new ArgumentNullException(nameof(runtimeIdentifier));
     }
     return(ResolveAssets(context, runtimeIdentifier, self.RuntimeAssemblyGroups).Select(GetAssemblyName));
 }
Exemplo n.º 41
0
 private string WriteRuntimeTargetInfo(DependencyContext context)
 {
     return(context.IsPortable?
            context.TargetFramework :
            context.TargetFramework + DependencyContextStrings.VersionSeperator + context.Runtime);
 }
Exemplo n.º 42
0
 public static IEnumerable <RuntimeFile> GetDefaultNativeRuntimeFileAssets(this RuntimeLibrary self, DependencyContext context)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     return(ResolveRuntimeFiles(context, string.Empty, self.NativeLibraryGroups));
 }
        public void GetCandidateLibraries_ReturnsLibrariesWithTransitiveReferencesToAnyMvcAssembly()
        {
            // Arrange
            var expectedLibraries = new[] { "Foo", "Bar", "Baz", "LibraryA", "LibraryB", "LibraryC", "LibraryE", "LibraryG", "LibraryH" };

            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
                {
                     GetLibrary("Foo", "Bar"),
                     GetLibrary("Bar", "Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Qux", "Not.Mvc.Assembly", "Unofficial.Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Baz", "Microsoft.AspNetCore.Mvc.Abstractions"),
                     GetLibrary("Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Not.Mvc.Assembly"),
                     GetLibrary("Microsoft.AspNetCore.Mvc.Abstractions"),
                     GetLibrary("Unofficial.Microsoft.AspNetCore.Mvc"),
                     GetLibrary("LibraryA", "LibraryB"),
                     GetLibrary("LibraryB","LibraryC"),
                     GetLibrary("LibraryC", "LibraryD", "Microsoft.AspNetCore.Mvc.Abstractions"),
                     GetLibrary("LibraryD"),
                     GetLibrary("LibraryE","LibraryF","LibraryG"),
                     GetLibrary("LibraryF"),
                     GetLibrary("LibraryG", "LibraryH"),
                     GetLibrary("LibraryH", "LibraryI", "Microsoft.AspNetCore.Mvc"),
                     GetLibrary("LibraryI")
                },
                Enumerable.Empty<RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(expectedLibraries, candidates.Select(a => a.Name));
        }
Exemplo n.º 44
0
 public static IEnumerable <RuntimeFile> GetRuntimeNativeRuntimeFileAssets(this RuntimeLibrary self, DependencyContext context, string runtimeIdentifier)
 {
     if (self == null)
     {
         throw new ArgumentNullException(nameof(self));
     }
     if (context == null)
     {
         throw new ArgumentNullException(nameof(context));
     }
     if (runtimeIdentifier == null)
     {
         throw new ArgumentNullException(nameof(runtimeIdentifier));
     }
     return(ResolveRuntimeFiles(context, runtimeIdentifier, self.NativeLibraryGroups));
 }
Exemplo n.º 45
0
 private JObject WriteRuntimeGraph(DependencyContext context)
 {
     return(new JObject(
                context.RuntimeGraph.Select(g => new JProperty(g.Key, new JArray(g.Value)))
                ));
 }
Exemplo n.º 46
0
 public static IEnumerable<AssemblyName> GetDefaultAssemblyNames(this RuntimeLibrary self, DependencyContext context)
 {
     return ResolveAssets(context, string.Empty, self.RuntimeAssemblyGroups).Select(GetAssemblyName);
 }
        public void GetCandidateLibraries_SkipsMvcAssemblies()
        {
            // Arrange
            var dependencyContext = new DependencyContext(
                new TargetInfo("framework", "runtime", "signature", isPortable: true),
                CompilationOptions.Default,
                new CompilationLibrary[0],
                new[]
                {
                     GetLibrary("MvcSandbox", "Microsoft.AspNetCore.Mvc.Core", "Microsoft.AspNetCore.Mvc"),
                     GetLibrary("Microsoft.AspNetCore.Mvc.TagHelpers", "Microsoft.AspNetCore.Mvc.Razor"),
                     GetLibrary("Microsoft.AspNetCore.Mvc", "Microsoft.AspNetCore.Mvc.Abstractions", "Microsoft.AspNetCore.Mvc.Core"),
                     GetLibrary("Microsoft.AspNetCore.Mvc.Core", "Microsoft.AspNetCore.HttpAbstractions"),
                     GetLibrary("ControllersAssembly", "Microsoft.AspNetCore.Mvc"),

                },
                Enumerable.Empty<RuntimeFallbacks>());

            // Act
            var candidates = DefaultAssemblyPartDiscoveryProvider.GetCandidateLibraries(dependencyContext);

            // Assert
            Assert.Equal(new[] { "MvcSandbox", "ControllersAssembly" }, candidates.Select(a => a.Name));
        }
        public static IEnumerable <RuntimeFile> GetDefaultNativeRuntimeFileAssets(this RuntimeLibrary self, DependencyContext context)
        {
            ThrowHelper.ThrowIfNull(self);

            return(ResolveRuntimeFiles(context, string.Empty, self.NativeLibraryGroups));
        }