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() { var logger = new MSBuildLogger(Log); BuildTasksUtility.LogInputParam(logger, nameof(CurrentProjectTargetFramework), CurrentProjectTargetFramework); BuildTasksUtility.LogInputParam(logger, nameof(FallbackTargetFrameworks), FallbackTargetFrameworks == null ? "" : string.Join(";", FallbackTargetFrameworks.Select(p => p))); BuildTasksUtility.LogInputParam(logger, nameof(AnnotatedProjectReferences), AnnotatedProjectReferences == null ? "" : string.Join(";", AnnotatedProjectReferences.Select(p => p.ItemSpec))); if (AnnotatedProjectReferences == null) { return(!Log.HasLoggedErrors); } var fallbackNuGetFrameworks = new List <NuGetFramework>(); // validate current project framework var errorMessage = string.Format(Strings.UnsupportedTargetFramework, CurrentProjectTargetFramework); if (!TryParseFramework(CurrentProjectTargetFramework, errorMessage, logger, out var projectNuGetFramework)) { return(false); } if (FallbackTargetFrameworks != null && FallbackTargetFrameworks.Length > 0) { foreach (var fallbackFramework in FallbackTargetFrameworks) { // validate ATF project frameworks errorMessage = string.Format(Strings.UnsupportedFallbackFramework, fallbackFramework); if (!TryParseFramework(fallbackFramework, errorMessage, logger, out var nugetFramework)) { return(false); } else { fallbackNuGetFrameworks.Add(nugetFramework); } } } AssignedProjects = new ITaskItem[AnnotatedProjectReferences.Length]; for (var index = 0; index < AnnotatedProjectReferences.Length; index++) { AssignedProjects[index] = AssignNearestFrameworkForSingleReference(AnnotatedProjectReferences[index], projectNuGetFramework, fallbackNuGetFrameworks, logger); } BuildTasksUtility.LogOutputParam(logger, nameof(AssignedProjects), string.Join(";", AssignedProjects.Select(p => p.ItemSpec))); return(!Log.HasLoggedErrors); }
public override bool Execute() { var log = new MSBuildLogger(Log); // item -> string var all = AllProjects?.Select(e => e.ItemSpec).ToArray() ?? Array.Empty <string>(); var valid = ValidProjects?.Select(e => e.ItemSpec).ToArray() ?? Array.Empty <string>(); // log inputs BuildTasksUtility.LogInputParam(log, nameof(AllProjects), all); BuildTasksUtility.LogInputParam(log, nameof(ValidProjects), valid); // Log warnings for invalid projects foreach (var path in all.Except(valid, PathUtility.GetStringComparerBasedOnOS())) { var message = MSBuildRestoreUtility.GetWarningForUnsupportedProject(path); log.Log(message); } return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); // Log Inputs BuildTasksUtility.LogInputParam(log, nameof(HasPackageReferenceItems), HasPackageReferenceItems.ToString()); BuildTasksUtility.LogInputParam(log, nameof(MSBuildProjectDirectory), MSBuildProjectDirectory); BuildTasksUtility.LogInputParam(log, nameof(MSBuildProjectName), MSBuildProjectName); BuildTasksUtility.LogInputParam(log, nameof(ProjectJsonPath), ProjectJsonPath); BuildTasksUtility.LogInputParam(log, nameof(RestoreProjectStyle), RestoreProjectStyle); var result = BuildTasksUtility.GetProjectRestoreStyle(RestoreProjectStyle, HasPackageReferenceItems, ProjectJsonPath, MSBuildProjectDirectory, MSBuildProjectName, log); IsPackageReferenceCompatibleProjectStyle = result.IsPackageReferenceCompatibleProjectStyle; ProjectStyle = result.ProjectStyle; // Log Outputs BuildTasksUtility.LogOutputParam(log, nameof(IsPackageReferenceCompatibleProjectStyle), IsPackageReferenceCompatibleProjectStyle.ToString()); BuildTasksUtility.LogOutputParam(log, nameof(ProjectStyle), ProjectStyle.ToString()); return(!Log.HasLoggedErrors); }
public override bool Execute() { var log = new MSBuildLogger(Log); // Log Inputs BuildTasksUtility.LogInputParam(log, nameof(ProjectUniqueName), ProjectUniqueName); BuildTasksUtility.LogInputParam(log, nameof(RestoreSources), RestoreSources); BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPath), RestorePackagesPath); BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFolders), RestoreFallbackFolders); BuildTasksUtility.LogInputParam(log, nameof(RestoreConfigFile), RestoreConfigFile); BuildTasksUtility.LogInputParam(log, nameof(RestoreSolutionDirectory), RestoreSolutionDirectory); BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPathOverride), RestorePackagesPathOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreSourcesOverride), RestoreSourcesOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFoldersOverride), RestoreFallbackFoldersOverride); BuildTasksUtility.LogInputParam(log, nameof(MSBuildStartupDirectory), MSBuildStartupDirectory); try { // Validate inputs if (RestoreSourcesOverride == null && MSBuildRestoreUtility.LogErrorForClearIfInvalid(RestoreSources, ProjectUniqueName, log)) { // Fail due to invalid source combination return(false); } if (RestoreFallbackFoldersOverride == null && MSBuildRestoreUtility.LogErrorForClearIfInvalid(RestoreFallbackFolders, ProjectUniqueName, log)) { // Fail due to invalid fallback combination return(false); } // Settings // Find the absolute path of nuget.config, this should only be set on the command line. Setting the path in project files // is something that could happen, but it is not supported. var absoluteConfigFilePath = GetGlobalAbsolutePath(RestoreConfigFile); var settings = RestoreSettingsUtils.ReadSettings(RestoreSolutionDirectory, Path.GetDirectoryName(ProjectUniqueName), absoluteConfigFilePath, _machineWideSettings); OutputConfigFilePaths = SettingsUtility.GetConfigFilePaths(settings).ToArray(); // PackagesPath OutputPackagesPath = RestoreSettingsUtils.GetValue( () => GetGlobalAbsolutePath(RestorePackagesPathOverride), () => string.IsNullOrEmpty(RestorePackagesPath) ? null : UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, RestorePackagesPath), () => SettingsUtility.GetGlobalPackagesFolder(settings)); // Sources var currentSources = RestoreSettingsUtils.GetValue( () => RestoreSourcesOverride?.Select(MSBuildRestoreUtility.FixSourcePath).Select(e => GetGlobalAbsolutePath(e)).ToArray(), () => MSBuildRestoreUtility.ContainsClearKeyword(RestoreSources) ? new string[0] : null, () => RestoreSources?.Select(MSBuildRestoreUtility.FixSourcePath).Select(e => UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, e)).ToArray(), () => (new PackageSourceProvider(settings)).LoadPackageSources().Where(e => e.IsEnabled).Select(e => e.Source).ToArray()); // Append additional sources // Escape strings to avoid xplat path issues with msbuild. var additionalProjectSources = MSBuildRestoreUtility.AggregateSources( values: GetPropertyValues(RestoreSettingsPerFramework, "RestoreAdditionalProjectSources"), excludeValues: Enumerable.Empty <string>()) .Select(MSBuildRestoreUtility.FixSourcePath) .ToArray(); OutputSources = AppendItems(currentSources, additionalProjectSources); // Fallback folders var currentFallbackFolders = RestoreSettingsUtils.GetValue( () => RestoreFallbackFoldersOverride?.Select(e => GetGlobalAbsolutePath(e)).ToArray(), () => MSBuildRestoreUtility.ContainsClearKeyword(RestoreFallbackFolders) ? new string[0] : null, () => RestoreFallbackFolders?.Select(e => UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, e)).ToArray(), () => SettingsUtility.GetFallbackPackageFolders(settings).ToArray()); // Append additional fallback folders after removing excluded folders var additionalProjectFallbackFolders = MSBuildRestoreUtility.AggregateSources( values: GetPropertyValues(RestoreSettingsPerFramework, "RestoreAdditionalProjectFallbackFolders"), excludeValues: GetPropertyValues(RestoreSettingsPerFramework, "RestoreAdditionalProjectFallbackFoldersExcludes")) .ToArray(); OutputFallbackFolders = AppendItems(currentFallbackFolders, additionalProjectFallbackFolders); } catch (Exception ex) { // Log exceptions with error codes if they exist. ExceptionUtilities.LogException(ex, log); return(false); } // Log Outputs BuildTasksUtility.LogOutputParam(log, nameof(OutputPackagesPath), OutputPackagesPath); BuildTasksUtility.LogOutputParam(log, nameof(OutputSources), OutputSources); BuildTasksUtility.LogOutputParam(log, nameof(OutputFallbackFolders), OutputFallbackFolders); BuildTasksUtility.LogOutputParam(log, nameof(OutputConfigFilePaths), OutputConfigFilePaths); return(true); }
public override bool Execute() { #if DEBUG var debugRestoreTask = Environment.GetEnvironmentVariable("DEBUG_RESTORE_SETTINGS_TASK"); if (!string.IsNullOrEmpty(debugRestoreTask) && debugRestoreTask.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase)) { System.Diagnostics.Debugger.Launch(); } #endif var log = new MSBuildLogger(Log); // Log Inputs BuildTasksUtility.LogInputParam(log, nameof(ProjectUniqueName), ProjectUniqueName); BuildTasksUtility.LogInputParam(log, nameof(RestoreSources), RestoreSources); BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPath), RestorePackagesPath); BuildTasksUtility.LogInputParam(log, nameof(RestoreRepositoryPath), RestoreRepositoryPath); BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFolders), RestoreFallbackFolders); BuildTasksUtility.LogInputParam(log, nameof(RestoreConfigFile), RestoreConfigFile); BuildTasksUtility.LogInputParam(log, nameof(RestoreSolutionDirectory), RestoreSolutionDirectory); BuildTasksUtility.LogInputParam(log, nameof(RestoreRootConfigDirectory), RestoreRootConfigDirectory); BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPathOverride), RestorePackagesPathOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreSourcesOverride), RestoreSourcesOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFoldersOverride), RestoreFallbackFoldersOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreProjectStyle), RestoreProjectStyle); BuildTasksUtility.LogInputParam(log, nameof(MSBuildStartupDirectory), MSBuildStartupDirectory); try { // Validate inputs if (RestoreSourcesOverride == null && MSBuildRestoreUtility.LogErrorForClearIfInvalid(RestoreSources, ProjectUniqueName, log)) { // Fail due to invalid source combination return(false); } if (RestoreFallbackFoldersOverride == null && MSBuildRestoreUtility.LogErrorForClearIfInvalid(RestoreFallbackFolders, ProjectUniqueName, log)) { // Fail due to invalid fallback combination return(false); } // Settings // Find the absolute path of nuget.config, this should only be set on the command line. Setting the path in project files // is something that could happen, but it is not supported. var absoluteConfigFilePath = GetGlobalAbsolutePath(RestoreConfigFile); string restoreDir; // To match non-msbuild behavior, we only default the restoreDir for non-PackagesConfig scenarios. if (string.IsNullOrEmpty(RestoreRootConfigDirectory)) { restoreDir = Path.GetDirectoryName(ProjectUniqueName); } else { restoreDir = RestoreRootConfigDirectory; } var settings = RestoreSettingsUtils.ReadSettings(RestoreSolutionDirectory, restoreDir, absoluteConfigFilePath, _machineWideSettings); OutputConfigFilePaths = settings.GetConfigFilePaths().ToArray(); // PackagesPath OutputPackagesPath = RestoreSettingsUtils.GetValue( () => GetGlobalAbsolutePath(RestorePackagesPathOverride), () => string.IsNullOrEmpty(RestorePackagesPath) ? null : UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, RestorePackagesPath), () => SettingsUtility.GetGlobalPackagesFolder(settings)); OutputRepositoryPath = RestoreSettingsUtils.GetValue( () => GetGlobalAbsolutePath(RestoreRepositoryPathOverride), () => string.IsNullOrEmpty(RestoreRepositoryPath) ? null : UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, RestoreRepositoryPath), () => SettingsUtility.GetRepositoryPath(settings)); // Sources OutputSources = BuildTasksUtility.GetSources( MSBuildStartupDirectory, Path.GetDirectoryName(ProjectUniqueName), RestoreSources, RestoreSourcesOverride, GetPropertyValues(RestoreSettingsPerFramework, "RestoreAdditionalProjectSources"), settings); // Fallback folders OutputFallbackFolders = BuildTasksUtility.GetFallbackFolders( MSBuildStartupDirectory, Path.GetDirectoryName(ProjectUniqueName), RestoreFallbackFolders, RestoreFallbackFoldersOverride, GetPropertyValues(RestoreSettingsPerFramework, "RestoreAdditionalProjectFallbackFolders"), GetPropertyValues(RestoreSettingsPerFramework, "RestoreAdditionalProjectFallbackFoldersExcludes"), settings); } catch (Exception ex) { // Log exceptions with error codes if they exist. ExceptionUtilities.LogException(ex, log); return(false); } // Log Outputs BuildTasksUtility.LogOutputParam(log, nameof(OutputPackagesPath), OutputPackagesPath); BuildTasksUtility.LogOutputParam(log, nameof(OutputRepositoryPath), OutputRepositoryPath); BuildTasksUtility.LogOutputParam(log, nameof(OutputSources), OutputSources); BuildTasksUtility.LogOutputParam(log, nameof(OutputFallbackFolders), OutputFallbackFolders); BuildTasksUtility.LogOutputParam(log, nameof(OutputConfigFilePaths), OutputConfigFilePaths); return(true); }
public override bool Execute() { var log = new MSBuildLogger(Log); // Log Inputs BuildTasksUtility.LogInputParam(log, nameof(ProjectUniqueName), ProjectUniqueName); BuildTasksUtility.LogInputParam(log, nameof(RestoreSources), RestoreSources); BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPath), RestorePackagesPath); BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFolders), RestoreFallbackFolders); BuildTasksUtility.LogInputParam(log, nameof(RestoreConfigFile), RestoreConfigFile); BuildTasksUtility.LogInputParam(log, nameof(RestoreSolutionDirectory), RestoreSolutionDirectory); BuildTasksUtility.LogInputParam(log, nameof(RestoreAdditionalProjectSources), RestoreAdditionalProjectSources); BuildTasksUtility.LogInputParam(log, nameof(RestoreAdditionalProjectFallbackFolders), RestoreAdditionalProjectFallbackFolders); BuildTasksUtility.LogInputParam(log, nameof(RestorePackagesPathOverride), RestorePackagesPathOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreSourcesOverride), RestoreSourcesOverride); BuildTasksUtility.LogInputParam(log, nameof(RestoreFallbackFoldersOverride), RestoreFallbackFoldersOverride); try { // Validate inputs if (RestoreSourcesOverride == null && MSBuildRestoreUtility.LogErrorForClearIfInvalid(RestoreSources, ProjectUniqueName, log)) { // Fail due to invalid source combination return(false); } if (RestoreFallbackFoldersOverride == null && MSBuildRestoreUtility.LogErrorForClearIfInvalid(RestoreFallbackFolders, ProjectUniqueName, log)) { // Fail due to invalid fallback combination return(false); } // Settings var settings = RestoreSettingsUtils.ReadSettings(RestoreSolutionDirectory, Path.GetDirectoryName(ProjectUniqueName), RestoreConfigFile, _machineWideSettings); OutputConfigFilePaths = SettingsUtility.GetConfigFilePaths(settings).ToArray(); // PackagesPath OutputPackagesPath = RestoreSettingsUtils.GetValue( () => string.IsNullOrEmpty(RestorePackagesPathOverride) ? null : UriUtility.GetAbsolutePath(MSBuildStartupDirectory, RestorePackagesPathOverride), () => string.IsNullOrEmpty(RestorePackagesPath) ? null : UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, RestorePackagesPath), () => SettingsUtility.GetGlobalPackagesFolder(settings)); // Sources var currentSources = RestoreSettingsUtils.GetValue( () => RestoreSourcesOverride?.Select(MSBuildRestoreUtility.FixSourcePath).Select(e => UriUtility.GetAbsolutePath(MSBuildStartupDirectory, e)).ToArray(), () => MSBuildRestoreUtility.ContainsClearKeyword(RestoreSources) ? new string[0] : null, () => RestoreSources?.Select(MSBuildRestoreUtility.FixSourcePath).Select(e => UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, e)).ToArray(), () => (new PackageSourceProvider(settings)).LoadPackageSources().Select(e => e.Source).ToArray()); // Append additional sources // Escape strings to avoid xplat path issues with msbuild. OutputSources = AppendItems(currentSources, RestoreAdditionalProjectSources?.Select(MSBuildRestoreUtility.FixSourcePath).ToArray()); // Fallback folders var currentFallbackFolders = RestoreSettingsUtils.GetValue( () => RestoreFallbackFoldersOverride?.Select(e => UriUtility.GetAbsolutePath(MSBuildStartupDirectory, e)).ToArray(), () => MSBuildRestoreUtility.ContainsClearKeyword(RestoreFallbackFolders) ? new string[0] : null, () => RestoreFallbackFolders?.Select(e => UriUtility.GetAbsolutePathFromFile(ProjectUniqueName, e)).ToArray(), () => SettingsUtility.GetFallbackPackageFolders(settings).ToArray()); // Append additional fallback folders OutputFallbackFolders = AppendItems(currentFallbackFolders, RestoreAdditionalProjectFallbackFolders); } catch (Exception ex) { // Log exceptions with error codes if they exist. ExceptionUtilities.LogException(ex, log); return(false); } // Log Outputs BuildTasksUtility.LogOutputParam(log, nameof(OutputPackagesPath), OutputPackagesPath); BuildTasksUtility.LogOutputParam(log, nameof(OutputSources), OutputSources); BuildTasksUtility.LogOutputParam(log, nameof(OutputFallbackFolders), OutputFallbackFolders); BuildTasksUtility.LogOutputParam(log, nameof(OutputConfigFilePaths), OutputConfigFilePaths); return(true); }