/// <summary> /// Deletes packages from known nuget cache location /// </summary> /// <returns></returns> public override bool Execute() { base.Execute(); if (WhatIf) { WhatIfAction(); } else { packagesToBeCleaned?.AddRange(PackageReferences); TaskLogger.LogInfo(MessageImportance.Low, packagesToBeCleaned, "Pacakges to be deleted...."); List <string> localCacheLocations = new NugetExec().GetRestoreCacheLocation(); if (RestoreCacheLocations != null) { localCacheLocations.AddRange(RestoreCacheLocations); } if (!string.IsNullOrEmpty(PackageDirSearchPattern)) { packagesToBeCleaned.Add(PackageDirSearchPattern); } if (localCacheLocations.Any <string>()) { Task[] delTsks = new Task[localCacheLocations.Count]; int tskCount = 0; localCacheLocations.ForEach((cl) => { //TaskLogger.LogDebugInfo("Checking {0}", cl); delTsks[tskCount] = Task.Run(async() => await CleanRestoredPackagesAsync(cl)); tskCount++; }); Task.WaitAll(delTsks); TaskLogger.LogInfo("Cleaning of Packages completed....."); } //DeleteNupkgOutputDir(); } return(TaskLogger.TaskSucceededWithNoErrorsLogged); }