private bool ParseArguments() { ProjectPath = Options.ProjectArgument.Value; if (string.IsNullOrEmpty(ProjectPath)) { Application.Error.WriteLine("Project path not specified."); return(false); } if (!OutputPathOption.HasValue()) { Application.Error.WriteLine($"Option {OutputPathTemplate} does not specify a value."); return(false); } if (!ApplicationNameOption.HasValue()) { Application.Error.WriteLine($"Option {ApplicationNameTemplate} does not specify a value."); return(false); } if (!Options.ContentRootOption.HasValue()) { Application.Error.WriteLine($"Option {CommonOptions.ContentRootTemplate} does not specify a value."); return(false); } return(true); }
private int Execute() { if (!ParseArguments()) { return(1); } MvcServiceProvider = new MvcServiceProvider( ProjectPath, ApplicationNameOption.Value(), Options.ContentRootOption.Value(), Options.ConfigureCompilationType.Value()); Application.Out.WriteLine("Running Razor view precompilation."); var stopWatch = Stopwatch.StartNew(); var results = GenerateCode(); var success = true; foreach (var result in results) { if (!result.GeneratorResults.Success) { success = false; foreach (var error in result.GeneratorResults.ParserErrors) { Application.Error.WriteLine($"{error.Location.FilePath} ({error.Location.LineIndex}): {error.Message}"); } } } if (!success) { return(1); } var precompileAssemblyName = $"{ApplicationNameOption.Value()}{ViewsFeatureProvider.PrecompiledViewsAssemblySuffix}"; var compilation = CompileViews(results, precompileAssemblyName); var resources = GetResources(results); var assemblyPath = Path.Combine(OutputPathOption.Value(), precompileAssemblyName + ".dll"); var emitResult = EmitAssembly(compilation, assemblyPath, resources); if (!emitResult.Success) { foreach (var diagnostic in emitResult.Diagnostics) { Application.Error.WriteLine(CSharpDiagnosticFormatter.Instance.Format(diagnostic)); } return(1); } stopWatch.Stop(); Application.Out.WriteLine($"Precompiled views emitted to {assemblyPath}."); Application.Out.WriteLine($"Successfully compiled {results.Length} Razor views in {stopWatch.ElapsedMilliseconds}ms."); return(0); }
private void ParseArguments() { ProjectPath = GetProjectPath(); Configuration = ConfigurationOption.Value() ?? DotNet.Cli.Utils.Constants.DefaultConfiguration; if (!FrameworkOption.HasValue()) { throw new Exception($"Option {FrameworkOption.Template} does not have a value."); } TargetFramework = NuGetFramework.Parse(FrameworkOption.Value()); if (!OutputPathOption.HasValue()) { throw new Exception($"Option {OutputPathOption.Template} does not have a value."); } OutputPath = OutputPathOption.Value(); }
private void ParseArguments() { ProjectPath = Options.ProjectArgument.Value; if (string.IsNullOrEmpty(ProjectPath)) { throw new ArgumentException("Project path not specified."); } if (!OutputPathOption.HasValue()) { throw new ArgumentException($"Option {OutputPathTemplate} does not specify a value."); } if (!ApplicationNameOption.HasValue()) { throw new ArgumentException($"Option {ApplicationNameTemplate} does not specify a value."); } }
private bool ParseArguments() { ProjectPath = GetProjectPath(Options.ProjectArgument.Value); Configuration = ConfigurationOption.Value() ?? DotNet.Cli.Utils.Constants.DefaultConfiguration; if (FrameworkOption.HasValue()) { TargetFramework = NuGetFramework.Parse(FrameworkOption.Value()); } if (!OutputPathOption.HasValue()) { Application.Error.WriteLine($"Option {OutputPathOption.Template} does not have a value."); return(false); } OutputPath = OutputPathOption.Value(); return(true); }