Exemplo n.º 1
0
        public void IncludesReferencesToEmbeddedContent()
        {
            // Arrange/Act
            var embeddedContent = new[]
            {
                new EmbeddedResourceInfo(EmbeddedResourceKind.Static, "my/static/file"),
                new EmbeddedResourceInfo(EmbeddedResourceKind.Css, "css/first.css"),
                new EmbeddedResourceInfo(EmbeddedResourceKind.JavaScript, "javascript/first.js"),
                new EmbeddedResourceInfo(EmbeddedResourceKind.Css, "css/second.css"),
                new EmbeddedResourceInfo(EmbeddedResourceKind.JavaScript, "javascript/second.js"),
            };
            var content = BootJsonWriter.GetBootJsonContent(
                "MyApp.Entrypoint",
                "MyNamespace.MyType::MyMethod",
                assemblyReferences: new[] { "Something.dll" },
                embeddedContent: embeddedContent,
                linkerEnabled: true);

            // Assert
            var parsedContent = JsonConvert.DeserializeObject <JObject>(content);

            Assert.Equal(
                new[] { "css/first.css", "css/second.css" },
                parsedContent["cssReferences"].Values <string>());
            Assert.Equal(
                new[] { "javascript/first.js", "javascript/second.js" },
                parsedContent["jsReferences"].Values <string>());
        }
Exemplo n.º 2
0
        public static void Command(CommandLineApplication command)
        {
            var referencesFile = command.Option("--references",
                                                "The path to a file that lists the paths to given referenced dll files",
                                                CommandOptionType.SingleValue);

            var embeddedResourcesFile = command.Option("--embedded-resources",
                                                       "The path to a file that lists the paths of .NET assemblies that may contain embedded resources (typically, referenced assemblies in their pre-linked states)",
                                                       CommandOptionType.SingleValue);

            var outputPath = command.Option("--output",
                                            "Path to the output file",
                                            CommandOptionType.SingleValue);

            var mainAssemblyPath = command.Argument("assembly",
                                                    "Path to the assembly containing the entry point of the application.");

            var linkerEnabledFlag = command.Option("--linker-enabled",
                                                   "If set, specifies that the application is being built with linking enabled.",
                                                   CommandOptionType.NoValue);

            command.OnExecute(() =>
            {
                if (string.IsNullOrEmpty(mainAssemblyPath.Value) || !outputPath.HasValue())
                {
                    command.ShowHelp(command.Name);
                    return(1);
                }

                try
                {
                    var referencesSources = referencesFile.HasValue()
                        ? File.ReadAllLines(referencesFile.Value())
                        : Array.Empty <string>();

                    var embeddedResourcesSources = embeddedResourcesFile.HasValue()
                        ? File.ReadAllLines(embeddedResourcesFile.Value())
                        : Array.Empty <string>();

                    BootJsonWriter.WriteFile(
                        mainAssemblyPath.Value,
                        referencesSources,
                        embeddedResourcesSources,
                        linkerEnabledFlag.HasValue(),
                        outputPath.Value());
                    return(0);
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"ERROR: {ex.Message}");
                    Console.WriteLine(ex.StackTrace);
                    return(1);
                }
            });
        }
Exemplo n.º 3
0
        public void ProducesJsonReferencingAssemblyAndDependencies()
        {
            // Arrange/Act
            var assemblyReferences = new string[] { "System.Abc.dll", "MyApp.ClassLib.dll", };
            var content            = BootJsonWriter.GetBootJsonContent(
                "MyApp.Entrypoint.dll",
                "MyNamespace.MyType::MyMethod",
                assemblyReferences,
                Enumerable.Empty <EmbeddedResourceInfo>(),
                linkerEnabled: true);

            // Assert
            var parsedContent = JsonConvert.DeserializeObject <JObject>(content);

            Assert.Equal("MyApp.Entrypoint.dll", parsedContent["main"].Value <string>());
            Assert.Equal("MyNamespace.MyType::MyMethod", parsedContent["entryPoint"].Value <string>());
            Assert.Equal(assemblyReferences, parsedContent["assemblyReferences"].Values <string>());
        }