Esempio n. 1
0
        public void AddAssemblyMetadata(
            AssemblyName applicationAssemblyName,
            StrongNameOptions strongNameOptions)
        {
            if (!string.IsNullOrEmpty(strongNameOptions.KeyFile))
            {
                var updatedOptions = Compilation.Options.WithStrongNameProvider(new DesktopStrongNameProvider());

                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || strongNameOptions.PublicSign)
                {
                    updatedOptions = updatedOptions.WithCryptoPublicKey(
                        SnkUtils.ExtractPublicKey(File.ReadAllBytes(strongNameOptions.KeyFile)));
                }
                else
                {
                    updatedOptions = updatedOptions.WithCryptoKeyFile(strongNameOptions.KeyFile)
                                     .WithDelaySign(strongNameOptions.DelaySign);
                }

                Compilation = Compilation.WithOptions(updatedOptions);
            }

            var assemblyVersionContent = $"[assembly:{typeof(AssemblyVersionAttribute).FullName}(\"{applicationAssemblyName.Version}\")]";
            var syntaxTree             = Compiler.CreateSyntaxTree(SourceText.From(assemblyVersionContent));

            Compilation = Compilation.AddSyntaxTrees(syntaxTree);
        }
        public void Configure(CommandLineApplication app)
        {
            Application = app;
            Options.Configure(app);
            StrongNameOptions.Configure(app);

            OutputPathOption = app.Option(
                OutputPathTemplate,
                "Path to the emit the precompiled assembly to.",
                CommandOptionType.SingleValue);

            ApplicationNameOption = app.Option(
                ApplicationNameTemplate,
                "Name of the application to produce precompiled assembly for.",
                CommandOptionType.SingleValue);

            app.OnExecute(() => Execute());
        }