diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CommonOptions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CommonOptions.cs deleted file mode 100644 index 5f954cf7b5..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CommonOptions.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.CommandLineUtils; - -namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal -{ - public class CommonOptions - { - public static readonly string ConfigureCompilationTypeTemplate = "--configure-compilation-type"; - public static readonly string ContentRootTemplate = "--content-root"; - public static readonly string EmbedViewSourceTemplate = "--embed-view-sources"; - - public CommandArgument ProjectArgument { get; private set; } - - public CommandOption ConfigureCompilationType { get; private set; } - - public CommandOption ContentRootOption { get; private set; } - - public CommandOption EmbedViewSourcesOption { get; private set; } - - public void Configure(CommandLineApplication app) - { - ProjectArgument = app.Argument( - "project", - "The path to the project (project folder or project.json) with precompilation."); - - ConfigureCompilationType = app.Option( - ConfigureCompilationTypeTemplate, - "Type with Configure method", - CommandOptionType.SingleValue); - - ContentRootOption = app.Option( - ContentRootTemplate, - "The application's content root.", - CommandOptionType.SingleValue); - - EmbedViewSourcesOption = app.Option( - EmbedViewSourceTemplate, - "Embed view sources as resources in the generated assembly.", - CommandOptionType.NoValue); - } - } -} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs new file mode 100644 index 0000000000..6f65d64421 --- /dev/null +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/CompilationOptions.cs @@ -0,0 +1,94 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Microsoft.Extensions.CommandLineUtils; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal +{ + public class CompilationOptions + { + public static readonly string ConfigureCompilationTypeTemplate = "--configure-compilation-type"; + public static readonly string ContentRootTemplate = "--content-root"; + public static readonly string EmbedViewSourceTemplate = "--embed-view-sources"; + public static readonly string StrongNameKeyPath = "--key-file"; + public static readonly string DelaySignTemplate = "--delay-sign"; + public static readonly string PublicSignTemplate = "--public-sign"; + public static readonly string ApplicationNameTemplate = "--application-name"; + public static readonly string OutputPathTemplate = "--output-path"; + + public CompilationOptions(CommandLineApplication 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); + + ProjectArgument = app.Argument( + "project", + "The path to the project (project folder or project.json) with precompilation."); + + ConfigureCompilationType = app.Option( + ConfigureCompilationTypeTemplate, + "Type with Configure method", + CommandOptionType.SingleValue); + + ContentRootOption = app.Option( + ContentRootTemplate, + "The application's content root.", + CommandOptionType.SingleValue); + + EmbedViewSourcesOption = app.Option( + EmbedViewSourceTemplate, + "Embed view sources as resources in the generated assembly.", + CommandOptionType.NoValue); + + KeyFileOption = app.Option( + StrongNameKeyPath, + "Strong name key path", + CommandOptionType.SingleValue); + + DelaySignOption = app.Option( + DelaySignTemplate, + "Determines if the precompiled view assembly is to be delay signed.", + CommandOptionType.NoValue); + + PublicSignOption = app.Option( + PublicSignTemplate, + "Determines if the precompiled view assembly is to be public signed.", + CommandOptionType.NoValue); + } + + public CommandArgument ProjectArgument { get; } + + public CommandOption ConfigureCompilationType { get; } + + public CommandOption ContentRootOption { get; } + + public CommandOption EmbedViewSourcesOption { get; } + + public CommandOption KeyFileOption { get; } + + public CommandOption DelaySignOption { get; } + + public CommandOption PublicSignOption { get; } + + public CommandOption OutputPathOption { get; } + + public CommandOption ApplicationNameOption { get; } + + public string OutputPath => OutputPathOption.Value(); + + public string ApplicationName => ApplicationNameOption.Value(); + + public string KeyFile => KeyFileOption.Value(); + + public bool DelaySign => DelaySignOption.HasValue(); + + public bool PublicSign => PublicSignOption.HasValue(); + } +} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs index 91c6f8ef81..2d494eafe5 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; @@ -23,8 +22,6 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { public class PrecompileRunCommand { - public static readonly string ApplicationNameTemplate = "--application-name"; - public static readonly string OutputPathTemplate = "--output-path"; private static readonly ParallelOptions ParalellOptions = new ParallelOptions { MaxDegreeOfParallelism = 4 @@ -32,33 +29,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal private CommandLineApplication Application { get; set; } - private CommandOption OutputPathOption { get; set; } - - private CommandOption ApplicationNameOption { get; set; } - private MvcServiceProvider MvcServiceProvider { get; set; } - private CommonOptions Options { get; } = new CommonOptions(); - - private StrongNameOptions StrongNameOptions { get; } = new StrongNameOptions(); + private CompilationOptions Options { get; set; } private string ProjectPath { get; set; } 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); + Options = new CompilationOptions(app); app.OnExecute(() => Execute()); } @@ -72,7 +52,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal MvcServiceProvider = new MvcServiceProvider( ProjectPath, - ApplicationNameOption.Value(), + Options.ApplicationNameOption.Value(), Options.ContentRootOption.Value(), Options.ConfigureCompilationType.Value()); @@ -95,11 +75,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal return 1; } - var precompileAssemblyName = $"{ApplicationNameOption.Value()}{ViewsFeatureProvider.PrecompiledViewsAssemblySuffix}"; + var precompileAssemblyName = $"{Options.ApplicationName}{ViewsFeatureProvider.PrecompiledViewsAssemblySuffix}"; var compilation = CompileViews(results, precompileAssemblyName); var resources = GetResources(results); - var assemblyPath = Path.Combine(OutputPathOption.Value(), precompileAssemblyName + ".dll"); + var assemblyPath = Path.Combine(Options.OutputPath, precompileAssemblyName + ".dll"); var emitResult = EmitAssembly( compilation, MvcServiceProvider.Compiler.EmitOptions, @@ -212,9 +192,9 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal var codeGenerator = new ViewInfoContainerCodeGenerator(compiler, compilation); codeGenerator.AddViewFactory(results); - var assemblyName = new AssemblyName(ApplicationNameOption.Value()); + var assemblyName = new AssemblyName(Options.ApplicationName); assemblyName = Assembly.Load(assemblyName).GetName(); - codeGenerator.AddAssemblyMetadata(assemblyName, StrongNameOptions); + codeGenerator.AddAssemblyMetadata(assemblyName, Options); return codeGenerator.Compilation; } @@ -228,21 +208,21 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal return false; } - if (!OutputPathOption.HasValue()) + if (!Options.OutputPathOption.HasValue()) { - Application.Error.WriteLine($"Option {OutputPathTemplate} does not specify a value."); + Application.Error.WriteLine($"Option {CompilationOptions.OutputPathTemplate} does not specify a value."); return false; } - if (!ApplicationNameOption.HasValue()) + if (!Options.ApplicationNameOption.HasValue()) { - Application.Error.WriteLine($"Option {ApplicationNameTemplate} does not specify a value."); + Application.Error.WriteLine($"Option {CompilationOptions.ApplicationNameTemplate} does not specify a value."); return false; } if (!Options.ContentRootOption.HasValue()) { - Application.Error.WriteLine($"Option {CommonOptions.ContentRootTemplate} does not specify a value."); + Application.Error.WriteLine($"Option {CompilationOptions.ContentRootTemplate} does not specify a value."); return false; } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/StrongNameOptions.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/StrongNameOptions.cs deleted file mode 100644 index d22580bc1e..0000000000 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/StrongNameOptions.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.CommandLineUtils; - -namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal -{ - public class StrongNameOptions - { - public static readonly string StrongNameKeyPath = "--key-file"; - public static readonly string DelaySignTemplate = "--delay-sign"; - public static readonly string PublicSignTemplate = "--public-sign"; - - public CommandOption KeyFileOption { get; set; } - - public CommandOption DelaySignOption { get; private set; } - - public CommandOption PublicSignOption { get; private set; } - - public void Configure(CommandLineApplication app) - { - KeyFileOption = app.Option( - StrongNameKeyPath, - "Strong name key path", - CommandOptionType.SingleValue); - - DelaySignOption = app.Option( - DelaySignTemplate, - "Determines if the precompiled view assembly is to be delay signed.", - CommandOptionType.NoValue); - - PublicSignOption = app.Option( - PublicSignTemplate, - "Determines if the precompiled view assembly is to be public signed.", - CommandOptionType.NoValue); - } - - public string KeyFile => KeyFileOption.Value(); - - public bool DelaySign => DelaySignOption.HasValue(); - - public bool PublicSign => PublicSignOption.HasValue(); - } -} diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs index 4c02f27d0a..397f2c038e 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs @@ -58,14 +58,14 @@ namespace {ViewsFeatureProvider.ViewInfoContainerNamespace} public void AddAssemblyMetadata( AssemblyName applicationAssemblyName, - StrongNameOptions strongNameOptions) + CompilationOptions compilationOptions) { - if (!string.IsNullOrEmpty(strongNameOptions.KeyFile)) + if (!string.IsNullOrEmpty(compilationOptions.KeyFile)) { var updatedOptions = Compilation.Options.WithStrongNameProvider(new DesktopStrongNameProvider()); - var keyFilePath = Path.GetFullPath(strongNameOptions.KeyFile); + var keyFilePath = Path.GetFullPath(compilationOptions.KeyFile); - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || strongNameOptions.PublicSign) + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || compilationOptions.PublicSign) { updatedOptions = updatedOptions.WithCryptoPublicKey( SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFilePath))); @@ -73,7 +73,7 @@ namespace {ViewsFeatureProvider.ViewInfoContainerNamespace} else { updatedOptions = updatedOptions.WithCryptoKeyFile(keyFilePath) - .WithDelaySign(strongNameOptions.DelaySign); + .WithDelaySign(compilationOptions.DelaySign); } Compilation = Compilation.WithOptions(updatedOptions);