public override bool Execute() { var log = new MSBuildLogger(Log); // Log inputs log.LogDebug($"(in) RestoreGraphItems Count '{RestoreGraphItems?.Count() ?? 0}'"); log.LogDebug($"(in) RestoreSources '{RestoreSources}'"); log.LogDebug($"(in) RestorePackagesPath '{RestorePackagesPath}'"); log.LogDebug($"(in) RestoreFallbackFolders '{RestoreFallbackFolders}'"); log.LogDebug($"(in) RestoreDisableParallel '{RestoreDisableParallel}'"); log.LogDebug($"(in) RestoreConfigFile '{RestoreConfigFile}'"); log.LogDebug($"(in) RestoreNoCache '{RestoreNoCache}'"); log.LogDebug($"(in) RestoreIgnoreFailedSources '{RestoreIgnoreFailedSources}'"); log.LogDebug($"(in) RestoreRecursive '{RestoreRecursive}'"); log.LogDebug($"(in) RestoreForce '{RestoreForce}'"); log.LogDebug($"(in) HideWarningsAndErrors '{HideWarningsAndErrors}'"); try { return(ExecuteAsync(log).Result); } catch (AggregateException ex) when(_cts.Token.IsCancellationRequested && ex.InnerException is TaskCanceledException) { // Canceled by user log.LogError(Strings.RestoreCanceled); return(false); } catch (Exception e) { ExceptionUtilities.LogException(e, log); return(false); } }
public override bool Execute() { var log = new MSBuildLogger(Log); BuildTasksUtility.LogInputParam(log, nameof(CurrentProjectTargetFramework), CurrentProjectTargetFramework); BuildTasksUtility.LogInputParam(log, nameof(AnnotatedProjectReferences), AnnotatedProjectReferences == null ? "" : string.Join(";", AnnotatedProjectReferences.Select(p => p.ItemSpec))); if (AnnotatedProjectReferences == null) { return(!Log.HasLoggedErrors); } var frameworkToMatch = NuGetFramework.Parse(CurrentProjectTargetFramework); if (frameworkToMatch.IsUnsupported) { log.LogError(string.Format(Strings.UnsupportedTargetFramework, CurrentProjectTargetFramework)); return(false); } AssignedProjects = new ITaskItem[AnnotatedProjectReferences.Length]; for (var index = 0; index < AnnotatedProjectReferences.Length; index++) { AssignedProjects[index] = AssignPropertiesForSingleReference(AnnotatedProjectReferences[index], frameworkToMatch); } BuildTasksUtility.LogOutputParam(log, nameof(AssignedProjects), string.Join(";", AssignedProjects.Select(p => p.ItemSpec))); return(!Log.HasLoggedErrors); }
public override bool Execute() { #if DEBUG var debugRestoreTask = Environment.GetEnvironmentVariable("DEBUG_RESTORE_TASK"); if (!string.IsNullOrEmpty(debugRestoreTask) && debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { #if IS_CORECLR Console.WriteLine("Waiting for debugger to attach."); Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}"); while (!Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } Debugger.Break(); #else Debugger.Launch(); #endif } #endif var log = new MSBuildLogger(Log); // Log inputs log.LogDebug($"(in) RestoreGraphItems Count '{RestoreGraphItems?.Count() ?? 0}'"); log.LogDebug($"(in) RestoreDisableParallel '{RestoreDisableParallel}'"); log.LogDebug($"(in) RestoreNoCache '{RestoreNoCache}'"); log.LogDebug($"(in) RestoreIgnoreFailedSources '{RestoreIgnoreFailedSources}'"); log.LogDebug($"(in) RestoreRecursive '{RestoreRecursive}'"); log.LogDebug($"(in) RestoreForce '{RestoreForce}'"); log.LogDebug($"(in) HideWarningsAndErrors '{HideWarningsAndErrors}'"); log.LogDebug($"(in) RestoreForceEvaluate '{RestoreForceEvaluate}'"); try { DefaultCredentialServiceUtility.SetupDefaultCredentialService(log, !Interactive); return(ExecuteAsync(log).Result); } catch (AggregateException ex) when(_cts.Token.IsCancellationRequested && ex.InnerException is TaskCanceledException) { // Canceled by user log.LogError(Strings.RestoreCanceled); return(false); } catch (Exception e) { ExceptionUtilities.LogException(e, log); return(false); } finally { // The CredentialService lifetime is for the duration of the process. We should not leave a potentially unavailable logger. // We need to update the delegating logger with a null instance // because the tear downs of the plugins and similar rely on idleness and process exit. DefaultCredentialServiceUtility.UpdateCredentialServiceDelegatingLogger(NullLogger.Instance); } }
private ITaskItem AssignNearestFrameworkForSingleReference( ITaskItem project, NuGetFramework projectNuGetFramework, IList <NuGetFramework> fallbackNuGetFrameworks, MSBuildLogger logger) { var itemWithProperties = new TaskItem(project); var referencedProjectFrameworkString = project.GetMetadata(TARGET_FRAMEWORKS); var referencedProjectFile = project.GetMetadata(MSBUILD_SOURCE_PROJECT_FILE); if (string.IsNullOrEmpty(referencedProjectFrameworkString)) { // No target frameworks set, nothing to do. return(itemWithProperties); } var referencedProjectFrameworks = MSBuildStringUtility.Split(referencedProjectFrameworkString); // try project framework var nearestNuGetFramework = NuGetFrameworkUtility.GetNearest(referencedProjectFrameworks, projectNuGetFramework, NuGetFramework.Parse); if (nearestNuGetFramework != null) { itemWithProperties.SetMetadata(NEAREST_TARGET_FRAMEWORK, nearestNuGetFramework); return(itemWithProperties); } // try project fallback frameworks foreach (var currentProjectTargetFramework in fallbackNuGetFrameworks) { nearestNuGetFramework = NuGetFrameworkUtility.GetNearest(referencedProjectFrameworks, currentProjectTargetFramework, NuGetFramework.Parse); if (nearestNuGetFramework != null) { var message = string.Format(CultureInfo.CurrentCulture, Strings.ImportsFallbackWarning, referencedProjectFile, currentProjectTargetFramework.DotNetFrameworkName, projectNuGetFramework.DotNetFrameworkName); var warning = RestoreLogMessage.CreateWarning(NuGetLogCode.NU1702, message); warning.LibraryId = referencedProjectFile; warning.ProjectPath = CurrentProjectName; // log NU1702 for ATF on project reference logger.Log(warning); itemWithProperties.SetMetadata(NEAREST_TARGET_FRAMEWORK, nearestNuGetFramework); return(itemWithProperties); } } // no match found logger.LogError(string.Format(Strings.NoCompatibleTargetFramework, project.ItemSpec, CurrentProjectTargetFramework, referencedProjectFrameworkString)); return(itemWithProperties); }
private static bool TryParseFramework(string framework, string errorMessage, MSBuildLogger logger, out NuGetFramework nugetFramework) { nugetFramework = NuGetFramework.Parse(framework); // validate framework if (nugetFramework.IsUnsupported) { logger.LogError(errorMessage); return(false); } return(true); }
private static bool TryParseAndAddFrameworkToList(string framework, IList <NuGetFramework> frameworkList, string errorMessage, MSBuildLogger logger) { var nugetFramework = NuGetFramework.Parse(framework); // validate framework if (nugetFramework.IsUnsupported) { logger.LogError(errorMessage); return(false); } frameworkList.Add(nugetFramework); return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); // Log inputs log.LogDebug($"(in) RestoreGraphItems Count '{RestoreGraphItems?.Count() ?? 0}'"); log.LogDebug($"(in) RestoreSources '{RestoreSources}'"); log.LogDebug($"(in) RestorePackagesPath '{RestorePackagesPath}'"); log.LogDebug($"(in) RestoreFallbackFolders '{RestoreFallbackFolders}'"); log.LogDebug($"(in) RestoreDisableParallel '{RestoreDisableParallel}'"); log.LogDebug($"(in) RestoreConfigFile '{RestoreConfigFile}'"); log.LogDebug($"(in) RestoreNoCache '{RestoreNoCache}'"); log.LogDebug($"(in) RestoreIgnoreFailedSources '{RestoreIgnoreFailedSources}'"); log.LogDebug($"(in) RestoreRecursive '{RestoreRecursive}'"); try { return(ExecuteAsync(log).Result); } catch (Exception e) { // Log the error if (ExceptionLogger.Instance.ShowStack) { log.LogError(e.ToString()); } else { log.LogError(ExceptionUtilities.DisplayMessage(e)); } // Log the stack trace as verbose output. log.LogVerbose(e.ToString()); return(false); } }
public override bool Execute() { #if DEBUG var debugRestoreTask = Environment.GetEnvironmentVariable("DEBUG_RESTORE_TASK"); if (!string.IsNullOrEmpty(debugRestoreTask) && debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { #if IS_CORECLR Console.WriteLine("Waiting for debugger to attach."); Console.WriteLine($"Process ID: {Process.GetCurrentProcess().Id}"); while (!Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } Debugger.Break(); #else Debugger.Launch(); #endif } #endif var log = new MSBuildLogger(Log); // Log inputs log.LogDebug($"(in) RestoreGraphItems Count '{RestoreGraphItems?.Count() ?? 0}'"); log.LogDebug($"(in) RestoreDisableParallel '{RestoreDisableParallel}'"); log.LogDebug($"(in) RestoreNoCache '{RestoreNoCache}'"); log.LogDebug($"(in) RestoreIgnoreFailedSources '{RestoreIgnoreFailedSources}'"); log.LogDebug($"(in) RestoreRecursive '{RestoreRecursive}'"); log.LogDebug($"(in) RestoreForce '{RestoreForce}'"); log.LogDebug($"(in) HideWarningsAndErrors '{HideWarningsAndErrors}'"); log.LogDebug($"(in) RestoreForceEvaluate '{RestoreForceEvaluate}'"); log.LogDebug($"(in) RestorePackagesConfig '{RestorePackagesConfig}'"); try { return(ExecuteAsync(log).Result); } catch (AggregateException ex) when(_cts.Token.IsCancellationRequested && ex.InnerException is TaskCanceledException) { // Canceled by user log.LogError(Strings.RestoreCanceled); return(false); } catch (Exception e) { ExceptionUtilities.LogException(e, log); return(false); } }
private static bool TryParseFramework(string targetFrameworkMoniker, string targetPlatformMoniker, string errorMessage, MSBuildLogger logger, out NuGetFramework nugetFramework) { // Check if we have a long name. nugetFramework = targetFrameworkMoniker.Contains(',') ? NuGetFramework.ParseComponents(targetFrameworkMoniker, targetPlatformMoniker) : NuGetFramework.Parse(targetFrameworkMoniker); // validate framework if (nugetFramework.IsUnsupported) { logger.LogError(errorMessage); return(false); } return(true); }
private ITaskItem AssignNearestFrameworkForSingleReference( ITaskItem project, NuGetFramework projectNuGetFramework, IList <NuGetFramework> fallbackNuGetFrameworks, MSBuildLogger logger) { var itemWithProperties = new TaskItem(project); var referencedProjectFrameworkString = project.GetMetadata(TARGET_FRAMEWORKS); var referenceTargetFrameworkMonikers = project.GetMetadata(TARGET_FRAMEWORK_MONIKERS); var referencedProjectPlatformString = project.GetMetadata(TARGET_PLATFORM_MONIKERS); var referencedProjectFile = project.GetMetadata(MSBUILD_SOURCE_PROJECT_FILE); if (string.IsNullOrEmpty(referencedProjectFrameworkString)) { // No target frameworks set, nothing to do. return(itemWithProperties); } var referencedProjectFrameworks = MSBuildStringUtility.Split(referencedProjectFrameworkString); var referencedProjectTargetFrameworkMonikers = MSBuildStringUtility.Split(referenceTargetFrameworkMonikers); var referencedProjectTargetPlatformMonikers = MSBuildStringUtility.Split(referencedProjectPlatformString); if (referencedProjectTargetFrameworkMonikers.Length > 0 && (referencedProjectTargetFrameworkMonikers.Length != referencedProjectTargetPlatformMonikers.Length || referencedProjectTargetFrameworkMonikers.Length != referencedProjectFrameworks.Length)) { logger.LogError($"Internal error for {CurrentProjectName}." + $" Expected {TARGET_FRAMEWORKS}:{referencedProjectFrameworks}, " + $"{TARGET_FRAMEWORK_MONIKERS}:{referenceTargetFrameworkMonikers}, " + $"{TARGET_PLATFORM_MONIKERS}:{referencedProjectPlatformString} to have the same number of elements."); return(itemWithProperties); } // TargetFrameworks, TargetFrameworkMoniker, TargetPlatforMoniker var targetFrameworkInformations = new List <TargetFrameworkInformation>(); var useTargetMonikers = referencedProjectTargetFrameworkMonikers.Length > 0; for (int i = 0; i < referencedProjectFrameworks.Length; i++) { targetFrameworkInformations.Add(new TargetFrameworkInformation( referencedProjectFrameworks[i], useTargetMonikers ? referencedProjectTargetFrameworkMonikers[i] : null, useTargetMonikers ? referencedProjectTargetPlatformMonikers[i] : null)); } // try project framework var nearestNuGetFramework = NuGetFrameworkUtility.GetNearest(targetFrameworkInformations, projectNuGetFramework, GetNuGetFramework); if (nearestNuGetFramework != null) { itemWithProperties.SetMetadata(NEAREST_TARGET_FRAMEWORK, nearestNuGetFramework._targetFrameworkAlias); return(itemWithProperties); } // try project fallback frameworks foreach (var currentProjectTargetFramework in fallbackNuGetFrameworks) { nearestNuGetFramework = NuGetFrameworkUtility.GetNearest(targetFrameworkInformations, currentProjectTargetFramework, GetNuGetFramework); if (nearestNuGetFramework != null) { var message = string.Format(CultureInfo.CurrentCulture, Strings.ImportsFallbackWarning, referencedProjectFile, currentProjectTargetFramework.DotNetFrameworkName, projectNuGetFramework.DotNetFrameworkName); var warning = RestoreLogMessage.CreateWarning(NuGetLogCode.NU1702, message); warning.LibraryId = referencedProjectFile; warning.ProjectPath = CurrentProjectName; // log NU1702 for ATF on project reference logger.Log(warning); itemWithProperties.SetMetadata(NEAREST_TARGET_FRAMEWORK, nearestNuGetFramework._targetFrameworkAlias); return(itemWithProperties); } } // no match found logger.LogError(string.Format(CultureInfo.CurrentCulture, Strings.NoCompatibleTargetFramework, project.ItemSpec, projectNuGetFramework.DotNetFrameworkName, referencedProjectFrameworkString)); return(itemWithProperties); }