/// <summary> /// Steps of execution /// 1. Try getting the projectContext for the project /// 2. Invoke project dependency command with the first compatible tfm found in the project /// </summary> internal int Execute(string[] args, bool isNoBuild) { var app = new ScaffoldingApp(false); bool isShowHelp = false; app.OnExecute(() => { try { string project = app.ProjectPath.Value(); if (string.IsNullOrEmpty(project)) { project = Directory.GetCurrentDirectory(); } project = Path.GetFullPath(project); var configuration = app.AppConfiguration.Value() ?? "Debug"; isShowHelp = ToolCommandLineHelper.IsHelpArgument(args) || app.GeneratorArgument == null || string.IsNullOrEmpty(app.GeneratorArgument.Value); ProjectFileFinder projectFileFinder = new ProjectFileFinder(project); if (isShowHelp) { app.ProjectContext = GetProjectInformation(projectFileFinder.ProjectFilePath, configuration); app.ShowHelp(); return(0); } // Invoke the tool from the project's build directory. return(BuildAndDispatchDependencyCommand( args, projectFileFinder.ProjectFilePath, app.BuildBasePath.Value(), configuration, isNoBuild, Logger)); } catch (Exception ex) { Logger.LogMessage(Resources.GenericErrorMessage, LogMessageLevel.Error); Logger.LogMessage(ex.Message, LogMessageLevel.Error); if (isShowHelp) { app.ShowHelp(); } Logger.LogMessage(ex.StackTrace, LogMessageLevel.Trace); if (Logger is ConsoleLogger consoleLogger && !consoleLogger.IsTracing) { Logger.LogMessage(Resources.EnableTracingMessage); } return(-1); } }); return(app.Execute(args)); }
private IProjectContext GetProjectInformation(string projectPath, string configuration) { var projectFileFinder = new ProjectFileFinder(projectPath); if (projectFileFinder.IsMsBuildProject) { if (!SkipImportTarget) { // First install the target to obj folder so that it imports the one in the tools package. // Here we are taking an assumption that the 'obj' folder is the right place to put the project extension target. // This may not always be true if the user's settings override the default in the csproj. // However, currently restoring the project always creates the obj folder irrespective of the user's settings. new TargetInstaller(_logger) .EnsureTargetImported( Path.GetFileName(projectFileFinder.ProjectFilePath), Path.Combine(Path.GetDirectoryName(projectFileFinder.ProjectFilePath), "obj")); } return(new MsBuildProjectContextBuilder(projectFileFinder.ProjectFilePath, CodeGenerationTargetsLocation, configuration) .Build()); } throw new InvalidOperationException(string.Format(Resources.InvalidMsBuildProjectFile, projectFileFinder.ProjectFilePath)); }
/// <summary> /// Steps of execution /// 1. Try getting the projectContext for the project /// 2. Invoke project dependency command with the first compatible tfm found in the project /// </summary> private static void Execute(string[] args, bool isNoBuild, ILogger logger) { var app = new ScaffoldingApp(false); app.OnExecute(() => { string project = app.ProjectPath.Value(); if (string.IsNullOrEmpty(project)) { project = Directory.GetCurrentDirectory(); } project = Path.GetFullPath(project); var configuration = app.AppConfiguration.Value() ?? "Debug"; var projectFileFinder = new ProjectFileFinder(project); if (ToolCommandLineHelper.IsHelpArgument(args)) { app.ProjectContext = GetProjectInformation(projectFileFinder.ProjectFilePath, configuration); app.ShowHelp(); return(0); } // Invoke the tool from the project's build directory. return(BuildAndDispatchDependencyCommand( args, projectFileFinder.ProjectFilePath, app.BuildBasePath.Value(), configuration, isNoBuild, logger)); }); app.Execute(args); }