From bbd4211c8e9002ca2634bc41459bc782651cd01f Mon Sep 17 00:00:00 2001 From: William Li Date: Thu, 1 Jul 2021 16:00:11 -0700 Subject: [PATCH] Add workload restore command Adding _FindAllReferenceWorkload target to find workloads in project. Discover the projects and then pipe all arguements to workload install command --- src/Cli/dotnet/CommonOptionsExtension.cs | 46 +++++++ src/Cli/dotnet/Parser.cs | 17 +-- .../dotnet-workload/WorkloadCommandParser.cs | 8 +- .../install/WorkloadInstallCommand.cs | 5 +- .../install/WorkloadInstallCommandParser.cs | 9 +- .../restore/LocalizableStrings.resx | 48 +------- .../restore/WorkloadRestoreCommand.cs | 116 +++++++++++++++--- .../restore/WorkloadRestoreCommandParser.cs | 13 +- .../restore/xlf/LocalizableStrings.cs.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.de.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.es.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.fr.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.it.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.ja.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.ko.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.pl.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.pt-BR.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.ru.xlf | 78 ++---------- .../restore/xlf/LocalizableStrings.tr.xlf | 78 ++---------- .../xlf/LocalizableStrings.zh-Hans.xlf | 78 ++---------- .../xlf/LocalizableStrings.zh-Hant.xlf | 78 ++---------- ...NET.Sdk.BeforeCommonCrossTargeting.targets | 1 + ...etRequiredWorkloads.CrossTargeting.targets | 33 +++++ .../Microsoft.NET.Sdk.ImportWorkloads.targets | 27 +++- ...t.NET.Sdk.Workloads.CrossTargeting.targets | 33 +++++ ...rosoft.PackageDependencyResolution.targets | 2 +- .../WorkloadTests.cs | 71 +++++++++++ .../Commands/GetValuesCommand.cs | 2 + .../GivenDotnetWorkloadInstall.cs | 28 ++--- .../GivenDotnetWorkloadList.cs | 4 +- ...nWorkloadInstallerAndWorkloadsInstalled.cs | 6 +- .../GivenDotnetWorkloadRepair.cs | 6 +- .../DiscoverAllProjectsTests.cs | 73 +++++++++++ .../GivenDotnetWorkloadSearch.cs | 20 +-- .../GivenDotnetWorkloadUninstall.cs | 4 +- .../GivenDotnetWorkloadUpdate.cs | 24 ++-- src/Tests/dotnet.Tests/dotnet.Tests.csproj | 1 + 37 files changed, 573 insertions(+), 1038 deletions(-) create mode 100644 src/Cli/dotnet/CommonOptionsExtension.cs create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.GetRequiredWorkloads.CrossTargeting.targets create mode 100644 src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Workloads.CrossTargeting.targets create mode 100644 src/Tests/dotnet-workload-restore.Tests/DiscoverAllProjectsTests.cs diff --git a/src/Cli/dotnet/CommonOptionsExtension.cs b/src/Cli/dotnet/CommonOptionsExtension.cs new file mode 100644 index 000000000000..69d516853333 --- /dev/null +++ b/src/Cli/dotnet/CommonOptionsExtension.cs @@ -0,0 +1,46 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using Microsoft.DotNet.Tools; +using System.CommandLine; +using System.IO; +using Microsoft.Build.Framework; +using Microsoft.DotNet.Tools.Common; + +namespace Microsoft.DotNet.Cli +{ + internal static class CommonOptionsExtension + { + public static LoggerVerbosity ToLoggerVerbosity(this VerbosityOptions verbosityOptions) + { + LoggerVerbosity verbosity = Build.Framework.LoggerVerbosity.Normal; + switch (verbosityOptions) + { + case VerbosityOptions.d: + case VerbosityOptions.detailed: + verbosity = Build.Framework.LoggerVerbosity.Detailed; + break; + case VerbosityOptions.diag: + case VerbosityOptions.diagnostic: + verbosity = Build.Framework.LoggerVerbosity.Diagnostic; + break; + case VerbosityOptions.m: + case VerbosityOptions.minimal: + verbosity = Build.Framework.LoggerVerbosity.Minimal; + break; + case VerbosityOptions.n: + case VerbosityOptions.normal: + verbosity = Build.Framework.LoggerVerbosity.Normal; + break; + case VerbosityOptions.q: + case VerbosityOptions.quiet: + verbosity = Build.Framework.LoggerVerbosity.Quiet; + break; + } + + + return verbosity; + } + } +} diff --git a/src/Cli/dotnet/Parser.cs b/src/Cli/dotnet/Parser.cs index dfcdf6d78699..c13efc55e911 100644 --- a/src/Cli/dotnet/Parser.cs +++ b/src/Cli/dotnet/Parser.cs @@ -72,7 +72,7 @@ public static class Parser // Argument public static readonly Argument DotnetSubCommand = new Argument() { Arity = ArgumentArity.ExactlyOne, IsHidden = true }; - private static Command ConfigureCommandLine(Command rootCommand, bool includeWorkloadCommands = false) + private static Command ConfigureCommandLine(Command rootCommand) { // Add subcommands foreach (var subcommand in Subcommands) @@ -80,11 +80,10 @@ private static Command ConfigureCommandLine(Command rootCommand, bool includeWor rootCommand.AddCommand(subcommand); } - // Workload command is behind a feature flag during development - rootCommand.AddCommand(WorkloadCommandParser.GetCommand(includeWorkloadCommands || Env.GetEnvironmentVariableAsBool("DEVENABLEWORKLOADCOMMAND", defaultValue: false))); + rootCommand.AddCommand(WorkloadCommandParser.GetCommand()); //Add internal commands - rootCommand.AddCommand(InstallSuccessCommand); + rootCommand.AddCommand(InstallSuccessCommand); // Add options rootCommand.AddOption(DiagOption); @@ -115,16 +114,6 @@ private static CommandLineBuilder DisablePosixBinding(this CommandLineBuilder bu .DisablePosixBinding() .Build(); - public static System.CommandLine.Parsing.Parser GetWorkloadsInstance { get; } = new CommandLineBuilder(ConfigureCommandLine(new RootCommand(), true)) - .UseExceptionHandler(ExceptionHandler) - .UseHelp() - .UseHelpBuilder(context => new DotnetHelpBuilder(context.Console)) - .UseResources(new CommandLineValidationMessages()) - .UseParseDirective() - .UseSuggestDirective() - .DisablePosixBinding() - .Build(); - private static void ExceptionHandler(Exception exception, InvocationContext context) { if (exception is TargetInvocationException) diff --git a/src/Cli/dotnet/commands/dotnet-workload/WorkloadCommandParser.cs b/src/Cli/dotnet/commands/dotnet-workload/WorkloadCommandParser.cs index 65a4bf949020..87ae90491f32 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/WorkloadCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/WorkloadCommandParser.cs @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli { internal static class WorkloadCommandParser { - public static Command GetCommand(bool includeAllCommands) + public static Command GetCommand() { var command = new Command("workload", LocalizableStrings.CommandDescription); @@ -18,11 +18,7 @@ public static Command GetCommand(bool includeAllCommands) command.AddCommand(WorkloadSearchCommandParser.GetCommand()); command.AddCommand(WorkloadUninstallCommandParser.GetCommand()); command.AddCommand(WorkloadRepairCommandParser.GetCommand()); - if (includeAllCommands) - { - command.AddCommand(WorkloadRestoreCommandParser.GetCommand()); - } - + command.AddCommand(WorkloadRestoreCommandParser.GetCommand()); command.AddCommand(WorkloadElevateCommandParser.GetCommand()); return command; diff --git a/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommand.cs b/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommand.cs index 9c9470e81e55..94268f8533e6 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommand.cs @@ -57,7 +57,8 @@ public WorkloadInstallCommand( string dotnetDir = null, string userHome = null, string tempDirPath = null, - string version = null) + string version = null, + IReadOnlyCollection workloadIds = null) : base(parseResult) { _reporter = reporter ?? Reporter.Output; @@ -66,7 +67,7 @@ public WorkloadInstallCommand( _printDownloadLinkOnly = parseResult.ValueForOption(WorkloadInstallCommandParser.PrintDownloadLinkOnlyOption); _fromCacheOption = parseResult.ValueForOption(WorkloadInstallCommandParser.FromCacheOption); _downloadToCacheOption = parseResult.ValueForOption(WorkloadInstallCommandParser.DownloadToCacheOption); - _workloadIds = parseResult.ValueForArgument>(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly(); + _workloadIds = workloadIds ?? parseResult.ValueForArgument>(WorkloadInstallCommandParser.WorkloadIdArgument).ToList().AsReadOnly(); _verbosity = parseResult.ValueForOption(WorkloadInstallCommandParser.VerbosityOption); _dotnetPath = dotnetDir ?? Path.GetDirectoryName(Environment.ProcessPath); _sdkVersion = WorkloadOptionsExtensions.GetValidatedSdkVersion(parseResult.ValueForOption(WorkloadInstallCommandParser.VersionOption), version, _dotnetPath); diff --git a/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommandParser.cs b/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommandParser.cs index 9157b55b9f91..f934ffbdd14d 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/install/WorkloadInstallCommandParser.cs @@ -57,6 +57,13 @@ public static Command GetCommand() var command = new Command("install", LocalizableStrings.CommandDescription); command.AddArgument(WorkloadIdArgument); + AddWorkloadInstallCommandOptions(command); + + return command; + } + + internal static void AddWorkloadInstallCommandOptions(Command command) + { command.AddOption(VersionOption); command.AddOption(ConfigOption); command.AddOption(SourceOption); @@ -68,8 +75,6 @@ public static Command GetCommand() command.AddOption(TempDirOption); command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); command.AddOption(VerbosityOption); - - return command; } } } diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/LocalizableStrings.resx b/src/Cli/dotnet/commands/dotnet-workload/restore/LocalizableStrings.resx index f4b4e7670db9..b504335ecf6f 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/LocalizableStrings.resx +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/LocalizableStrings.resx @@ -120,49 +120,13 @@ Restore workloads required for the project. - - Warning: workload package '{0}' is invalid + + Installing workloads: {0} - - Package Id + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - Version - - - Commands - - - Add an additional NuGet package source to use during installation. - - - SOURCE - - - The NuGet configuration file to use. - - - FILE - - - The version of the workload package to install. - - - VERSION - - - Package "{0}" failed to restore, due to {1} - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - - - Restore partially failed. - - - Restore failed. - - - No workloads were restored. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommand.cs b/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommand.cs index d7f4c444008e..bf8305108721 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommand.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommand.cs @@ -2,21 +2,28 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; using System.CommandLine.Parsing; +using System.IO; +using System.Linq; +using Microsoft.Build.Construction; +using Microsoft.Build.Execution; +using Microsoft.Build.Framework; +using Microsoft.Build.Logging; using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Workloads.Workload.Install; using Microsoft.Extensions.EnvironmentAbstractions; +using Microsoft.NET.Sdk.WorkloadManifestReader; namespace Microsoft.DotNet.Workloads.Workload.Restore { internal class WorkloadRestoreCommand : CommandBase { - private readonly string _configFilePath; - private readonly IReporter _errorReporter; - private readonly IFileSystem _fileSystem; + private readonly ParseResult _result; private readonly IReporter _reporter; - private readonly string[] _sources; - private readonly string _verbosity; + private readonly IEnumerable _slnOrProjectArgument; public WorkloadRestoreCommand( ParseResult result, @@ -24,21 +31,102 @@ public WorkloadRestoreCommand( IReporter reporter = null) : base(result) { - _fileSystem = fileSystem ?? new FileSystemWrapper(); - + _result = result; _reporter = reporter ?? Reporter.Output; - _errorReporter = reporter ?? Reporter.Error; - - _configFilePath = result.ValueForOption(WorkloadRestoreCommandParser.ConfigOption); - _sources = result.ValueForOption(WorkloadRestoreCommandParser.SourceOption); - _verbosity = - Enum.GetName(result.ValueForOption(WorkloadRestoreCommandParser.VerbosityOption)); + _slnOrProjectArgument = + result.ValueForArgument>(RestoreCommandParser.SlnOrProjectArgument); } public override int Execute() { - _reporter.WriteLine("WIP workload restore stub"); + var allProjects = DiscoverAllProjects(Directory.GetCurrentDirectory(), _slnOrProjectArgument).Distinct(); + List allWorkloadId = RunTargetToGetWorkloadIds(allProjects); + _reporter.WriteLine(string.Format(LocalizableStrings.InstallingWorkloads, string.Join(" ", allWorkloadId))); + + var workloadInstallCommand = new WorkloadInstallCommand(_result, + workloadIds: allWorkloadId.Select(a => a.ToString()).ToList().AsReadOnly()); + + workloadInstallCommand.Execute(); return 0; } + + private List RunTargetToGetWorkloadIds(IEnumerable allProjects) + { + var globalProperties = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + {"SkipResolvePackageAssets", "true"} + }; + + var allWorkloadId = new List(); + foreach (string projectFile in allProjects) + { + var project = new ProjectInstance(projectFile, globalProperties, null); + + bool buildResult = project.Build(new[] {"_GetRequiredWorkloads"}, + loggers: new ILogger[] + { + new ConsoleLogger(_result + .ValueForOption(WorkloadInstallCommandParser.VerbosityOption) + .ToLoggerVerbosity()) + }, + remoteLoggers: Enumerable.Empty(), + targetOutputs: out var targetOutputs); + + if (buildResult == false) + { + throw new GracefulException( + string.Format( + LocalizableStrings.FailedToRunTarget, + projectFile)); + } + + var targetResult = targetOutputs["_GetRequiredWorkloads"]; + allWorkloadId.AddRange(targetResult.Items.Select(item => new WorkloadId(item.ItemSpec))); + } + + allWorkloadId = allWorkloadId.Distinct().ToList(); + return allWorkloadId; + } + + + internal static List DiscoverAllProjects(string currentDirectory, + IEnumerable slnOrProjectArgument = null) + { + var slnFiles = new List(); + var projectFiles = new List(); + if (slnOrProjectArgument == null || !slnOrProjectArgument.Any()) + { + slnFiles = Directory.GetFiles(currentDirectory, "*.sln").ToList(); + projectFiles.AddRange(Directory.GetFiles(currentDirectory, "*.*proj")); + } + else + { + slnFiles = slnOrProjectArgument + .Where(s => Path.GetExtension(s).Equals(".sln", StringComparison.OrdinalIgnoreCase)) + .Select(Path.GetFullPath).ToList(); + projectFiles = slnOrProjectArgument + .Where(s => Path.GetExtension(s).EndsWith("proj", StringComparison.OrdinalIgnoreCase)) + .Select(Path.GetFullPath).ToList(); + } + + foreach (string file in slnFiles) + { + var solutionFile = SolutionFile.Parse(file); + var projects = solutionFile.ProjectsInOrder; + foreach (var p in projects) + { + projectFiles.Add(p.AbsolutePath); + } + } + + if (projectFiles.Count == 0) + { + throw new GracefulException( + LocalizableStrings.CouldNotFindAProject, + currentDirectory, "--project"); + } + + return projectFiles; + } } } diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommandParser.cs b/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommandParser.cs index 8daadc88e9ed..c0125541803f 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommandParser.cs +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/WorkloadRestoreCommandParser.cs @@ -8,21 +8,12 @@ namespace Microsoft.DotNet.Cli { internal static class WorkloadRestoreCommandParser { - public static readonly Option ConfigOption = WorkloadInstallCommandParser.ConfigOption; - - public static readonly Option SourceOption = WorkloadInstallCommandParser.SourceOption; - - public static readonly Option VerbosityOption = WorkloadInstallCommandParser.VerbosityOption; - public static Command GetCommand() { Command command = new Command("restore", LocalizableStrings.CommandDescription); - command.AddOption(ConfigOption); - command.AddOption(SourceOption); - command.AddWorkloadCommandNuGetRestoreActionConfigOptions(); - command.AddOption(VerbosityOption); - + command.AddArgument(RestoreCommandParser.SlnOrProjectArgument); + WorkloadInstallCommandParser.AddWorkloadInstallCommandOptions(command); return command; } } diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.cs.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.cs.xlf index 2daba4f2ac61..1f647afa645e 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.cs.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.cs.xlf @@ -7,79 +7,19 @@ Obnoví nástroje definované v manifestu místního nástroje. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Neobnovily se žádné nástroje. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - ID balíčku - - - - Version - Verze - - - - Commands - Příkazy - - - - Add an additional NuGet package source to use during installation. - Přidá další zdroj balíčku NuGet, který se použije při instalaci. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Konfigurační soubor NuGet, který se použije. - - - - FILE - FILE - - - - The version of the workload package to install. - Verze balíčku nástroje, který se má nainstalovat - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Balíček {0} se nepovedlo obnovit. Příčina: {1} - - - - Restore failed. - Obnovení selhalo. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - Nástroj {0} (verze {1}) se obnovil. Dostupné příkazy: {2} - - - - Restore partially failed. - Obnovení bylo částečně neúspěšné. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.de.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.de.xlf index d780d08d1b9c..8352cdc7b6bd 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.de.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.de.xlf @@ -7,79 +7,19 @@ Hiermit stellen Sie die im lokalen Workloadmanifest definierten Workloads wieder her. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Es wurden keine Workloads wiederhergestellt. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - Paket-ID - - - - Version - Version - - - - Commands - Befehle - - - - Add an additional NuGet package source to use during installation. - Hiermit wird eine weitere NuGet-Paketquelle zur Verwendung während der Installation hinzugefügt. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Die zu verwendende NuGet-Konfigurationsdatei. - - - - FILE - FILE - - - - The version of the workload package to install. - Die Version des zu installierenden Workloadpakets. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Das Paket "{0}" konnte nicht wiederhergestellt werden. Ursache: {1} - - - - Restore failed. - Fehler bei der Wiederherstellung. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - Das Workload "{0}" (Version {1}) wurde wiederhergestellt. Verfügbare Befehle: {2} - - - - Restore partially failed. - Die Wiederherstellung war nur teilweise möglich. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.es.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.es.xlf index f86e10393d1c..5d3c407de628 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.es.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.es.xlf @@ -7,79 +7,19 @@ Restaurar las herramientas definidas en el manifiesto de la herramienta local. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - No se restauró ninguna herramienta. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - Id. de paquete - - - - Version - Versión - - - - Commands - Comandos - - - - Add an additional NuGet package source to use during installation. - Agrega un origen de paquetes de NuGet para utilizar durante la instalación. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Archivo de configuración de NuGet que debe usarse. - - - - FILE - FILE - - - - The version of the workload package to install. - La versión del paquete de herramientas para instalar. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - No se pudo restaurar el paquete "{0}", debido a {1} - - - - Restore failed. - Error de restauración. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - Se restauró la herramienta "{0}" (versión "{1}"). Comandos disponibles: {2} - - - - Restore partially failed. - Error parcial de restauración. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.fr.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.fr.xlf index 2dad430c157d..e51b3d9faf1d 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.fr.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.fr.xlf @@ -7,79 +7,19 @@ Restaure les outils définis dans le manifeste d'outils locaux. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Aucun outil n'a été restauré. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - ID de package - - - - Version - Version - - - - Commands - Commandes - - - - Add an additional NuGet package source to use during installation. - Ajoutez une source de package NuGet supplémentaire à utiliser durant l'installation. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Fichier de configuration NuGet à utiliser. - - - - FILE - FILE - - - - The version of the workload package to install. - Version du package d'outils à installer. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Échec de la restauration du package "{0}". Raison : {1} - - - - Restore failed. - La restauration a échoué. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - L'outil '{0}' (version '{1}') a été restauré. Commandes disponibles : {2} - - - - Restore partially failed. - Échec partiel de la restauration. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.it.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.it.xlf index 871556f2a616..670db612996c 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.it.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.it.xlf @@ -7,79 +7,19 @@ Ripristina gli strumenti definiti nel manifesto degli strumenti locale. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Non è stato ripristinato alcuno strumento. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - ID pacchetto - - - - Version - Versione - - - - Commands - Comandi - - - - Add an additional NuGet package source to use during installation. - Aggiunge un'altra origine pacchetto NuGet da usare durante l'installazione. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - File di configurazione NuGet da usare. - - - - FILE - FILE - - - - The version of the workload package to install. - Versione del pacchetto dello strumento da installare. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Il ripristino del pacchetto "{0}" non è riuscito a causa di {1} - - - - Restore failed. - Il ripristino non è riuscito. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - Lo strumento '{0}' (versione '{1}') è stato ripristinato. Comandi disponibili: {2} - - - - Restore partially failed. - Il ripristino non è riuscito parzialmente. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ja.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ja.xlf index 725fce8fa256..9823947480e5 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ja.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ja.xlf @@ -7,79 +7,19 @@ ローカル ツール マニフェストで定義されているツールを復元します。 - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - 復元されたツールはありません。 + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - パッケージ ID - - - - Version - バージョン - - - - Commands - コマンド - - - - Add an additional NuGet package source to use during installation. - インストール中に使用する他の NuGet パッケージ ソースを追加します。 - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - 使用する NuGet 構成ファイル。 - - - - FILE - FILE - - - - The version of the workload package to install. - インストールするツール パッケージのバージョン。 - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - {1} が原因で、パッケージ "{0}" の復元が失敗しました。 - - - - Restore failed. - 復元できませんでした。 - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - ツール '{0}' (バージョン '{1}') は復元されました。使用できるコマンド: {2} - - - - Restore partially failed. - 復元が部分的に失敗しました。 + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ko.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ko.xlf index 23de1644a73e..af6915a882fd 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ko.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ko.xlf @@ -7,79 +7,19 @@ 로컬 도구 매니페스트에 정의된 도구를 복원합니다. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - 복원된 도구가 없습니다. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - 패키지 ID - - - - Version - 버전 - - - - Commands - 명령 - - - - Add an additional NuGet package source to use during installation. - 설치 중 사용할 추가 NuGet 패키지 소스를 추가합니다. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - 사용할 NuGet 구성 파일입니다. - - - - FILE - FILE - - - - The version of the workload package to install. - 설치할 도구 패키지 버전입니다. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - {1}(으)로 인해 "{0}" 패키지를 복원하지 못했습니다. - - - - Restore failed. - 복원하지 못했습니다. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - '{0}' 도구(버전 '{1}')가 복원되었습니다. 사용 가능한 명령: {2} - - - - Restore partially failed. - 부분적으로 복원하지 못했습니다. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pl.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pl.xlf index e2c94e3f10b1..59c15166b791 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pl.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pl.xlf @@ -7,79 +7,19 @@ Przywróć narzędzia zdefiniowane w manifeście narzędzi lokalnych. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Nie przywrócono żadnych narzędzi. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - Identyfikator pakietu - - - - Version - Wersja - - - - Commands - Polecenia - - - - Add an additional NuGet package source to use during installation. - Dodaj dodatkowe źródło pakietu NuGet do użycia podczas instalacji. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Plik konfiguracji programu NuGet do użycia. - - - - FILE - FILE - - - - The version of the workload package to install. - Wersja pakietu narzędzia do zainstalowania. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Nie można przywrócić pakietu „{0}” z powodu {1} - - - - Restore failed. - Błąd przywracania. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - Narzędzie „{0}” (wersja „{1}”) zostało przywrócone. Dostępne polecenia: {2} - - - - Restore partially failed. - Przywracanie częściowo nie powiodło się. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pt-BR.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pt-BR.xlf index 4c60e440ff02..122ce354cc27 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.pt-BR.xlf @@ -7,79 +7,19 @@ Restaure as ferramentas definidas no manifesto de ferramenta local. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Nenhuma ferramenta foi restaurada. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - ID do Pacote - - - - Version - Versão - - - - Commands - Comandos - - - - Add an additional NuGet package source to use during installation. - Adicionar uma origem adicional do pacote do NuGet a ser usada durante a instalação. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - O arquivo de configuração do NuGet a ser usado. - - - - FILE - FILE - - - - The version of the workload package to install. - A versão do pacote da ferramenta a ser instalada. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Falha na restauração do pacote "{0}" devido a {1} - - - - Restore failed. - Falha na restauração. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - A ferramenta '{0}' (versão '{1}') foi restaurada. Comandos disponíveis: {2} - - - - Restore partially failed. - Falha parcial na restauração. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ru.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ru.xlf index 14ca42af89ab..f76261836180 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ru.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.ru.xlf @@ -7,79 +7,19 @@ Восстановление средств, определенных в манифесте локального инструмента. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Не были восстановлены никакие средства. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - Идентификатор пакета - - - - Version - Версия - - - - Commands - Команды - - - - Add an additional NuGet package source to use during installation. - Добавление дополнительного источника пакетов NuGet для использования при установке. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Используемый файл конфигурации NuGet. - - - - FILE - FILE - - - - The version of the workload package to install. - Версия устанавливаемого пакета инструмента. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - Не удалось восстановить пакет "{0}" по следующей причине: {1} - - - - Restore failed. - Сбой восстановления. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - Средство "{0}" (версия "{1}") было восстановлено. Доступные команды: {2} - - - - Restore partially failed. - Восстановление частично не выполнено. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.tr.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.tr.xlf index ea46ce94c793..8ad8d5d34b40 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.tr.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.tr.xlf @@ -7,79 +7,19 @@ Yerel araç bildiriminde tanımlı araçları geri yükleyin. - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - Hiçbir araç geri yüklenmedi. + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - Paket Kimliği - - - - Version - Sürüm - - - - Commands - Komutlar - - - - Add an additional NuGet package source to use during installation. - Yükleme sırasında kullanılacak ek bir NuGet paket kaynağı ekler. - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - Kullanılacak NuGet yapılandırma dosyası. - - - - FILE - FILE - - - - The version of the workload package to install. - Yüklenecek araç paketinin sürümü. - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - "{0}" adlı paket, {1} nedeniyle geri yüklenemedi - - - - Restore failed. - Geri yükleme başarısız oldu. - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - '{0}' aracı (sürüm '{1}') geri yüklendi. Kullanılabilen komutlar: {2} - - - - Restore partially failed. - Geri yükleme kısmen başarısız oldu. + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hans.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hans.xlf index d9bed1001a01..0853179e8437 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hans.xlf @@ -7,79 +7,19 @@ 还原本地工具清单中定义的工具。 - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - 未还原任何工具。 + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - 包 ID - - - - Version - 版本 - - - - Commands - 命令 - - - - Add an additional NuGet package source to use during installation. - 添加其他要在安装期间使用的 NuGet 包源。 - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - 要使用的 NuGet 配置文件。 - - - - FILE - FILE - - - - The version of the workload package to install. - 要安装的工具包版本。 - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - 包“{0}”无法还原,因为 {1} - - - - Restore failed. - 还原失败。 - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - 工具“{0}”(版本“{1}”)已还原。可用的命令: {2} - - - - Restore partially failed. - 还原部分失败。 + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hant.xlf b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hant.xlf index a8e6d6c7d65b..f39a64fee50c 100644 --- a/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/commands/dotnet-workload/restore/xlf/LocalizableStrings.zh-Hant.xlf @@ -7,79 +7,19 @@ 還原本機工具資訊清單中所定義的工具。 - - Warning: workload package '{0}' is invalid - Warning: workload package '{0}' is invalid + + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. + Couldn't find a project. Ensure a project exists in {0}, or pass the path to the project using {1}. - - No workloads were restored. - 未還原任何工具。 + + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. + Failed to restore workload for project {0}: Failed to run MSBuild Target _GetRequiredWorkloads. - - Package Id - 套件識別碼 - - - - Version - 版本 - - - - Commands - 命令 - - - - Add an additional NuGet package source to use during installation. - 新增於安裝期間要使用的額外 NuGet 套件來源。 - - - - SOURCE - SOURCE - - - - The NuGet configuration file to use. - 要使用的 NuGet 組態檔。 - - - - FILE - FILE - - - - The version of the workload package to install. - 要安裝之工具套件的版本。 - - - - VERSION - VERSION - - - - Package "{0}" failed to restore, due to {1} - 因為 {1},所以無法還原套件 "{0}" - - - - Restore failed. - 還原失敗。 - - - - Workload '{0}' (version '{1}') was restored. Available commands: {2} - 已還原工具 '{0}' (版本 '{1}')。可用的命令: {2} - - - - Restore partially failed. - 還原部分失敗。 + + Installing workloads: {0} + Installing workloads: {0} diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets index d25f48071cb6..2fbae7d16b50 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.BeforeCommonCrossTargeting.targets @@ -13,5 +13,6 @@ Copyright (c) .NET Foundation. All rights reserved. + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.GetRequiredWorkloads.CrossTargeting.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.GetRequiredWorkloads.CrossTargeting.targets new file mode 100644 index 000000000000..579963e32c43 --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.GetRequiredWorkloads.CrossTargeting.targets @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.ImportWorkloads.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.ImportWorkloads.targets index a4757ad5b12d..788e84d6c5e4 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.ImportWorkloads.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.ImportWorkloads.targets @@ -17,7 +17,9 @@ Copyright (c) .NET Foundation. All rights reserved. - + - + - + + + + + + + + + + <_ResolvedSuggestedWorkload Include="@(SuggestedWorkload)"/> + <_ResolvedSuggestedWorkload Include="@(SuggestedWorkloadFromReference)"/> + + + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Workloads.CrossTargeting.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Workloads.CrossTargeting.targets new file mode 100644 index 000000000000..579963e32c43 --- /dev/null +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Workloads.CrossTargeting.targets @@ -0,0 +1,33 @@ + + + + + + + + + + + + diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets index ba355f8ac231..3a14b23e9214 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.PackageDependencyResolution.targets @@ -208,7 +208,7 @@ Copyright (c) .NET Foundation. All rights reserved. (() => installManager.InstallWorkloads(mockWorkloadIds, true)); @@ -91,7 +91,7 @@ public void GivenWorkloadInstallOnFailingRollbackItDisplaysTopLevelError() var dotnetRoot = Path.Combine(testDirectory, "dotnet"); var installer = new MockPackWorkloadInstaller(failingWorkload: "xamarin-android-build", failingRollback: true); var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot }); - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "xamarin-android-build", "--skip-manifest-update" }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "xamarin-android-build", "--skip-manifest-update" }); var installManager = new WorkloadInstallCommand(parseResult, reporter: _reporter, workloadResolver: workloadResolver, workloadInstaller: installer, version: "6.0.100"); var exceptionThrown = Assert.Throws(() => installManager.InstallWorkloads(mockWorkloadIds, true)); @@ -99,11 +99,11 @@ public void GivenWorkloadInstallOnFailingRollbackItDisplaysTopLevelError() string.Join(" ", _reporter.Lines).Should().Contain("Rollback failure"); } - + [Fact] public void GivenWorkloadInstallItCanUpdateAdvertisingManifests() { - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android" }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android" }); (_, var installManager, var installer, _, var manifestUpdater, _) = GetTestInstallers(parseResult); installManager.InstallWorkloads(new List(), false); // Don't actually do any installs, just update manifests @@ -117,7 +117,7 @@ public void GivenWorkloadInstallItCanUpdateAdvertisingManifests() public void GivenWorkloadInstallItCanUpdateInstalledManifests() { var parseResult = - Parser.GetWorkloadsInstance.Parse(new string[] {"dotnet", "workload", "install", "xamarin-android"}); + Parser.Instance.Parse(new string[] {"dotnet", "workload", "install", "xamarin-android"}); var manifestsToUpdate = new (ManifestId, ManifestVersion, ManifestVersion, Dictionary Workloads)[] @@ -148,7 +148,7 @@ public void GivenWorkloadInstallFromCacheItInstallsCachedManifest() }; var cachePath = Path.Combine(_testAssetsManager.CreateTestDirectory(identifier: "mockCache").Path, "mockCachePath"); - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--from-cache", cachePath }); @@ -167,7 +167,7 @@ public void GivenWorkloadInstallFromCacheItInstallsCachedManifest() public void GivenWorkloadInstallItCanDownloadToOfflineCache() { var cachePath = Path.Combine(_testAssetsManager.CreateTestDirectory(identifier: "mockCache").Path, "mockCachePath"); - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--download-to-cache", cachePath }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--download-to-cache", cachePath }); (_, var installManager, var installer, _, var manifestUpdater, _) = GetTestInstallers(parseResult, tempDirManifestPath: _manifestPath); installManager.Execute(); @@ -185,7 +185,7 @@ public void GivenWorkloadInstallItCanInstallFromOfflineCache() { var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") }; var cachePath = "mockCachePath"; - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--from-cache", cachePath }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--from-cache", cachePath }); (_, var installManager, var installer, _, _, var nugetDownloader) = GetTestInstallers(parseResult); installManager.Execute(); @@ -197,11 +197,11 @@ public void GivenWorkloadInstallItCanInstallFromOfflineCache() installer.InstalledPacks.Where(pack => pack.Id.Contains("Android")).Count().Should().Be(8); nugetDownloader.DownloadCallParams.Count().Should().Be(0); } - + [Fact] public void GivenWorkloadInstallItPrintsDownloadUrls() { - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--print-download-link-only" }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--print-download-link-only" }); (_, var installManager, _, _, _, _) = GetTestInstallers(parseResult, tempDirManifestPath: _manifestPath); installManager.Execute(); @@ -222,7 +222,7 @@ public void GivenWorkloadInstallItErrorsOnUnsupportedPlatform() var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { manifestPath }), new string[] { dotnetRoot }); var nugetDownloader = new MockNuGetPackageDownloader(dotnetRoot); var manifestUpdater = new MockWorkloadManifestUpdater(); - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", mockWorkloadId }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", mockWorkloadId }); var exceptionThrown = Assert.Throws(() => new WorkloadInstallCommand(parseResult, reporter: _reporter, workloadResolver: workloadResolver, workloadInstaller: installer, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, dotnetDir: dotnetRoot, version: "6.0.100")); @@ -243,13 +243,13 @@ public void GivenWorkloadInstallItDoesNotRemoveOldInstallsOnRollback() var installingWorkload = "mock-2"; // Successfully install a workload - var installParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", existingWorkload }); + var installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", existingWorkload }); var installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: new MockNuGetPackageDownloader(dotnetRoot), workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); installCommand.Execute(); // Install a workload with a mocked nuget failure - installParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); + installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); var exceptionThrown = Assert.Throws(() => installCommand.Execute()); diff --git a/src/Tests/dotnet-workload-list.Tests/GivenDotnetWorkloadList.cs b/src/Tests/dotnet-workload-list.Tests/GivenDotnetWorkloadList.cs index 9ab712252245..9af5664a393d 100644 --- a/src/Tests/dotnet-workload-list.Tests/GivenDotnetWorkloadList.cs +++ b/src/Tests/dotnet-workload-list.Tests/GivenDotnetWorkloadList.cs @@ -23,8 +23,8 @@ public class GivenDotnetWorkloadList : SdkTest public GivenDotnetWorkloadList(ITestOutputHelper log) : base(log) { _reporter = new BufferedReporter(); - _machineReadableParseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload list --machine-readable"); - _parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload list"); + _machineReadableParseResult = Parser.Instance.Parse("dotnet workload list --machine-readable"); + _parseResult = Parser.Instance.Parse("dotnet workload list"); } [Fact] diff --git a/src/Tests/dotnet-workload-list.Tests/GivenWorkloadInstallerAndWorkloadsInstalled.cs b/src/Tests/dotnet-workload-list.Tests/GivenWorkloadInstallerAndWorkloadsInstalled.cs index 92975618e016..1ff884358465 100644 --- a/src/Tests/dotnet-workload-list.Tests/GivenWorkloadInstallerAndWorkloadsInstalled.cs +++ b/src/Tests/dotnet-workload-list.Tests/GivenWorkloadInstallerAndWorkloadsInstalled.cs @@ -86,7 +86,7 @@ private void Setup(string identifier) }) }; - ParseResult listParseResult = Parser.GetWorkloadsInstance.Parse(new[] + ParseResult listParseResult = Parser.Instance.Parse(new[] { "dotnet", "workload", "list", "--machine-readable", WorkloadInstallCommandParser.VersionOption.Aliases.First(), "7.0.100" }); @@ -128,7 +128,7 @@ public void ItShouldGetListOfWorkloadWithCurrentSdkVersionBand() public void GivenLowerTargetVersionItShouldThrow() { _workloadListCommand = new WorkloadListCommand( - Parser.GetWorkloadsInstance.Parse(new[] + Parser.Instance.Parse(new[] { "dotnet", "workload", "list", "--machine-readable", WorkloadInstallCommandParser.VersionOption.Aliases.First(), "5.0.306" }), @@ -148,7 +148,7 @@ public void GivenLowerTargetVersionItShouldThrow() public void GivenSameLowerTargetVersionBandItShouldNotThrow() { _workloadListCommand = new WorkloadListCommand( - Parser.GetWorkloadsInstance.Parse(new[] + Parser.Instance.Parse(new[] { "dotnet", "workload", "list", "--machine-readable", WorkloadInstallCommandParser.VersionOption.Aliases.First(), "6.0.100" }), diff --git a/src/Tests/dotnet-workload-repair.Tests/GivenDotnetWorkloadRepair.cs b/src/Tests/dotnet-workload-repair.Tests/GivenDotnetWorkloadRepair.cs index bca61d346354..2f09910530ac 100644 --- a/src/Tests/dotnet-workload-repair.Tests/GivenDotnetWorkloadRepair.cs +++ b/src/Tests/dotnet-workload-repair.Tests/GivenDotnetWorkloadRepair.cs @@ -28,7 +28,7 @@ public class GivenDotnetWorkloadRepair : SdkTest public GivenDotnetWorkloadRepair(ITestOutputHelper log) : base(log) { _reporter = new BufferedReporter(); - _parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload repair"); + _parseResult = Parser.Instance.Parse("dotnet workload repair"); _manifestPath = Path.Combine(_testAssetsManager.GetAndValidateTestProjectDirectory("SampleManifest"), "Sample.json"); } @@ -61,7 +61,7 @@ public void GivenExtraPacksInstalledRepairGarbageCollects() var installingWorkload = "xamarin-android"; // Install a workload - var installParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); + var installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); var installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); installCommand.Execute(); @@ -99,7 +99,7 @@ public void GivenMissingPacksRepairFixesInstall() var installingWorkload = "xamarin-android"; // Install a workload - var installParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); + var installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); var installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); installCommand.Execute(); diff --git a/src/Tests/dotnet-workload-restore.Tests/DiscoverAllProjectsTests.cs b/src/Tests/dotnet-workload-restore.Tests/DiscoverAllProjectsTests.cs new file mode 100644 index 000000000000..393c1a1b2a86 --- /dev/null +++ b/src/Tests/dotnet-workload-restore.Tests/DiscoverAllProjectsTests.cs @@ -0,0 +1,73 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using FluentAssertions; +using Microsoft.NET.TestFramework; +using Xunit; +using Xunit.Abstractions; +using Microsoft.NET.TestFramework.Assertions; +using Microsoft.DotNet.Workloads.Workload.List; +using System.CommandLine.Parsing; +using Microsoft.NET.TestFramework.Utilities; +using System.Collections.Generic; +using System.IO; +using Microsoft.DotNet.Workloads.Workload.Restore; +using Microsoft.NET.Sdk.WorkloadManifestReader; + +namespace Microsoft.DotNet.Cli.Workload.Restore.Tests +{ + public class DiscoverAllProjectsTests : SdkTest + { + public DiscoverAllProjectsTests(ITestOutputHelper log) : base(log) + { + } + + [Fact] + public void WhenCallWithNoSlnOrProjectArgumentItCollectProjectsFromSolution() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .WithSource() + .Path; + + var result = WorkloadRestoreCommand.DiscoverAllProjects(projectDirectory); + result.Should().Contain(f => Path.GetFileName(f) == "App.csproj"); + } + + [Fact] + public void WhenCallWithSlnOrProjectArgumentItCollectProjectsFromSolution() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .WithSource() + .Path; + + var result = + WorkloadRestoreCommand.DiscoverAllProjects("", + new[] + { + Path.Combine(projectDirectory, "App.sln"), + Path.Combine(projectDirectory, "Lib", "Lib.csproj") + }); + + // current directory is ignored + result.Should().Contain(f => Path.GetFileName(f) == "App.csproj", "from checking the sln file"); + result.Should().Contain(f => Path.GetFileName(f) == "Lib.csproj", "from directly pass in"); + } + + [Fact] + public void WhenCallWithDirectoryWith2ProjectItShouldFindAll() + { + var projectDirectory = _testAssetsManager + .CopyTestAsset("TestAppWithSlnAndCsprojFiles") + .WithSource() + .Path; + + var result = + WorkloadRestoreCommand.DiscoverAllProjects(Path.Combine(projectDirectory, "Multiple")); + + result.Should().Contain(f => Path.GetFileName(f) == "First.csproj"); + result.Should().Contain(f => Path.GetFileName(f) == "Second.csproj"); + } + } +} diff --git a/src/Tests/dotnet-workload-search.Tests/GivenDotnetWorkloadSearch.cs b/src/Tests/dotnet-workload-search.Tests/GivenDotnetWorkloadSearch.cs index 62981a47a524..68292c811f7c 100644 --- a/src/Tests/dotnet-workload-search.Tests/GivenDotnetWorkloadSearch.cs +++ b/src/Tests/dotnet-workload-search.Tests/GivenDotnetWorkloadSearch.cs @@ -21,15 +21,15 @@ public class GivenDotnetWorkloadSearch : SdkTest private readonly IEnumerable _avaliableWorkloads = new List() { - new WorkloadDefinition(new WorkloadId("mock-workload-1"), false, null, WorkloadDefinitionKind.Dev, new List(), + new WorkloadDefinition(new WorkloadId("mock-workload-1"), false, null, WorkloadDefinitionKind.Dev, new List(), new List(), new List()), - new WorkloadDefinition(new WorkloadId("mock-workload-2"), false, string.Empty, WorkloadDefinitionKind.Build, null, + new WorkloadDefinition(new WorkloadId("mock-workload-2"), false, string.Empty, WorkloadDefinitionKind.Build, null, new List(), new List() { "platform1", "platform2" }), - new WorkloadDefinition(new WorkloadId("mock-workload-3"), true, "Fake description 1", WorkloadDefinitionKind.Dev, + new WorkloadDefinition(new WorkloadId("mock-workload-3"), true, "Fake description 1", WorkloadDefinitionKind.Dev, new List() { new WorkloadId("mock-workload-2") }, new List(), new List()), - new WorkloadDefinition(new WorkloadId("fake-workload-1"), true, null, WorkloadDefinitionKind.Build, + new WorkloadDefinition(new WorkloadId("fake-workload-1"), true, null, WorkloadDefinitionKind.Build, new List(), new List(), null), - new WorkloadDefinition(new WorkloadId("fake-workload-2"), false, "Fake description 2", WorkloadDefinitionKind.Dev, null, + new WorkloadDefinition(new WorkloadId("fake-workload-2"), false, "Fake description 2", WorkloadDefinitionKind.Dev, null, new List(), new List()) }; @@ -42,7 +42,7 @@ public GivenDotnetWorkloadSearch(ITestOutputHelper log) : base(log) public void GivenNoWorkloadsAreInstalledSearchIsEmpty() { _reporter.Clear(); - var parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload search"); + var parseResult = Parser.Instance.Parse("dotnet workload search"); var workloadResolver = new MockWorkloadResolver(new List()); var command = new WorkloadSearchCommand(parseResult, _reporter, workloadResolver, "6.0.100"); command.Execute(); @@ -54,7 +54,7 @@ public void GivenNoWorkloadsAreInstalledSearchIsEmpty() public void GivenNoStubIsProvidedSearchShowsAllWorkloads() { _reporter.Clear(); - var parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload search"); + var parseResult = Parser.Instance.Parse("dotnet workload search"); var workloadResolver = new MockWorkloadResolver(_avaliableWorkloads); var command = new WorkloadSearchCommand(parseResult, _reporter, workloadResolver, "6.0.100"); command.Execute(); @@ -78,7 +78,7 @@ public void GivenNoStubIsProvidedSearchShowsAllWorkloads() public void GivenDetailedVerbositySearchShowsAllColumns() { _reporter.Clear(); - var parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload search -v d"); + var parseResult = Parser.Instance.Parse("dotnet workload search -v d"); var workloadResolver = new MockWorkloadResolver(_avaliableWorkloads); var command = new WorkloadSearchCommand(parseResult, _reporter, workloadResolver, "6.0.100"); command.Execute(); @@ -102,7 +102,7 @@ public void GivenDetailedVerbositySearchShowsAllColumns() public void GivenStubIsProvidedSearchShowsAllMatchingWorkloads() { _reporter.Clear(); - var parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload search mock"); + var parseResult = Parser.Instance.Parse("dotnet workload search mock"); var workloadResolver = new MockWorkloadResolver(_avaliableWorkloads); var command = new WorkloadSearchCommand(parseResult, _reporter, workloadResolver, "6.0.100"); command.Execute(); @@ -123,7 +123,7 @@ public void GivenStubIsProvidedSearchShowsAllMatchingWorkloads() public void GivenSearchResultsAreOrdered() { _reporter.Clear(); - var parseResult = Parser.GetWorkloadsInstance.Parse("dotnet workload search"); + var parseResult = Parser.Instance.Parse("dotnet workload search"); var workloadResolver = new MockWorkloadResolver(_avaliableWorkloads); var command = new WorkloadSearchCommand(parseResult, _reporter, workloadResolver, "6.0.100"); command.Execute(); diff --git a/src/Tests/dotnet-workload-uninstall.Tests/GivenDotnetWorkloadUninstall.cs b/src/Tests/dotnet-workload-uninstall.Tests/GivenDotnetWorkloadUninstall.cs index cf29bf4653d2..04124718ef47 100644 --- a/src/Tests/dotnet-workload-uninstall.Tests/GivenDotnetWorkloadUninstall.cs +++ b/src/Tests/dotnet-workload-uninstall.Tests/GivenDotnetWorkloadUninstall.cs @@ -148,7 +148,7 @@ private void InstallWorkload(string installingWorkload, string testDirectory, st var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot }); var nugetDownloader = new MockNuGetPackageDownloader(dotnetRoot); var manifestUpdater = new MockWorkloadManifestUpdater(); - var installParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); + var installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); var installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); installCommand.Execute(); @@ -159,7 +159,7 @@ private void UninstallWorkload(string uninstallingWorkload, string testDirectory var dotnetRoot = Path.Combine(testDirectory, "dotnet"); var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot }); var nugetDownloader = new MockNuGetPackageDownloader(dotnetRoot); - var uninstallParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "uninstall", uninstallingWorkload }); + var uninstallParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "uninstall", uninstallingWorkload }); var uninstallCommand = new WorkloadUninstallCommand(uninstallParseResult, reporter: _reporter, workloadResolver, nugetDownloader, dotnetDir: dotnetRoot, version: sdkFeatureVersion); uninstallCommand.Execute(); diff --git a/src/Tests/dotnet-workload-update.Tests/GivenDotnetWorkloadUpdate.cs b/src/Tests/dotnet-workload-update.Tests/GivenDotnetWorkloadUpdate.cs index 793b410b543a..b2a28ebf7eae 100644 --- a/src/Tests/dotnet-workload-update.Tests/GivenDotnetWorkloadUpdate.cs +++ b/src/Tests/dotnet-workload-update.Tests/GivenDotnetWorkloadUpdate.cs @@ -34,7 +34,7 @@ public GivenDotnetWorkloadUpdate(ITestOutputHelper log) : base(log) { _reporter = new BufferedReporter(); _manifestPath = Path.Combine(_testAssetsManager.GetAndValidateTestProjectDirectory("SampleManifest"), "Sample.json"); - _parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update" }); + _parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update" }); } [Fact] @@ -49,7 +49,7 @@ public void GivenWorkloadUpdateItRemovesOldPacksAfterInstall() var installingWorkload = "xamarin-android"; // Install a workload - var installParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); + var installParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", installingWorkload }); var installCommand = new WorkloadInstallCommand(installParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); installCommand.Execute(); @@ -83,7 +83,7 @@ public void GivenWorkloadUpdateItRemovesOldPacksAfterInstall() new string[] { dotnetRoot }); // Update workload - var updateParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update" }); + var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update" }); var updateCommand = new WorkloadUpdateCommand(updateParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); updateCommand.Execute(); @@ -142,7 +142,7 @@ public void GivenWorkloadUpdateAcrossFeatureBandsItUpdatesPacks() File.Create(Path.Combine(dotnetRoot, "metadata", "workloads", sdkFeatureVersion, "InstalledWorkloads", installingWorkload)); // Update workload (without installing any workloads to this feature band) - var updateParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--from-previous-sdk" }); + var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--from-previous-sdk" }); var updateCommand = new WorkloadUpdateCommand(updateParseResult, reporter: _reporter, workloadResolver: workloadResolver, nugetPackageDownloader: nugetDownloader, workloadManifestUpdater: manifestUpdater, userHome: testDirectory, version: sdkFeatureVersion, dotnetDir: dotnetRoot, tempDirPath: testDirectory); updateCommand.Execute(); @@ -195,7 +195,7 @@ public void GivenWorkloadUpdateItCanDownloadToOfflineCache() { var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") }; var cachePath = Path.Combine(_testAssetsManager.CreateTestDirectory(identifier: "cachePath").Path, "mockCachePath"); - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--download-to-cache", cachePath }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--download-to-cache", cachePath }); (_, var command, var installer, _, var manifestUpdater, _) = GetTestInstallers(parseResult, installedWorkloads: mockWorkloadIds, includeInstalledPacks: true); command.Execute(); @@ -214,7 +214,7 @@ public void GivenWorkloadUpdateItCanInstallFromOfflineCache() { var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") }; var cachePath = "mockCachePath"; - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--from-cache", cachePath }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--from-cache", cachePath }); (_, var command, var installer, _, _, var nugetDownloader) = GetTestInstallers(parseResult, installedWorkloads: mockWorkloadIds); command.Execute(); @@ -230,7 +230,7 @@ public void GivenWorkloadUpdateItCanInstallFromOfflineCache() public void GivenWorkloadUpdateItPrintsDownloadUrls() { var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") }; - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--print-download-link-only" }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--print-download-link-only" }); (_, var command, _, _, _, _) = GetTestInstallers(parseResult, installedWorkloads: mockWorkloadIds, includeInstalledPacks: true); command.Execute(); @@ -247,8 +247,8 @@ public void GivenWorkloadUpdateAcrossFeatureBandsItErrorsWhenManifestsDoNotExist { var testDirectory = _testAssetsManager.CreateTestDirectory().Path; var dotnetRoot = Path.Combine(testDirectory, "dotnet"); - var updateParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--sdk-version", "7.0.100" }); - + var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--sdk-version", "7.0.100" }); + var exceptionThrown = Assert.Throws(() => new WorkloadUpdateCommand(updateParseResult, reporter: _reporter, dotnetDir: dotnetRoot)); exceptionThrown.Message.Should().Contain("No manifests exist"); } @@ -258,7 +258,7 @@ public void GivenWorkloadUpdateAcrossFeatureBandsItErrorsWhenUnableToReadManifes { var testDirectory = _testAssetsManager.CreateTestDirectory().Path; var dotnetRoot = Path.Combine(testDirectory, "dotnet"); - var updateParseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--sdk-version", "7.0.100" }); + var updateParseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--sdk-version", "7.0.100" }); // Write manifest of "new" format that we don't recognize Directory.CreateDirectory(Path.Combine(dotnetRoot, "sdk-manifests", "7.0.100", "mock.workload")); @@ -279,7 +279,7 @@ public void GivenWorkloadUpdateAcrossFeatureBandsItErrorsWhenUnableToReadManifes [Fact] public void GivenOnlyUpdateAdManifestItSucceeds() { - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--advertising-manifests-only" }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--advertising-manifests-only" }); (_, var command, _, _, var manifestUpdater, _) = GetTestInstallers(parseResult); command.Execute(); @@ -289,7 +289,7 @@ public void GivenOnlyUpdateAdManifestItSucceeds() [Fact] public void GivenPrintRollbackDefinitionItIncludesAllInstalledManifests() { - var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--print-rollback" }); + var parseResult = Parser.Instance.Parse(new string[] { "dotnet", "workload", "update", "--print-rollback" }); (_, var updateCommand, _, _, _, _) = GetTestInstallers(parseResult); updateCommand.Execute(); diff --git a/src/Tests/dotnet.Tests/dotnet.Tests.csproj b/src/Tests/dotnet.Tests/dotnet.Tests.csproj index ae435e708522..ab71536ca689 100644 --- a/src/Tests/dotnet.Tests/dotnet.Tests.csproj +++ b/src/Tests/dotnet.Tests/dotnet.Tests.csproj @@ -47,6 +47,7 @@ +