public static async Task <bool> ExecuteScriptAsync(PackageIdentity identity, string packageInstallPath, INuGetProjectContext projectContext, IScriptExecutor scriptExecutor, EnvDTEProject envDTEProject, bool throwOnFailure) { if (scriptExecutor != null) { var packageReader = new PackageFolderReader(packageInstallPath); var toolItemGroups = packageReader.GetToolItems(); if (toolItemGroups != null) { // Init.ps1 must be found at the root folder, target frameworks are not recognized here, // since this is run for the solution. var toolItemGroup = toolItemGroups .Where(group => group.TargetFramework.IsAny) .FirstOrDefault(); if (toolItemGroup != null) { var initPS1RelativePath = toolItemGroup.Items .FirstOrDefault(p => p.StartsWith( PowerShellScripts.InitPS1RelativePath, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrEmpty(initPS1RelativePath)) { initPS1RelativePath = PathUtility .ReplaceAltDirSeparatorWithDirSeparator(initPS1RelativePath); return(await scriptExecutor.ExecuteAsync( identity, packageInstallPath, initPS1RelativePath, envDTEProject, projectContext, throwOnFailure)); } } } } return(false); }
private async Task ApplyScriptsAsync(IDictionary <BuildItem, List <BuildItem> > scriptsToDependencies, IScriptExecutor executor, Func <BuildItem, IEnumerable <BuildItem> > referencerFunc, Func <BuildItem, bool> eligibilityFunc, Action <BuildItem> successAction, Action <BuildItem, Exception> failureAction) { // Execute script files that don't have any dependencies and remove them from the queue. // Continue doing this until all scripts have executed. var eligibleScripts = scriptsToDependencies.Where(x => !x.Value.Any() && eligibilityFunc(x.Key)).ToList(); while (eligibleScripts.Any()) { foreach (var s in eligibleScripts) { try { await _logger.LogMessageAsync(s.Key.BuildAction + ": " + s.Key.DatabaseObject, SeverityLevel.Verbose); // Run script await executor.ExecuteAsync(s.Key.Script, s.Key.BuildAction); // Remove this script from all other scripts' dependencies //foreach (var r in s.Key.Referencers) foreach (var r in referencerFunc(s.Key).Where(scriptsToDependencies.ContainsKey)) { scriptsToDependencies[r].Remove(s.Key); } // Set status successAction(s.Key); } catch (Exception ex) { failureAction(s.Key, ex); } // Remove this script from the queue scriptsToDependencies.Remove(s.Key); } eligibleScripts = scriptsToDependencies.Where(x => !x.Value.Any() && eligibilityFunc(x.Key)).ToList(); } foreach (var s in scriptsToDependencies.Keys.Where(eligibilityFunc)) { s.ReportError(new CircularDependencyError(s, scriptsToDependencies)); } }
private async Task ApplyScriptsAsync(IDictionary<BuildItem, List<BuildItem>> scriptsToDependencies, IScriptExecutor executor, Func<BuildItem, IEnumerable<BuildItem>> referencerFunc, Func<BuildItem, bool> eligibilityFunc, Action<BuildItem> successAction, Action<BuildItem, Exception> failureAction) { // Execute script files that don't have any dependencies and remove them from the queue. // Continue doing this until all scripts have executed. var eligibleScripts = scriptsToDependencies.Where(x => !x.Value.Any() && eligibilityFunc(x.Key)).ToList(); while (eligibleScripts.Any()) { foreach (var s in eligibleScripts) { try { // Run script await executor.ExecuteAsync(s.Key.Script, s.Key.BuildAction); // Remove this script from all other scripts' dependencies //foreach (var r in s.Key.Referencers) foreach (var r in referencerFunc(s.Key).Where(scriptsToDependencies.ContainsKey)) { scriptsToDependencies[r].Remove(s.Key); } // Set status successAction(s.Key); } catch (Exception ex) { failureAction(s.Key, ex); } // Remove this script from the queue scriptsToDependencies.Remove(s.Key); } eligibleScripts = scriptsToDependencies.Where(x => !x.Value.Any() && eligibilityFunc(x.Key)).ToList(); } foreach (var s in scriptsToDependencies.Keys.Where(eligibilityFunc)) { s.ReportError(new CircularDependencyError(s, scriptsToDependencies)); } }
async Task ExecuteInitPs1Async( string installPath, PackageIdentity identity, INuGetProjectContext context, CancellationToken token) { try { var toolsPath = Path.Combine(installPath, "tools"); if (Directory.Exists(toolsPath)) { //AddPathToEnvironment (toolsPath); var relativePath = Path.Combine("tools", PowerShellScripts.Init); if (!scriptHasRun) { // Make sure first messages from running script are not on PowerShell prompt line. scriptHasRun = true; context.Log(MessageLevel.Info, "\n"); } await scriptExecutor.ExecuteAsync( identity, installPath, relativePath, null, context, false, token); return; } scriptExecutor.TryMarkVisited(identity, PackageInitPS1State.NotFound); } catch (Exception ex) { LoggingService.LogError("ExecuteInitPs1Async error", ex); } }