From 3f6a212106aae8c734f4d823c3df094e08369231 Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Wed, 16 Oct 2024 11:43:13 +0300 Subject: [PATCH] Use DotNet command template --- .../CSharpInteractive.HostApi.csproj | 8 +- CSharpInteractive.HostApi/CommandLines.cs | 68 + CSharpInteractive.HostApi/CommandLines.tt | 6 +- .../DotNetBuildServer.cs | 3 +- ...pleDotNetCommands.cs => DotNetCommands.cs} | 350 +++--- CSharpInteractive.HostApi/DotNetCommands.tt | 1096 +++++++++++++++++ CSharpInteractive.HostApi/DotNetLanguage.cs | 11 +- .../DotNetNewListColumn.cs | 6 +- .../DotNetRollForward.cs | 3 +- .../DotNetTemplateType.cs | 3 +- .../DotNetTerminalLogger.cs | 3 +- .../DotNet/DotNetCommandLineExtensions.cs | 17 +- .../NuGetAuthenticationType.cs | 6 +- .../NuGetCertificateAlgorithm.cs | 14 +- CSharpInteractive.HostApi/NuGetListFormat.cs | 3 +- .../SimpleDotNetCommands.tt | 1096 ----------------- CSharpInteractive.Tests/README_TEMPLATE.md | 142 ++- CSharpInteractive.Tests/README_TEMPLATE.tt | 2 +- 18 files changed, 1501 insertions(+), 1336 deletions(-) rename CSharpInteractive.HostApi/{SimpleDotNetCommands.cs => DotNetCommands.cs} (93%) create mode 100644 CSharpInteractive.HostApi/DotNetCommands.tt delete mode 100644 CSharpInteractive.HostApi/SimpleDotNetCommands.tt diff --git a/CSharpInteractive.HostApi/CSharpInteractive.HostApi.csproj b/CSharpInteractive.HostApi/CSharpInteractive.HostApi.csproj index 74cdcfd..0ef20de 100644 --- a/CSharpInteractive.HostApi/CSharpInteractive.HostApi.csproj +++ b/CSharpInteractive.HostApi/CSharpInteractive.HostApi.csproj @@ -35,15 +35,15 @@ CommandLines.tt - - SimpleDotNetCommands.cs + + DotNetCommands.cs TextTemplatingFileGenerator - + True True - SimpleDotNetCommands.tt + DotNetCommands.tt diff --git a/CSharpInteractive.HostApi/CommandLines.cs b/CSharpInteractive.HostApi/CommandLines.cs index c3ac253..23bba28 100644 --- a/CSharpInteractive.HostApi/CommandLines.cs +++ b/CSharpInteractive.HostApi/CommandLines.cs @@ -2857,6 +2857,74 @@ public partial record DotNetNuGetWhy: ICommandLine public static DotNetNuGetWhy operator -(DotNetNuGetWhy command, IEnumerable<(string name, string value)> vars) => command.RemoveVars(vars); } +[ExcludeFromCodeCoverage] +public partial record DotNetNuConfigGet: ICommandLine +{ + /// + /// Appends an argument. + /// + /// The command to which an argument will be added. + /// Argument to add. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator +(DotNetNuConfigGet command, string arg) => command.AddArgs(arg); + + /// + /// Removes an argument by its name. + /// + /// The command to which an argument will be removed. + /// Argument to remove. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator -(DotNetNuConfigGet command, string arg) => command.RemoveArgs(arg); + + /// + /// Appends arguments. + /// + /// The command to which arguments will be added. + /// Arguments to add. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator +(DotNetNuConfigGet command, IEnumerable args) => command.AddArgs(args); + + /// + /// Removes arguments by their name. + /// + /// The command to which arguments will be removed. + /// Arguments to remove. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator -(DotNetNuConfigGet command, IEnumerable args) => command.RemoveArgs(args); + + /// + /// Appends an environment variable. + /// + /// The command to which an environment variable will be added. + /// Environment variable to add. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator +(DotNetNuConfigGet command, (string name, string value) var) => command.AddVars(var); + + /// + /// Removes environment variable by its name and value. + /// + /// The command to which an environment variable will be removed. + /// Environment variable to remove. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator -(DotNetNuConfigGet command, (string name, string value) var) => command.RemoveVars(var); + + /// + /// Appends environment variables. + /// + /// The command to which environment variables will be added. + /// Environment variables to add. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator +(DotNetNuConfigGet command, IEnumerable<(string name, string value)> vars) => command.AddVars(vars); + + /// + /// Removes environment variables by their name and value. + /// + /// The command to which environment variables will be removed. + /// environment variables to remove. + /// Returns a new command with the corresponding changes. + public static DotNetNuConfigGet operator -(DotNetNuConfigGet command, IEnumerable<(string name, string value)> vars) => command.RemoveVars(vars); +} + [ExcludeFromCodeCoverage] public partial record DotNetPack: ICommandLine { diff --git a/CSharpInteractive.HostApi/CommandLines.tt b/CSharpInteractive.HostApi/CommandLines.tt index 47a4e10..b6df9b3 100644 --- a/CSharpInteractive.HostApi/CommandLines.tt +++ b/CSharpInteractive.HostApi/CommandLines.tt @@ -1,7 +1,4 @@ -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ import namespace="System.Text" #> -// ReSharper disable InconsistentNaming +// ReSharper disable InconsistentNaming namespace HostApi; <# @@ -51,6 +48,7 @@ namespace HostApi; "DotNetNuGetTrustSource", "DotNetNuGetSign", "DotNetNuGetWhy", + "DotNetNuConfigGet", "DotNetPack", "DotNetPublish", "DotNetRestore", diff --git a/CSharpInteractive.HostApi/DotNetBuildServer.cs b/CSharpInteractive.HostApi/DotNetBuildServer.cs index 6b332cf..7e9baac 100644 --- a/CSharpInteractive.HostApi/DotNetBuildServer.cs +++ b/CSharpInteractive.HostApi/DotNetBuildServer.cs @@ -27,7 +27,8 @@ public enum DotNetBuildServer internal static class DotNetBuildServerExtensions { - public static string[] ToArgs(this IEnumerable servers, string name) => + [SuppressMessage("ReSharper", "UnusedParameter.Global")] + public static string[] ToArgs(this IEnumerable servers, string name, string collectionSeparator) => servers.Select(server => server switch { DotNetBuildServer.MSBuild => "--msbuild", diff --git a/CSharpInteractive.HostApi/SimpleDotNetCommands.cs b/CSharpInteractive.HostApi/DotNetCommands.cs similarity index 93% rename from CSharpInteractive.HostApi/SimpleDotNetCommands.cs rename to CSharpInteractive.HostApi/DotNetCommands.cs index 054b52c..28e200d 100644 --- a/CSharpInteractive.HostApi/SimpleDotNetCommands.cs +++ b/CSharpInteractive.HostApi/DotNetCommands.cs @@ -1,4 +1,5 @@ -// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Global +// ReSharper disable InconsistentNaming namespace HostApi; using Internal.DotNet; @@ -61,10 +62,10 @@ public IStartInfo GetStartInfo(IHost host) .WithWorkingDirectory(WorkingDirectory) .WithVars(Vars.ToArray()) .AddNotEmptyArgs(PathToApplication.ToArg()) - .AddArgs(AdditionalProbingPaths.ToArgs("--additionalprobingpath")) - .AddArgs(AdditionalDeps.ToArgs("--additional-deps")) - .AddArgs(FxVersion.ToArgs("--fx-version")) - .AddArgs(RollForward.ToArgs("--roll-forward")) + .AddArgs(AdditionalProbingPaths.ToArgs("--additionalprobingpath", "")) + .AddArgs(AdditionalDeps.ToArgs("--additional-deps", "")) + .AddArgs(FxVersion.ToArgs("--fx-version", "")) + .AddArgs(RollForward.ToArgs("--roll-forward", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -138,12 +139,12 @@ public IStartInfo GetStartInfo(IHost host) .WithVars(Vars.ToArray()) .AddArgs("exec") .AddNotEmptyArgs(PathToApplication.ToArg()) - .AddArgs(AdditionalProbingPaths.ToArgs("--additionalprobingpath")) - .AddArgs(DepsFile.ToArgs("--depsfile")) - .AddArgs(AdditionalDeps.ToArgs("--additional-deps")) - .AddArgs(FxVersion.ToArgs("--fx-version")) - .AddArgs(RollForward.ToArgs("--roll-forward")) - .AddArgs(RuntimeConfig.ToArgs("--runtimeconfig")) + .AddArgs(AdditionalProbingPaths.ToArgs("--additionalprobingpath", "")) + .AddArgs(DepsFile.ToArgs("--depsfile", "")) + .AddArgs(AdditionalDeps.ToArgs("--additional-deps", "")) + .AddArgs(FxVersion.ToArgs("--fx-version", "")) + .AddArgs(RollForward.ToArgs("--roll-forward", "")) + .AddArgs(RuntimeConfig.ToArgs("--runtimeconfig", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -221,10 +222,10 @@ public IStartInfo GetStartInfo(IHost host) .AddNotEmptyArgs(Project.ToArg()) .AddArgs("package") .AddNotEmptyArgs(PackageName.ToArg()) - .AddArgs(Sources.ToArgs("--source")) - .AddArgs(Framework.ToArgs("--framework")) - .AddArgs(PackageDirectory.ToArgs("--package-directory")) - .AddArgs(Version.ToArgs("--version")) + .AddArgs(Sources.ToArgs("--source", "")) + .AddArgs(Framework.ToArgs("--framework", "")) + .AddArgs(PackageDirectory.ToArgs("--package-directory", "")) + .AddArgs(Version.ToArgs("--version", "")) .AddBooleanArgs( ("--no-restore", NoRestore), ("--prerelease", Prerelease), @@ -309,10 +310,10 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("list") .AddNotEmptyArgs(Project.ToArg()) .AddArgs("package") - .AddArgs(Frameworks.ToArgs("--framework")) - .AddArgs(Sources.ToArgs("--source")) - .AddArgs(Config.ToArgs("--config")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Frameworks.ToArgs("--framework", "")) + .AddArgs(Sources.ToArgs("--source", "")) + .AddArgs(Config.ToArgs("--config", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--deprecated", Deprecated), ("--highest-minor", HighestMinor), @@ -451,8 +452,8 @@ public IStartInfo GetStartInfo(IHost host) .AddNotEmptyArgs(Project.ToArg()) .AddArgs("reference") .AddNotEmptyArgs(References.ToArray().ToArg()) - .AddArgs(References.ToArgs("--source")) - .AddArgs(Framework.ToArgs("--framework")) + .AddArgs(References.ToArgs("--source", "")) + .AddArgs(Framework.ToArgs("--framework", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -581,8 +582,8 @@ public IStartInfo GetStartInfo(IHost host) .AddNotEmptyArgs(Project.ToArg()) .AddArgs("reference") .AddNotEmptyArgs(References.ToArray().ToArg()) - .AddArgs(References.ToArgs("--source")) - .AddArgs(Framework.ToArgs("--framework")) + .AddArgs(References.ToArgs("--source", "")) + .AddArgs(Framework.ToArgs("--framework", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -697,17 +698,17 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("build") .AddNotEmptyArgs(Project.ToArg()) .AddMSBuildLoggers(host, Verbosity) - .AddArgs(Sources.ToArgs("--source")) - .AddArgs(Arch.ToArgs("--arch")) - .AddArgs(ArtifactsPath.ToArgs("--artifacts-path")) - .AddArgs(Configuration.ToArgs("--configuration")) - .AddArgs(Framework.ToArgs("--framework")) - .AddArgs(Output.ToArgs("--output")) - .AddArgs(OS.ToArgs("--os")) - .AddArgs(Runtime.ToArgs("--runtime")) - .AddArgs(TerminalLogger.ToArgs("--tl")) - .AddArgs(Verbosity.ToArgs("--verbosity")) - .AddArgs(VersionSuffix.ToArgs("--version-suffix")) + .AddArgs(Sources.ToArgs("--source", "")) + .AddArgs(Arch.ToArgs("--arch", "")) + .AddArgs(ArtifactsPath.ToArgs("--artifacts-path", "")) + .AddArgs(Configuration.ToArgs("--configuration", "")) + .AddArgs(Framework.ToArgs("--framework", "")) + .AddArgs(Output.ToArgs("--output", "")) + .AddArgs(OS.ToArgs("--os", "")) + .AddArgs(Runtime.ToArgs("--runtime", "")) + .AddArgs(TerminalLogger.ToArgs("--tl", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) + .AddArgs(VersionSuffix.ToArgs("--version-suffix", "")) .AddBooleanArgs( ("--disable-build-servers", DisableBuildServers), ("--force", Force), @@ -778,7 +779,7 @@ public IStartInfo GetStartInfo(IHost host) .WithVars(Vars.ToArray()) .AddArgs("build-server") .AddArgs("shutdown") - .AddArgs(Servers.ToArgs("")) + .AddArgs(Servers.ToArgs("", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -859,13 +860,13 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("clean") .AddNotEmptyArgs(Project.ToArg()) .AddMSBuildLoggers(host, Verbosity) - .AddArgs(ArtifactsPath.ToArgs("--artifacts-path")) - .AddArgs(Configuration.ToArgs("--configuration")) - .AddArgs(Framework.ToArgs("--framework")) - .AddArgs(Output.ToArgs("--output")) - .AddArgs(Runtime.ToArgs("--runtime")) - .AddArgs(TerminalLogger.ToArgs("--tl")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(ArtifactsPath.ToArgs("--artifacts-path", "")) + .AddArgs(Configuration.ToArgs("--configuration", "")) + .AddArgs(Framework.ToArgs("--framework", "")) + .AddArgs(Output.ToArgs("--output", "")) + .AddArgs(Runtime.ToArgs("--runtime", "")) + .AddArgs(TerminalLogger.ToArgs("--tl", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--nologo", NoLogo), ("--diagnostics", Diagnostics) @@ -952,9 +953,9 @@ public IStartInfo GetStartInfo(IHost host) .WithVars(Vars.ToArray()) .AddArgs("dev-certs") .AddArgs("https") - .AddArgs(ExportPath.ToArgs("--export-path")) - .AddArgs(Format.ToArgs("--format")) - .AddArgs(Import.ToArgs("--import")) + .AddArgs(ExportPath.ToArgs("--export-path", "")) + .AddArgs(Format.ToArgs("--format", "")) + .AddArgs(Import.ToArgs("--import", "")) .AddBooleanArgs( ("--check", Check), ("--clean", Clean), @@ -1041,12 +1042,12 @@ public IStartInfo GetStartInfo(IHost host) .WithVars(Vars.ToArray()) .AddArgs("new") .AddNotEmptyArgs(TemplateName.ToArg()) - .AddArgs(Language.ToArgs("--language")) - .AddArgs(Name.ToArgs("--name")) - .AddArgs(Framework.ToArgs("--framework")) - .AddArgs(Output.ToArgs("--output")) - .AddArgs(Project.ToArgs("--project")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Language.ToArgs("--language", "")) + .AddArgs(Name.ToArgs("--name", "")) + .AddArgs(Framework.ToArgs("--framework", "")) + .AddArgs(Output.ToArgs("--output", "")) + .AddArgs(Project.ToArgs("--project", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--dry-run", DryRun), ("--force", Force), @@ -1132,14 +1133,14 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("new") .AddArgs("list") .AddNotEmptyArgs(TemplateName.ToArg()) - .AddArgs(Columns.ToArgs("--columns")) - .AddArgs(Author.ToArgs("--author")) - .AddArgs(Language.ToArgs("--language")) - .AddArgs(Output.ToArgs("--output")) - .AddArgs(Project.ToArgs("--project")) - .AddArgs(Tag.ToArgs("--tag")) - .AddArgs(Type.ToArgs("--type")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Columns.ToArgs("--columns", "")) + .AddArgs(Author.ToArgs("--author", "")) + .AddArgs(Language.ToArgs("--language", "")) + .AddArgs(Output.ToArgs("--output", "")) + .AddArgs(Project.ToArgs("--project", "")) + .AddArgs(Tag.ToArgs("--tag", "")) + .AddArgs(Type.ToArgs("--type", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--columns-all", ColumnsAll), ("--ignore-constraints", IgnoreConstraints), @@ -1220,13 +1221,13 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("new") .AddArgs("search") .AddNotEmptyArgs(TemplateName.ToArg()) - .AddArgs(Columns.ToArgs("--columns")) - .AddArgs(Author.ToArgs("--author")) - .AddArgs(Language.ToArgs("--language")) - .AddArgs(Package.ToArgs("--package")) - .AddArgs(Tag.ToArgs("--tag")) - .AddArgs(Type.ToArgs("--type")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Columns.ToArgs("--columns", "")) + .AddArgs(Author.ToArgs("--author", "")) + .AddArgs(Language.ToArgs("--language", "")) + .AddArgs(Package.ToArgs("--package", "")) + .AddArgs(Tag.ToArgs("--tag", "")) + .AddArgs(Type.ToArgs("--type", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--columns-all", ColumnsAll), ("--diagnostics", Diagnostics) @@ -1296,8 +1297,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("new") .AddArgs("details") .AddNotEmptyArgs(TemplateName.ToArg()) - .AddArgs(Sources.ToArgs("--add-source")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Sources.ToArgs("--add-source", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--force", Force), ("--diagnostics", Diagnostics) @@ -1367,8 +1368,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("new") .AddArgs("install") .AddNotEmptyArgs(Package.ToArg()) - .AddArgs(Sources.ToArgs("--add-source")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Sources.ToArgs("--add-source", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--force", Force), ("--diagnostics", Diagnostics) @@ -1434,7 +1435,7 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("new") .AddArgs("uninstall") .AddNotEmptyArgs(Package.ToArg()) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -1502,8 +1503,8 @@ public IStartInfo GetStartInfo(IHost host) .WithVars(Vars.ToArray()) .AddArgs("new") .AddArgs("update") - .AddArgs(Sources.ToArgs("--add-source")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Sources.ToArgs("--add-source", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--check-only", CheckOnly), ("--dry-run", DryRun), @@ -1580,8 +1581,8 @@ public IStartInfo GetStartInfo(IHost host) .AddNotEmptyArgs(PackageName.ToArg()) .AddNotEmptyArgs(PackageVersion.ToArg()) .AddArgs("--non-interactive") - .AddArgs(ApiKey.ToArgs("--api-key")) - .AddArgs(Source.ToArgs("--source")) + .AddArgs(ApiKey.ToArgs("--api-key", "")) + .AddArgs(Source.ToArgs("--source", "")) .AddBooleanArgs( ("--force-english-output", ForceEnglishOutput), ("--no-service-endpoint", NoServiceEndpoint), @@ -1800,12 +1801,12 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("nuget") .AddArgs("push") .AddNotEmptyArgs(Package.ToArg()) - .AddArgs(ApiKey.ToArgs("--api-key")) - .AddArgs(Source.ToArgs("--source")) - .AddArgs(SymbolApiKey.ToArgs("--symbol-api-key")) - .AddArgs(SymbolSource.ToArgs("--symbol-source")) - .AddArgs(Timeout.ToArgs("--timeout")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(ApiKey.ToArgs("--api-key", "")) + .AddArgs(Source.ToArgs("--source", "")) + .AddArgs(SymbolApiKey.ToArgs("--symbol-api-key", "")) + .AddArgs(SymbolSource.ToArgs("--symbol-source", "")) + .AddArgs(Timeout.ToArgs("--timeout", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--disable-buffering", DisableBuffering), ("--force-english-output", ForceEnglishOutput), @@ -1888,11 +1889,11 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("add") .AddArgs("source") .AddNotEmptyArgs(PackageSourcePath.ToArg()) - .AddArgs(ValidAuthenticationTypes.ToArgs("--valid-authentication-types")) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Name.ToArgs("--name")) - .AddArgs(Password.ToArgs("--password")) - .AddArgs(Username.ToArgs("--username")) + .AddArgs(ValidAuthenticationTypes.ToArgs("--valid-authentication-types", "")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Name.ToArgs("--name", "")) + .AddArgs(Password.ToArgs("--password", "")) + .AddArgs(Username.ToArgs("--username", "")) .AddBooleanArgs( ("--allow-insecure-connections", AllowInsecureConnections), ("--store-password-in-clear-text", StorePasswordInClearText), @@ -1960,7 +1961,7 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("disable") .AddArgs("source") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(ConfigFile.ToArgs("--configfile")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2026,7 +2027,7 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("enable") .AddArgs("source") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(ConfigFile.ToArgs("--configfile")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2091,8 +2092,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("nuget") .AddArgs("list") .AddArgs("source") - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Format.ToArgs("--format")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Format.ToArgs("--format", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2158,7 +2159,7 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("remove") .AddArgs("source") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(ConfigFile.ToArgs("--configfile")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2234,10 +2235,11 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("update") .AddArgs("source") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(ValidAuthenticationTypes.ToArgs("--valid-authentication-types")) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Password.ToArgs("--password")) - .AddArgs(Username.ToArgs("--username")) + .AddArgs(ValidAuthenticationTypes.ToArgs("--valid-authentication-types", "")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Password.ToArgs("--password", "")) + .AddArgs(Source.ToArgs("--source", "")) + .AddArgs(Username.ToArgs("--username", "")) .AddBooleanArgs( ("--store-password-in-clear-text", StorePasswordInClearText), ("--diagnostics", Diagnostics) @@ -2309,10 +2311,10 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("nuget") .AddArgs("verify") .AddNotEmptyArgs(Packages.ToArray().ToArg()) - .AddArgs(Packages.ToArgs("")) - .AddArgs(Fingerprints.ToArgs("--certificate-fingerprint")) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Packages.ToArgs("", "")) + .AddArgs(Fingerprints.ToArgs("--certificate-fingerprint", "")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--all", All), ("--diagnostics", Diagnostics) @@ -2378,8 +2380,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("nuget") .AddArgs("trust") .AddArgs("list") - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2444,8 +2446,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("trust") .AddArgs("sync") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2510,8 +2512,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("trust") .AddArgs("remove") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2581,8 +2583,8 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("author") .AddNotEmptyArgs(Name.ToArg()) .AddNotEmptyArgs(Package.ToArg()) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--allow-untrusted-root", AllowUntrustedRoot), ("--diagnostics", Diagnostics) @@ -2614,7 +2616,7 @@ public IStartInfo GetStartInfo(IHost host) public partial record DotNetNuGetTrustRepository( IEnumerable Args, IEnumerable<(string name, string value)> Vars, - IReadOnlyCollection Owners, + IEnumerable Owners, string Name = "", string Package = "", bool? AllowUntrustedRoot = default, @@ -2655,9 +2657,9 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("repository") .AddNotEmptyArgs(Name.ToArg()) .AddNotEmptyArgs(Package.ToArg()) - .AddArgs(Owners.ToArgs("--owners")) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Owners.ToArgs("--owners", ",")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--allow-untrusted-root", AllowUntrustedRoot), ("--diagnostics", Diagnostics) @@ -2730,9 +2732,9 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("certificate") .AddNotEmptyArgs(Name.ToArg()) .AddNotEmptyArgs(Fingerprint.ToArg()) - .AddArgs(Algorithm.ToArgs("--algorithm")) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Algorithm.ToArgs("--algorithm", "")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--allow-untrusted-root", AllowUntrustedRoot), ("--diagnostics", Diagnostics) @@ -2763,7 +2765,7 @@ public IStartInfo GetStartInfo(IHost host) public partial record DotNetNuGetTrustSource( IEnumerable Args, IEnumerable<(string name, string value)> Vars, - IReadOnlyCollection Owners, + IEnumerable Owners, string Name = "", string ConfigFile = "", string SourceUrl = "", @@ -2802,10 +2804,10 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("trust") .AddArgs("source") .AddNotEmptyArgs(Name.ToArg()) - .AddArgs(Owners.ToArgs("--owners")) - .AddArgs(ConfigFile.ToArgs("--configfile")) - .AddArgs(SourceUrl.ToArgs("--source-url")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Owners.ToArgs("--owners", ",")) + .AddArgs(ConfigFile.ToArgs("--configfile", "")) + .AddArgs(SourceUrl.ToArgs("--source-url", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2892,17 +2894,17 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("nuget") .AddArgs("sign") .AddNotEmptyArgs(Packages.ToArray().ToArg()) - .AddArgs(CertificatePath.ToArgs("--certificate-path")) - .AddArgs(CertificateStoreName.ToArgs("--certificate-store-name")) - .AddArgs(CertificateStoreLocation.ToArgs("--certificate-store-location")) - .AddArgs(CertificateSubjectName.ToArgs("--certificate-subject-name")) - .AddArgs(CertificateFingerprint.ToArgs("--certificate-fingerprint")) - .AddArgs(CertificatePassword.ToArgs("--certificate-password")) - .AddArgs(HashAlgorithm.ToArgs("--hash-algorithm")) - .AddArgs(Output.ToArgs("--output")) - .AddArgs(TimestampHashAlgorithm.ToArgs("--timestamp-hash-algorithm")) - .AddArgs(TimestampingServer.ToArgs("--timestamper")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(CertificatePath.ToArgs("--certificate-path", "")) + .AddArgs(CertificateStoreName.ToArgs("--certificate-store-name", "")) + .AddArgs(CertificateStoreLocation.ToArgs("--certificate-store-location", "")) + .AddArgs(CertificateSubjectName.ToArgs("--certificate-subject-name", "")) + .AddArgs(CertificateFingerprint.ToArgs("--certificate-fingerprint", "")) + .AddArgs(CertificatePassword.ToArgs("--certificate-password", "")) + .AddArgs(HashAlgorithm.ToArgs("--hash-algorithm", "")) + .AddArgs(Output.ToArgs("--output", "")) + .AddArgs(TimestampHashAlgorithm.ToArgs("--timestamp-hash-algorithm", "")) + .AddArgs(TimestampingServer.ToArgs("--timestamper", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--overwrite", Overwrite), ("--diagnostics", Diagnostics) @@ -2971,7 +2973,7 @@ public IStartInfo GetStartInfo(IHost host) .AddArgs("why") .AddNotEmptyArgs(Project.ToArg()) .AddNotEmptyArgs(Package.ToArg()) - .AddArgs(Frameworks.ToArgs("--framework")) + .AddArgs(Frameworks.ToArgs("--framework", "")) .AddBooleanArgs( ("--diagnostics", Diagnostics) ) @@ -2982,6 +2984,75 @@ public IStartInfo GetStartInfo(IHost host) public override string ToString() => "".GetShortName(ShortName, "nuget", "why", Project.ToArg(), Package.ToArg()); } +/// +/// Gets the NuGet configuration settings that will be applied. +///

+/// This command gets the NuGet configuration settings that will be applied from the config section. +///

+///
.NET CLI command
+///
+/// Specifies the set of command line arguments to use when starting the tool. +/// Specifies the set of environment variables that apply to this process and its child processes. +/// Overrides the tool executable path. +/// Specifies the working directory for the tool to be started. +/// ALL gets all merged NuGet configuration settings from multiple NuGet configuration files that will be applied, when invoking NuGet command from the working directory path. Otherwise gets the effective value of the specified configuration settings of the config section. +/// Indicate that the NuGet configuration file path will be shown beside the configuration settings. +/// Specifies the directory to start from when listing configuration files. If not specified, the current directory is used. +/// Enables diagnostic output. +/// Specifies a short name for this operation. +[Target] +public partial record DotNetNuConfigGet( + IEnumerable Args, + IEnumerable<(string name, string value)> Vars, + string ConfigKey = "", + bool? ShowPath = default, + string Directory = "", + string ExecutablePath = "", + string WorkingDirectory = "", + bool? Diagnostics = default, + string ShortName = "") +{ + /// + /// Create a new instance of the command. + /// + /// Specifies the set of command line arguments to use when starting the tool. + public DotNetNuConfigGet(params string[] args) + : this(args, []) + { + } + + /// + /// Create a new instance of the command. + /// + public DotNetNuConfigGet() + : this([], []) + { + } + + /// + public IStartInfo GetStartInfo(IHost host) + { + if (host == null) throw new ArgumentNullException(nameof(host)); + return host.CreateCommandLine(ExecutablePath) + .WithShortName(ToString()) + .WithWorkingDirectory(WorkingDirectory) + .WithVars(Vars.ToArray()) + .AddArgs("nuget") + .AddArgs("config") + .AddArgs("get") + .AddNotEmptyArgs(ConfigKey.ToArg()) + .AddArgs(Directory.ToArgs("--working-directory", "")) + .AddBooleanArgs( + ("--show-path", ShowPath), + ("--diagnostics", Diagnostics) + ) + .AddArgs(Args.ToArray()); + } + + /// + public override string ToString() => "".GetShortName(ShortName, "nuget", "config", "get", ConfigKey.ToArg()); +} + /// /// Runs source code without any explicit compile or launch commands. ///

@@ -3074,14 +3145,14 @@ public IStartInfo GetStartInfo(IHost host) .WithVars(Vars.ToArray()) .AddArgs("run") .AddNotEmptyArgs(Project.ToArg()) - .AddArgs(Arch.ToArgs("--arch")) - .AddArgs(Configuration.ToArgs("--configuration")) - .AddArgs(Framework.ToArgs("--framework")) - .AddArgs(LaunchProfile.ToArgs("--launch-profile")) - .AddArgs(OS.ToArgs("--os")) - .AddArgs(Runtime.ToArgs("--runtime")) - .AddArgs(TerminalLogger.ToArgs("--tl")) - .AddArgs(Verbosity.ToArgs("--verbosity")) + .AddArgs(Arch.ToArgs("--arch", "")) + .AddArgs(Configuration.ToArgs("--configuration", "")) + .AddArgs(Framework.ToArgs("--framework", "")) + .AddArgs(LaunchProfile.ToArgs("--launch-profile", "")) + .AddArgs(OS.ToArgs("--os", "")) + .AddArgs(Runtime.ToArgs("--runtime", "")) + .AddArgs(TerminalLogger.ToArgs("--tl", "")) + .AddArgs(Verbosity.ToArgs("--verbosity", "")) .AddBooleanArgs( ("--force", Force), ("--no-build", NoBuild), @@ -3098,3 +3169,4 @@ public IStartInfo GetStartInfo(IHost host) public override string ToString() => "".GetShortName(ShortName, "run", Project.ToArg()); } + diff --git a/CSharpInteractive.HostApi/DotNetCommands.tt b/CSharpInteractive.HostApi/DotNetCommands.tt new file mode 100644 index 0000000..a413278 --- /dev/null +++ b/CSharpInteractive.HostApi/DotNetCommands.tt @@ -0,0 +1,1096 @@ +<#@ import namespace="System.Linq" #> +<#@ import namespace="System.Collections.Generic" #> +// ReSharper disable UnusedMember.Global +// ReSharper disable InconsistentNaming +namespace HostApi; + +<# + const string paraStart = "

"; + const string paraFinish = "

"; + const string exampleStart = ""; + const string exampleFinish = ""; + const string codeStart = ""; + const string codeFinish = ""; + + string CreateCliRef(string command) => + $"
.NET CLI command
"; + + var projectArg = new Arg("Project", "", "string", "The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown.") { IsProject = true }; + var propsArg = new Arg("Props", "--property", "IEnumerable<(string name, string value)>", "MSBuild options for setting properties.") { IsCollection = true }; + var verbosityArg = new Arg("Verbosity", "--verbosity", "DotNetVerbosity?", "Sets the verbosity level of the command. Allowed values are , , , , and . The default is . For more information, see ."); + var pathToApplicationArg = new Arg("PathToApplication", "", "string", "Specifies the path to an application .dll file to run the application. To run the application means to find and execute the entry point, which in the case of console apps is the Main method. For example, dotnet myapp. dll runs the myapp application.") { IsProject = true }; + var rollForwardArg = new Arg("RollForward", "--roll-forward", "DotNetRollForward?", "Controls how roll forward is applied to the app. The SETTING can be one of the following values. If not specified, is the default."); + var additionalProbingPathsArg = new Arg("AdditionalProbingPaths", "--additionalprobingpath", "IEnumerable", "Paths containing probing policy and assemblies to probe.") { IsCollection = true }; + var additionalDepsArg = new Arg("AdditionalDeps", "--additional-deps", "string", "Path to an additional .deps.json file. A deps.json file contains a list of dependencies, compilation dependencies, and version information used to address assembly conflicts."); + var fxVersionArg = new Arg("FxVersion", "--fx-version", "string", "Version of the .NET runtime to use to run the application."); + var frameworkArg = new Arg("Framework", "--framework", "string", "Builds and runs the app using the specified framework. The framework must be specified in the project file."); + var configurationArg = new Arg("Configuration", "--configuration", "string", "Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project."); + var runtimeArg = new Arg("Runtime", "--runtime", "string", "Specifies the target runtime to restore packages for. For a list of Runtime Identifiers (RIDs), see the RID catalog. -r short option available since .NET Core 3.0 SDK."); + var noBuildArg = new Arg("NoBuild", "--no-build", "bool?", "Doesn't build the project before running. It also implicit sets the --no-restore flag."); + var noRestoreArg = new Arg("NoRestore", "--no-restore", "bool?", "Adds a package reference without performing a restore preview and compatibility check."); + var noDependenciesArg = new Arg("NoDependencies", "--no-dependencies", "bool?", "When restoring a project with project-to-project (P2P) references, restores the root project and not the references."); + var noIncrementalArg = new Arg("NoIncremental", "--no-incremental", "bool?", "Marks the build as unsafe for incremental build. This flag turns off incremental compilation and forces a clean rebuild of the project's dependency graph."); + var noLogoArg = new Arg("NoLogo", "--nologo", "bool?", "Doesn't display the startup banner or the copyright message."); + var noSelfContainedArg = new Arg("NoSelfContained", "--no-self-contained", "bool?", "Publishes the application as a framework dependent application. A compatible .NET runtime must be installed on the target machine to run the application. Available since .NET 6 SDK."); + var selfContainedArg = new Arg("SelfContained", "--self-contained", "bool?", "Publishes the .NET runtime with the application so the runtime doesn't need to be installed on the target machine. The default is true if a runtime identifier is specified. Available since .NET 6."); + var forceArg = new Arg("Force", "--force", "bool?", "Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file."); + var archArg = new Arg("Arch", "--arch", "string", "Specifies the target architecture. This is a shorthand syntax for setting the Runtime Identifier (RID), where the provided value is combined with the default RID. For example, on a win-x64 machine, specifying --arch x86 sets the RID to win-x86. If you use this option, don't use the -r|--runtime option. Available since .NET 6 Preview 7."); + var osArg = new Arg("OS", "--os", "string", "Specifies the target operating system (OS). This is a shorthand syntax for setting the Runtime Identifier (RID), where the provided value is combined with the default RID. For example, on a win-x64 machine, specifying --os linux sets the RID to linux-x64. If you use this option, don't use the -r|--runtime option. Available since .NET 6."); + var terminalLoggerArg = new Arg("TerminalLogger", "--tl", "DotNetTerminalLogger?", "Specifies whether the terminal logger should be used for the build output."); + var artifactsPathArg = new Arg("ArtifactsPath", "--artifacts-path", "string", "All build output files from the executed command will go in subfolders under the specified path, separated by project."); + var disableBuildServersArg = new Arg("DisableBuildServers", "--disable-build-servers", "bool?", "Forces the command to ignore any persistent build servers. This option provides a consistent way to disable all use of build caching, which forces a build from scratch. A build that doesn't rely on caches is useful when the caches might be corrupted or incorrect for some reason. Available since .NET 7 SDK."); + var outputArg = new Arg("Output", "--output", "string", "Directory in which to place the built binaries. If not specified, the default path is ./bin/<configuration>/<framework>/. For projects with multiple target frameworks (via the TargetFrameworks property), you also need to define --framework when you specify this option."); + var useCurrentRuntimeArg = new Arg("UseCurrentRuntime", "--use-current-runtime", "bool?", "Sets the RuntimeIdentifier to a platform portable RuntimeIdentifier based on the one of your machine. This happens implicitly with properties that require a RuntimeIdentifier, such as SelfContained, PublishAot, PublishSelfContained, PublishSingleFile, and PublishReadyToRun. If the property is set to false, that implicit resolution will no longer occur."); + var versionSuffixArg = new Arg("VersionSuffix", "--version-suffix", "string", "Sets the value of the $(VersionSuffix) property to use when building the project. This only works if the $(Version) property isn't set. Then, $(Version) is set to the $(VersionPrefix) combined with the $(VersionSuffix), separated by a dash."); + var templateNameArg = new Arg("TemplateName", "", "string", "The template to instantiate when the command is invoked. Each template might have specific options you can pass.") { IsProject = true }; + var languageArg = new Arg("Language", "--language", "DotNetLanguage?", ""); + var ownersArg = new Arg("Owners", "--owners", "IEnumerable", "List of trusted owners to further restrict the trust of a repository.") { IsCollection = true, CollectionSeparator = ","}; + var allowUntrustedRootArg = new Arg("AllowUntrustedRoot", "--allow-untrusted-root", "bool?", "Specifies if the certificate for the trusted signer should be allowed to chain to an untrusted root. This is not recommended."); + + var commands = new Command[] + { + new( + "DotNet", + [ + "Runs a dotnet application.", + paraStart, + "You specify the path to an application .dll file to run the application. To run the application means to find and execute the entry point, which in the case of console apps is the Main method. For example, dotnet myapp.dll runs the myapp application.", + paraFinish, + CreateCliRef("dotnet") + ], + ["$PathToApplication"], + [ + additionalProbingPathsArg, + pathToApplicationArg, + additionalDepsArg, + fxVersionArg, + rollForwardArg + ] + ), + new( + "DotNetExec", + [ + "Executes a dotnet application.", + paraStart, + "You specify the path to an application .dll file to run the application. To run the application means to find and execute the entry point, which in the case of console apps is the Main method. For example, dotnet myapp.dll runs the myapp application.", + paraFinish, + CreateCliRef("dotnet") + ], + ["exec", "$PathToApplication"], + [ + additionalProbingPathsArg, + pathToApplicationArg, + new Arg("DepsFile", "--depsfile", "string", "Path to a deps.json file. A deps.json file is a configuration file that contains information about dependencies necessary to run the application. This file is generated by the .NET SDK."), + additionalDepsArg, + fxVersionArg, + rollForwardArg, + new Arg("RuntimeConfig", "--runtimeconfig", "string", "Path to a runtimeconfig.json file. A runtimeconfig.json file contains run-time settings and is typically named <applicationname>.runtimeconfig.json.") + ] + ), + new( + "DotNetAddPackage", + [ + "Adds or updates a package reference in a project file.", + paraStart, + "This command provides a convenient option to add or update a package reference in a project file. When you run the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes and the package isn't referenced in the project file, a <PackageReference> element is added to the project file. If the check passes and the package is already referenced in the project file, the <PackageReference> element is updated to the latest compatible version. After the project file is updated, dotnet restore is run.", + paraFinish, + CreateCliRef("dotnet-add-package") + ], + ["add", "$Project", "package", "$PackageName"], + [ + new Arg("Sources", "--source", "IEnumerable", "The URI of the NuGet package source to use during the restore operation.") { IsCollection = true }, + projectArg, + new Arg("PackageName", "", "string", "The package reference to add."), + frameworkArg with { Comments = "Adds a package reference only when targeting a specific framework." }, + noRestoreArg, + new Arg("PackageDirectory", "--package-directory", "string", @"The directory where to restore the packages. The default package restore location is %userprofile%\.nuget\packages on Windows and ~/.nuget/packages on macOS and Linux."), + new Arg("Prerelease", "--prerelease", "bool?", "Allows prerelease packages to be installed. Available since .NET Core 5 SDK."), + new Arg("Version", "--version", "string", "Version of the package") + ] + ), + new( + "DotNetListPackage", + [ + "Lists the package references for a project or solution.", + paraStart, + "This command provides a convenient option to list all NuGet package references for a specific project or a solution. You first need to build the project in order to have the assets needed for this command to process.", + paraFinish, + CreateCliRef("dotnet-list-package") + ], + ["list", "$Project", "package"], + [ + new Arg("Frameworks", "--framework", "IEnumerable", "Displays only the packages applicable for the specified target framework.") { IsCollection = true }, + new Arg("Sources", "--source", "IEnumerable", "The NuGet sources to use when searching for newer packages. Requires the --outdated or --deprecated option.") { IsCollection = true }, + projectArg, + new Arg("Config", "--config", "string", "The NuGet sources to use when searching for newer packages. Requires the --outdated option."), + new Arg("Deprecated", "--deprecated", "bool?", "Displays packages that have been deprecated."), + new Arg("HighestMinor", "--highest-minor", "bool?", "Considers only the packages with a matching major version number when searching for newer packages. Requires the --outdated or --deprecated option."), + new Arg("HighestPatch", "--highest-patch", "bool?", "Considers only the packages with a matching major and minor version numbers when searching for newer packages. Requires the --outdated or --deprecated option."), + new Arg("IncludePrerelease", "--include-prerelease", "bool?", "Considers packages with prerelease versions when searching for newer packages. Requires the --outdated or --deprecated option."), + new Arg("IncludeTransitive", "--include-transitive", "bool?", "Lists transitive packages, in addition to the top-level packages. When specifying this option, you get a list of packages that the top-level packages depend on."), + new Arg("Outdated", "--outdated", "bool?", "Lists packages that have newer versions available."), + verbosityArg + ] + ), + new( + "DotNetRemovePackage", + [ + "Removes package reference from a project file.", + paraStart, + "This command provides a convenient option to remove a NuGet package reference from a project.", + paraFinish, + CreateCliRef("dotnet-remove-package") + ], + ["remove", "$Project", "package", "$PackageName"], + [ + projectArg, + new Arg("PackageName", "", "string", "The package reference to add.") + ] + ), + new( + "DotNetAddReference", + [ + "Adds project-to-project (P2P) references.", + paraStart, + "This command provides a convenient option to add project references to a project. After running the command, the <ProjectReference> elements are added to the project file.", + paraFinish, + CreateCliRef("dotnet-add-reference") + ], + ["add", "$Project", "reference", "$References"], + [ + new Arg("References", "--source", "IEnumerable", "Project-to-project (P2P) references to add. Specify one or more projects. Glob patterns are supported on Unix/Linux-based systems.") { IsCollection = true }, + projectArg, + frameworkArg with { Comments = "Adds project references only when targeting a specific framework using the TFM format." } + ] + ), + new( + "DotNetListReference", + [ + "Lists project-to-project references.", + paraStart, + "This command provides a convenient option to list project references for a given project.", + paraFinish, + CreateCliRef("dotnet-list-reference") + ], + ["list", "$Project"], + [ + projectArg + ] + ), + new( + "DotNetRemoveReference", + [ + "Removes project-to-project (P2P) references.", + paraStart, + "This command provides a convenient option to remove project references from a project.", + paraFinish, + CreateCliRef("dotnet-remove-reference") + ], + ["remove", "$Project", "reference", "$References"], + [ + new Arg("References", "--source", "IEnumerable", "Project-to-project (P2P) references to remove. You can specify one or multiple projects. Glob patterns are supported on Unix/Linux based terminals.") { IsCollection = true }, + projectArg, + frameworkArg with { Comments = "Removes the reference only when targeting a specific framework using the TFM format." } + ] + ), + new( + "DotNetBuild", + [ + "Builds a project and all of its dependencies.", + paraStart, + "This command builds the project and its dependencies into a set of binaries. The binaries include the project's code in Intermediate Language (IL) files with a .dll extension. For executable projects targeting versions earlier than .NET Core 3.0, library dependencies from NuGet are typically NOT copied to the output folder. They're resolved from the NuGet global packages folder at run time. With that in mind, the product of dotnet build isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the dotnet publish command). For more information, see .NET Application Deployment.", + paraFinish, + paraStart, + "For executable projects targeting .NET Core 3.0 and later, library dependencies are copied to the output folder. This means that if there isn't any other publish-specific logic (such as Web projects have), the build output should be deployable.", + paraFinish, + exampleStart, + codeStart, + "var configuration = Props.Get(\"configuration\", \"Release\");", + "", + "", + "new DotNetBuild().WithConfiguration(configuration)", + " .Build().EnsureSuccess();", + codeFinish, + exampleFinish, + CreateCliRef("dotnet-build") + ], + ["build", "$Project"], + [ + new Arg("Sources", "--source", "IEnumerable", "The URI of the NuGet package source to use during the restore operation.") { IsCollection = true }, + projectArg, + archArg, + artifactsPathArg, + configurationArg, + disableBuildServersArg, + frameworkArg, + forceArg, + noDependenciesArg, + noIncrementalArg, + noRestoreArg, + noLogoArg, + noSelfContainedArg, + outputArg, + osArg, + runtimeArg, + selfContainedArg, + terminalLoggerArg, + verbosityArg, + useCurrentRuntimeArg, + versionSuffixArg + ], + CommandTypes.Build + ), + new( + "DotNetBuildServerShutdown", + [ + "Shuts down build servers that are started from dotnet.", + paraStart, + "By default, all servers are shut down.", + paraFinish, + CreateCliRef("dotnet-build-server") + ], + ["build-server", "shutdown"], + [ + new Arg("Servers", "", "IEnumerable", "Shuts down build servers that are started from dotnet. By default, all servers are shut down.") { IsCollection = true } + ] + ), + new( + "DotNetClean", + [ + "Cleans the output of a project.", + paraStart, + "This command cleans the output of the previous build. It's implemented as an MSBuild target, so the project is evaluated when the command is run. Only the outputs created during the build are cleaned. Both intermediate (obj) and final output (bin) folders are cleaned.", + paraFinish, + CreateCliRef("dotnet-clean") + ], + ["clean", "$Project"], + [ + propsArg, + projectArg, + artifactsPathArg, + configurationArg, + frameworkArg, + noLogoArg, + outputArg, + runtimeArg, + terminalLoggerArg, + verbosityArg + ], + CommandTypes.Build + ), + new( + "DotNetDevCertsHttps", + [ + "Generates a self-signed certificate to enable HTTPS use in development.", + paraStart, + "This command manages a self-signed certificate to enable HTTPS use in local web app development. Its main functions are:", + "
- Generating a certificate for use with HTTPS endpoints during development.", + "
- Trusting the generated certificate on the local machine.", + "
- Removing the generated certificate from the local machine.", + "
- Exporting a certificate in various formats so that it can be used by other tools.", + "
- Importing an existing certificate generated by the tool into the local machine.", + paraFinish, + CreateCliRef("dotnet-dev-certs") + ], + ["dev-certs", "https"], + [ + new Arg("Check", "--check", "bool?", "Checks for the existence of the development certificate but doesn't perform any action. Use this option with the --trust option to check if the certificate is not only valid but also trusted."), + new Arg("Clean", "--clean", "bool?", "Removes all HTTPS development certificates from the certificate store by using the .NET certificate store API. Doesn't remove any physical files that were created by using the --export-path option. On macOS in .NET 7.0, the dotnet dev-certs command creates the certificate on a path on disk, and the clean operation removes that certificate file."), + new Arg("ExportPath", "--export-path", "string", "Exports the certificate to a file so that it can be used by other tools. Specify the full path to the exported certificate file, including the file name."), + new Arg("Format", "--format", "string", "When used with --export-path, specifies the format of the exported certificate file. Valid values are PFX and PEM, case-insensitive. PFX is the default. The file format is independent of the file name extension. For example, if you specify --format pfx and --export-path ./cert.pem, you'll get a file named cert.pem in PFX format."), + new Arg("Import", "--import", "string", "Imports the provided HTTPS development certificate into the local machine. Requires that you also specify the --clean option, which clears out any existing HTTPS developer certificates."), + new Arg("NoPassword", "--no-password", "bool?", "Doesn't use a password for the key when exporting a certificate to PEM format files. The key file is exported in plain text. This option is not applicable to PFX files and is intended for internal testing use only."), + new Arg("Password", "--password", "bool?", "Specifies the password to use."), + new Arg("Quiet", "--quiet", "bool?", "Display warnings and errors only."), + new Arg("Trust", "--trust", "bool?", "rusts the certificate on the local machine. If this option isn't specified, the certificate is added to the certificate store but not to a trusted list. When combined with the --check option, validates that the certificate is trusted."), + new Arg("Verbose", "--verbose", "bool?", "Display debug information.") + ] + ), + new( + "DotNetNew", + [ + "Creates a new project, configuration file, or solution based on the specified template.", + paraStart, + "This command creates a .NET project or other artifacts based on a template. The command calls the template engine to create the artifacts on disk based on the specified template and options.", + paraFinish, + CreateCliRef("dotnet-new") + ], + ["new", "$TemplateName"], + [ + templateNameArg with { Comments = "The template to instantiate when the command is invoked. Each template might have specific options you can pass." }, + new Arg("DryRun", "--dry-run", "bool?", "Displays a summary of what would happen if the given command were run if it would result in a template creation. Available since .NET Core 2.2 SDK."), + new Arg("Force", "--force", "bool?", "Forces content to be generated even if it would change existing files. This is required when the template chosen would override existing files in the output directory."), + languageArg with { Comments = "The language of the template to create. The language accepted varies by the template (see defaults in the arguments section). Not valid for some templates." }, + new Arg("Name", "--name", "string", "The name for the created output. If no name is specified, the name of the current directory is used."), + frameworkArg with { Comments = "Specifies the target framework. It expects a target framework moniker (TFM). Examples: \"net6.0\", \"net7.0-macos\". This value will be reflected in the project file." }, + new Arg("NoUpdateCheck", "-no-update-check", "bool?", "Disables checking for template package updates when instantiating a template. Available since .NET SDK 6.0.100."), + outputArg with { Comments = "Location to place the generated output. The default is the current directory." }, + new Arg("Project", "--project", "string", "The project that the template is added to. This project is used for context evaluation. If not specified, the project in the current or parent directories will be used. Available since .NET SDK 7.0.100."), + verbosityArg + ] + ), + new( + "DotNetNewList", + [ + "Lists available templates to be run using dotnet new.", + paraStart, + "This command lists available templates to use with dotnet new. If the <TEMPLATE_NAME> is specified, lists templates containing the specified name. This option lists only default and installed templates. To find templates in NuGet that you can install locally, use the search command.", + paraFinish, + CreateCliRef("dotnet-new-list") + ], + ["new", "list", "$TemplateName"], + [ + new Arg("Columns", "--columns", "IEnumerable", "Columns to display in the output.") { IsCollection = true }, + templateNameArg with { Comments = "If the argument is specified, only the templates containing TEMPLATE_NAME in template name or short name will be shown." }, + new Arg("Author", "--author", "string", "Filters templates based on template author. Partial match is supported. Available since .NET SDK 5.0.300."), + new Arg("ColumnsAll", "--columns-all", "bool?", "Displays all columns in the output. Available since .NET SDK 5.0.300."), + new Arg("IgnoreConstraints", "--ignore-constraints", "bool?", "Disables checking if the template meets the constraints to be run. Available since .NET SDK 7.0.100."), + languageArg with { Comments = "Filters templates based on language supported by the template. The language accepted varies by the template. Not valid for some templates." }, + outputArg with { Comments = "Location to place the generated output. The default is the current directory. For the list command, it might be necessary to specify the output directory to correctly evaluate constraints for the template. Available since .NET SDK 7.0.100." }, + new Arg("Project", "--project", "string", "The project that the template is added to. For the list command, it might be needed to specify the project the template is being added to to correctly evaluate constraints for the template. Available since .NET SDK 7.0.100."), + new Arg("Tag", "--tag", "string", "Filters templates based on template tags. To be selected, a template must have at least one tag that exactly matches the criteria. Available since .NET SDK 5.0.300."), + new Arg("Type", "--type", "DotNetTemplateType?", "Filters templates based on template type."), + verbosityArg + ] + ), + new( + "DotNetNewSearch", + [ + "Searches for the templates supported by dotnet new on NuGet.org.", + paraStart, + "This command searches for templates supported by dotnet new on NuGet.org. When the <TEMPLATE_NAME> is specified, searches for templates containing the specified name.", + paraFinish, + CreateCliRef("dotnet-new-search") + ], + ["new", "search", "$TemplateName"], + [ + new Arg("Columns", "--columns", "IEnumerable", "Columns to display in the output.") { IsCollection = true }, + templateNameArg with { Comments = "If the argument is specified, only the templates containing TEMPLATE_NAME in template name or short name will be shown." }, + new Arg("Author", "--author", "string", "Filters templates based on template author. Partial match is supported. Available since .NET SDK 5.0.300."), + new Arg("ColumnsAll", "--columns-all", "bool?", "Displays all columns in the output. Available since .NET SDK 5.0.300."), + languageArg with { Comments = "Filters templates based on language supported by the template." }, + new Arg("Package", "--package", "string", "Filters templates based on NuGet package ID. A partial match is supported."), + new Arg("Tag", "--tag", "string", "Filters templates based on template tags. To be selected, a template must have at least one tag that exactly matches the criteria."), + new Arg("Type", "--type", "DotNetTemplateType?", "Filters templates based on template type."), + verbosityArg + ] + ), + new( + "DotNetNewDetails", + [ + "Displays template package metadata.", + paraStart, + "This command displays the metadata of the template package from the package name provided. By default, the command searches for the latest available version. If the package is installed locally or is found on the official NuGet website, it also displays the templates that the package contains, otherwise it only displays basic metadata.", + paraFinish, + CreateCliRef("dotnet-new-details") + ], + ["new", "details", "$TemplateName"], + [ + new Arg("Sources", "--add-source", "IEnumerable", "By default, dotnet new details uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If --nuget-source is specified, the source is added to the list of sources to be checked.") { IsCollection = true }, + templateNameArg with { Comments = "If the argument is specified, only the templates containing TEMPLATE_NAME in template name or short name will be shown." }, + forceArg, + verbosityArg + ] + ), + new( + "DotNetNewInstall", + [ + "Installs a template package.", + paraStart, + "This command installs a template package from the PATH or NUGET_ID provided. If you want to install a specific version or prerelease version of a template package, specify the version in the format <package-name>::<package-version>. By default, dotnet new passes * for the version, which represents the latest stable package version.", + paraFinish, + CreateCliRef("dotnet-new-install") + ], + ["new", "install", "$Package"], + [ + new Arg("Sources", "--add-source", "IEnumerable", "By default, dotnet new details uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If --nuget-source is specified, the source is added to the list of sources to be checked.") { IsCollection = true }, + new Arg("Package", "", "string", "The folder on the file system or the NuGet package identifier to install the template package from. dotnet new attempts to install the NuGet package from the NuGet sources available for the current working directory and the sources specified via the --add-source option. If you want to install a specific version or prerelease version of a template package from NuGet source, specify the version in the format <package-name>::<package-version>.") { IsProject = true }, + forceArg, + verbosityArg + ] + ), + new( + "DotNetNewUninstall", + [ + "Uninstalls a template package.", + paraStart, + "This command uninstalls a template package at the PATH or NUGET_ID provided. When the <PATH|NUGET_ID> value isn't specified, all currently installed template packages and their associated templates are displayed. When specifying NUGET_ID, don't include the version number.", + paraFinish, + CreateCliRef("dotnet-new-uninstall") + ], + ["new", "uninstall", "$Package"], + [ + new Arg("Package", "", "string", "The folder on the file system or the NuGet package identifier the package was installed from. Note that the version for the NuGet package should not be specified.") { IsProject = true }, + verbosityArg + ] + ), + new( + "DotNetNewUpdate", + [ + "Updates installed template packages.", + paraStart, + "This command updates installed template packages. The dotnet new update command with --check-only option checks for available updates for installed template packages without applying them.", + paraFinish, + CreateCliRef("dotnet-new-update") + ], + ["new", "update"], + [ + new Arg("Sources", "--add-source", "IEnumerable", "By default, dotnet new install uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If Sources is specified, the source will be added to the list of sources to be checked. To check the configured sources for the current directory use dotnet nuget list source. Available since .NET SDK 7.0.100.") { IsCollection = true }, + new Arg("CheckOnly", "--check-only", "bool?", "Only checks for updates and displays the template packages to be updated, without applying any updates."), + new Arg("DryRun", "--dry-run", "bool?", "Only checks for updates and displays the template packages to be updated, without applying any updates."), + verbosityArg + ] + ), + new( + "DotNetNuGetDelete", + [ + "Deletes or unlists a package from the server.", + paraStart, + "This command deletes or unlists a package from the server. For nuget.org, the action is to unlist the package.", + paraFinish, + CreateCliRef("dotnet-nuget-delete") + ], + ["nuget", "delete", "$PackageName", "$PackageVersion"], + [ + new Arg("PackageName", "", "string", "Name/ID of the package to delete.") { IsProject = true }, + new Arg("PackageVersion", "", "string", "Version of the package to delete.") { IsProject = true }, + new Arg("ForceEnglishOutput", "--force-english-output", "bool?", "Forces the application to run using an invariant, English-based culture."), + new Arg("ApiKey", "--api-key", "string", "The API key for the server."), + new Arg("NoServiceEndpoint", "--no-service-endpoint", "bool?", "Doesn't append \"api/v2/package\" to the source URL."), + new Arg("Source", "--source", "string", "Specifies the server URL. NuGet identifies a UNC or local folder source and simply copies the file there instead of pushing it using HTTP.") + ], + CommandTypes.Default, + "--non-interactive" + ), + new( + "DotNetNuGetLocalsClear", + [ + "Clears local NuGet resources.", + paraStart, + "This command clears local NuGet resources in the http-request cache, temporary cache, or machine-wide global packages folder.", + paraFinish, + CreateCliRef("dotnet-nuget-locals") + ], + ["nuget", "locals", "$CacheLocation"], + [ + new Arg("CacheLocation", "", "NuGetCacheLocation?", "The cache location to clear.") { IsProject = true }, + new Arg("ForceEnglishOutput", "--force-english-output", "bool?", "Forces the application to run using an invariant, English-based culture.") + ], + CommandTypes.Default, + "--clear" + ), + new( + "DotNetNuGetLocalsList", + [ + "Lists local NuGet resources.", + paraStart, + "This command lists local NuGet resources in the http-request cache, temporary cache, or machine-wide global packages folder.", + paraFinish, + CreateCliRef("dotnet-nuget-locals") + ], + ["nuget", "locals", "$CacheLocation"], + [ + new Arg("CacheLocation", "", "NuGetCacheLocation?", "The cache location to list.") { IsProject = true }, + new Arg("ForceEnglishOutput", "--force-english-output", "bool?", "Forces the application to run using an invariant, English-based culture.") + ], + CommandTypes.Default, + "--list" + ), + new( + "DotNetNuGetPush", + [ + "Pushes a package to the server and publishes it.", + paraStart, + @"This command pushes a package to the server and publishes it. The push command uses server and credential details found in the system's NuGet config file or chain of config files. NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.config (Windows) or $HOME/.nuget/NuGet/NuGet.Config (Linux/macOS), then loading any nuget.config or .nuget\nuget.config starting from the root of drive and ending in the current directory.", + paraFinish, + CreateCliRef("dotnet-nuget-push") + ], + ["nuget", "push", "$Package"], + [ + new Arg("Package", "", "string", "Specifies the file path to the package to be pushed.") { IsProject = true }, + new Arg("DisableBuffering", "--disable-buffering", "bool?", "Disables buffering when pushing to an HTTP(S) server to reduce memory usage."), + new Arg("ForceEnglishOutput", "--force-english-output", "bool?", "Forces the application to run using an invariant, English-based culture."), + new Arg("ApiKey", "--api-key", "string", "The API key for the server."), + new Arg("NoSymbols", "--no-symbols", "bool?", "Doesn't push symbols (even if present)."), + new Arg("NoServiceEndpoint", "--no-service-endpoint", "bool?", "Doesn't append \"api/v2/package\" to the source URL."), + new Arg("Source", "--source", "string", "Specifies the server URL. NuGet identifies a UNC or local folder source and simply copies the file there instead of pushing it using HTTP."), + new Arg("SkipDuplicate", "--skip-duplicate", "bool?", "When pushing multiple packages to an HTTP(S) server, treats any 409 Conflict response as a warning so that other pushes can continue."), + new Arg("SymbolApiKey", "--symbol-api-key", "string", "The API key for the symbol server."), + new Arg("SymbolSource", "--symbol-source", "string", "Specifies the symbol server URL."), + new Arg("Timeout", "--timeout", "int?", "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes). Specifying 0 applies the default value."), + verbosityArg + ] + ), + new( + "DotNetNuGetAddSource", + [ + "Add a NuGet source.", + paraStart, + "This command adds a new package source to your NuGet configuration files. When adding multiple package sources, be careful not to introduce a dependency confusion vulnerability.", + paraFinish, + CreateCliRef("dotnet-nuget-add-source") + ], + ["nuget", "add", "source", "$PackageSourcePath"], + [ + new Arg("ValidAuthenticationTypes", "--valid-authentication-types", "IEnumerable", "List of valid authentication types for this source. Set this to basic if the server advertises NTLM or Negotiate and your credentials must be sent using the Basic mechanism, for instance when using a PAT with on-premises Azure DevOps Server. Other valid values include negotiate, kerberos, ntlm, and digest, but these values are unlikely to be useful.") { IsCollection = true }, + new Arg("PackageSourcePath", "", "string", "Path to the package source.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + new Arg("AllowInsecureConnections", "--allow-insecure-connections", "bool?", "Allows HTTP connections for adding or updating packages. This method is not secure. Available since .NET 9 SDK."), + new Arg("Name", "--name", "string", "Name of the source."), + new Arg("Password", "--password", "string", "Password to be used when connecting to an authenticated source."), + new Arg("StorePasswordInClearText", "--store-password-in-clear-text", "bool?", "Enables storing portable package source credentials by disabling password encryption. Storing passwords in clear text is strongly discouraged."), + new Arg("Username", "--username", "string", "Username to be used when connecting to an authenticated source.") + ] + ), + new( + "DotNetNuGetDisableSource", + [ + "Disable a NuGet source.", + paraStart, + "This command disables an existing source in your NuGet configuration files.", + paraFinish, + CreateCliRef("dotnet-nuget-disable-source") + ], + ["nuget", "disable", "source", "$Name"], + [ + new Arg("Name", "--name", "string", "Name of the source.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations.") + ] + ), + new( + "DotNetNuGetEnableSource", + [ + "Enable a NuGet source.", + paraStart, + "This command enables an existing source in your NuGet configuration files.", + paraFinish, + CreateCliRef("dotnet-nuget-enable-source") + ], + ["nuget", "enable", "source", "$Name"], + [ + new Arg("Name", "--name", "string", "Name of the source.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used.") + ] + ), + new( + "DotNetNuGetListSource", + [ + "Lists all configured NuGet sources.", + paraStart, + "This command lists all existing sources from your NuGet configuration files.", + paraFinish, + CreateCliRef("dotnet-nuget-list-source") + ], + ["nuget", "list", "source"], + [ + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations."), + new Arg("Format", "--format", "NuGetListFormat?", "The format of the list command output: Detailed (the default) and Short.") + ] + ), + new( + "DotNetNuGetRemoveSource", + [ + "Remove a NuGet source.", + paraStart, + "This command removes an existing source from your NuGet configuration files.", + paraFinish, + CreateCliRef("dotnet-nuget-remove-source") + ], + ["nuget", "remove", "source", "$Name"], + [ + new Arg("Name", "--name", "string", "Name of the source.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations.") + ] + ), + new( + "DotNetNuGetUpdateSource", + [ + "Update a NuGet source.", + paraStart, + "This command updates an existing source in your NuGet configuration files.", + paraFinish, + CreateCliRef("dotnet-nuget-update-source") + ], + ["nuget", "update", "source", "$Name"], + [ + new Arg("ValidAuthenticationTypes", "--valid-authentication-types", "IEnumerable", "List of valid authentication types for this source. Set this to basic if the server advertises NTLM or Negotiate and your credentials must be sent using the Basic mechanism, for instance when using a PAT with on-premises Azure DevOps Server. Other valid values include negotiate, kerberos, ntlm, and digest, but these values are unlikely to be useful.") { IsCollection = true }, + new Arg("Name", "--name", "string", "Name of the source.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + new Arg("Password", "--password", "string", "Password to be used when connecting to an authenticated source."), + new Arg("Source", "--source", "string", "Path to the package source."), + new Arg("StorePasswordInClearText", "--store-password-in-clear-text", "bool?", "Enables storing portable package source credentials by disabling password encryption. Storing passwords in clear text is strongly discouraged."), + new Arg("Username", "--username", "string", "Username to be used when connecting to an authenticated source.") + ] + ), + new( + "DotNetNuGetVerify", + [ + "Verifies a signed NuGet package.", + paraStart, + "This command verifies a signed NuGet package. This command requires a certificate root store that is valid for both code signing and timestamping. Also, this command may not be supported on some combinations of operating system and .NET SDK.", + paraFinish, + CreateCliRef("dotnet-nuget-verify") + ], + ["nuget", "verify", "$Packages"], + [ + new Arg("Packages", "", "IEnumerable", "Specifies the file path to the package(s) to be verified.") { IsCollection = true }, + new Arg("Fingerprints", "--certificate-fingerprint", "IEnumerable", "Verify that the signer certificate matches with one of the specified SHA256 fingerprints. This option can be supplied multiple times to provide multiple fingerprints.") { IsCollection = true }, + new Arg("All", "--all", "bool?", "Specifies that all verifications possible should be performed on the package(s). By default, only signatures are verified."), + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustList", + [ + "Lists all the trusted signers in the configuration.", + paraStart, + "This option will include all the certificates (with fingerprint and fingerprint algorithm) each signer has. If a certificate has a preceding [U], it means that certificate entry has allowUntrustedRoot set as true.", + paraFinish, + CreateCliRef("dotnet-nuget-trust#list") + ], + ["nuget", "trust", "list"], + [ + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustSync", + [ + "Deletes the current list of certificates and replaces them with an up-to-date list from the repository.", + CreateCliRef("dotnet-nuget-trust#sync") + ], + ["nuget", "trust", "sync", "$Name"], + [ + new Arg("Name", "", "string", "The name of the existing trusted signer to sync.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustRemove", + [ + "Removes any trusted signers that match the given name.", + CreateCliRef("dotnet-nuget-trust#sync") + ], + ["nuget", "trust", "remove", "$Name"], + [ + new Arg("Name", "", "string", "The name of the existing trusted signer to remove.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustAuthor", + [ + "Adds a trusted signer with the given name, based on the author signature of the package.", + CreateCliRef("dotnet-nuget-trust#author") + ], + ["nuget", "trust", "author", "$Name", "$Package"], + [ + new Arg("Name", "", "string", "The name of the trusted signer to add. If NAME already exists in the configuration, the signature is appended.") { IsProject = true }, + new Arg("Package", "", "string", "The given PACKAGE should be a local path to the signed .nupkg file.") { IsProject = true }, + allowUntrustedRootArg, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustRepository", + [ + "Adds a trusted signer with the given name, based on the repository signature or countersignature of a signed package.", + CreateCliRef("dotnet-nuget-trust#repository") + ], + ["nuget", "trust", "repository", "$Name", "$Package"], + [ + ownersArg, + new Arg("Name", "", "string", "The name of the trusted signer to add. If NAME already exists in the configuration, the signature is appended.") { IsProject = true }, + new Arg("Package", "", "string", "The given PACKAGE should be a local path to the signed .nupkg file.") { IsProject = true }, + allowUntrustedRootArg, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustCertificate", + [ + "Adds a trusted signer with the given name, based on a certificate fingerprint.", + CreateCliRef("dotnet-nuget-trust#certificate") + ], + ["nuget", "trust", "certificate", "$Name", "$Fingerprint"], + [ + new Arg("Name", "", "string", "The name of the trusted signer to add. If a trusted signer with the given name already exists, the certificate item is added to that signer. Otherwise a trusted author is created with a certificate item from the given certificate information.") { IsProject = true }, + new Arg("Fingerprint", "", "string", "The fingerprint of the certificate.") { IsProject = true }, + new Arg("Algorithm", "--algorithm", "NuGetCertificateAlgorithm?", "Specifies the hash algorithm used to calculate the certificate fingerprint. Defaults to SHA256. Values supported are SHA256, SHA384 and SHA512."), + allowUntrustedRootArg, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + verbosityArg + ] + ), + new( + "DotNetNuGetTrustSource", + [ + "Adds a trusted signer based on a given package source.", + CreateCliRef("dotnet-nuget-trust#source") + ], + ["nuget", "trust", "source", "$Name" ], + [ + ownersArg, + new Arg("Name", "", "string", "The name of the trusted signer to add. If only <NAME> is provided without --<source-url>, the package source from your NuGet configuration files with the same name is added to the trusted list. If <NAME> already exists in the configuration, the package source is appended to it.") { IsProject = true }, + new Arg("ConfigFile", "--configfile", "string", "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), + new Arg("SourceUrl", "--source-url", "string", "If a source-url is provided, it must be a v3 package source URL (like https://api.nuget.org/v3/index.json). Other package source types are not supported."), + verbosityArg + ] + ), + new( + "DotNetNuGetSign", + [ + "Signs all the NuGet packages matching the first argument with a certificate.", + paraStart, + "This command signs all the packages matching the first argument with a certificate. The certificate with the private key can be obtained from a file or from a certificate installed in a certificate store by providing a subject name or a SHA-1 fingerprint. This command requires a certificate root store that is valid for both code signing and timestamping. Also, this command may not be supported on some combinations of operating system and .NET SDK.", + paraFinish, + CreateCliRef("dotnet-nuget-sign") + ], + ["nuget", "sign", "$Packages"], + [ + new Arg("Packages", "", "IEnumerable", "Specifies the file path to the packages to be signed.") { IsProject = true, IsCollection = true }, + new Arg("CertificatePath", "--certificate-path", "string", "Specifies the file path to the certificate to be used in signing the package. This option currently supports only PKCS12 (PFX) files that contain the certificate's private key."), + new Arg("CertificateStoreName", "--certificate-store-name", "string", "Specifies the name of the X.509 certificate store to use to search for the certificate. Defaults to \"My\", the X.509 certificate store for personal certificates. This option should be used when specifying the certificate via --certificate-subject-name or --certificate-fingerprint options."), + new Arg("CertificateStoreLocation", "--certificate-store-location", "string", "Specifies the name of the X.509 certificate store use to search for the certificate. Defaults to \"CurrentUser\", the X.509 certificate store used by the current user. This option should be used when specifying the certificate via --certificate-subject-name or --certificate-fingerprint options."), + new Arg("CertificateSubjectName", "--certificate-subject-name", "string", "Specifies the subject name of the certificate used to search a local certificate store for the certificate. The search is a case-insensitive string comparison using the supplied value, which finds all certificates with the subject name containing that string, regardless of other subject values. The certificate store can be specified by --certificate-store-name and --certificate-store-location options. This option currently supports only a single matching certificate in the result. If there are multiple matching certificates in the result, or no matching certificate in the result, the sign command will fail."), + new Arg("CertificateFingerprint", "--certificate-fingerprint", "string", "Specifies the fingerprint of the certificate used to search a local certificate store for the certificate. Starting with .NET 9, this option can be used to specify the SHA-1, SHA-256, SHA-384, or SHA-512 fingerprint of the certificate. However, a NU3043 warning is raised when a SHA-1 certificate fingerprint is used because it is no longer considered secure. All the previous versions of the .NET SDK continue to accept only SHA-1 certificate fingerprint."), + new Arg("CertificatePassword", "--certificate-password", "string", "Specifies the certificate password, if needed. If a certificate is password protected but no password is provided, the sign command will fail."), + new Arg("HashAlgorithm", "--hash-algorithm", "NuGetCertificateAlgorithm?", "Hash algorithm to be used to sign the package. Defaults to SHA256. Possible values are SHA256, SHA384, and SHA512."), + new Arg("Output", "--output", "string", "Specifies the directory where the signed package should be saved. If this option isn't specified, by default the original package is overwritten by the signed package."), + new Arg("Overwrite", "--overwrite", "bool?", "Indicate that the current signature should be overwritten. By default the command will fail if the package already has a signature."), + new Arg("TimestampHashAlgorithm", "--timestamp-hash-algorithm", "NuGetCertificateAlgorithm?", "Hash algorithm to be used by the RFC 3161 timestamp server. Defaults to SHA256."), + new Arg("TimestampingServer", "--timestamper", "string", "URL to an RFC 3161 timestamping server."), + verbosityArg + ] + ), + new( + "DotNetNuGetWhy", + [ + "Shows the dependency graph for a particular package.", + paraStart, + @"This command shows the dependency graph for a particular package for a given project or solution. Starting from the .NET 9 SDK, it's possible to pass a NuGet assets file in place of the project file, in order to use the command with projects that can't be restored with the .NET SDK. First, restore the project in Visual Studio, or msbuild.exe. By default the assets file is in the project's obj\ directory, but you can find the location with msbuild.exe path\to\project.proj -getProperty:ProjectAssetsFile. Finally, run dotnet nuget why path\to\project.assets.json SomePackage.", + paraFinish, + CreateCliRef("dotnet-nuget-why") + ], + ["nuget", "why", "$Project", "$Package"], + [ + new Arg("Frameworks", "--framework", "IEnumerable", "The target frameworks for which dependency graphs are shown.") { IsCollection = true }, + new Arg("Project", "", "string", "The project or solution file to operate on. If a directory is specified, the command searches the directory for a project or solution file. If more than one project or solution is found, an error is thrown.") { IsProject = true }, + new Arg("Package", "", "string", "The package name to look up in the dependency graph.") { IsProject = true } + ] + ), + new( + "DotNetNuConfigGet", + [ + "Gets the NuGet configuration settings that will be applied.", + paraStart, + "This command gets the NuGet configuration settings that will be applied from the config section.", + paraFinish, + CreateCliRef("dotnet-nuget-config-get") + ], + ["nuget", "config", "get", "$ConfigKey"], + [ + new Arg("ConfigKey", "", "string", "ALL gets all merged NuGet configuration settings from multiple NuGet configuration files that will be applied, when invoking NuGet command from the working directory path. Otherwise gets the effective value of the specified configuration settings of the config section.") { IsProject = true }, + new Arg("ShowPath", "--show-path", "bool?", "Indicate that the NuGet configuration file path will be shown beside the configuration settings."), + new Arg("Directory", "--working-directory", "string", "Specifies the directory to start from when listing configuration files. If not specified, the current directory is used.") + ] + ), + new( + "DotNetRun", + [ + "Runs source code without any explicit compile or launch commands.", + paraStart, + "This command provides a convenient option to run your application from the source code with one command. It's useful for fast iterative development from the command line. The command depends on the dotnet build command to build the code. Any requirements for the build apply to dotnet run as well.", + paraFinish, + paraStart, + "To run the application, the dotnet run command resolves the dependencies of the application that are outside of the shared runtime from the NuGet cache. Because it uses cached dependencies, it's not recommended to use dotnet run to run applications in production. Instead, create a deployment using the dotnet publish command and deploy the published output.", + paraFinish, + exampleStart, + codeStart, + "var result = new DotNetNew(\"console\", \"-n\", \"MyApp\", \"--force\")", + " .Build().EnsureSuccess();", + "", + "", + "new DotNetRun().WithWorkingDirectory(\"MyApp\")", + " .Build().EnsureSuccess();", + codeFinish, + exampleFinish, + CreateCliRef("dotnet-run") + ], + ["run", "$Project"], + [ + propsArg, + projectArg, + archArg, + configurationArg, + frameworkArg, + forceArg, + new Arg("LaunchProfile", "--launch-profile", "string", "The name of the launch profile (if any) to use when launching the application. Launch profiles are defined in the launchSettings.json file and are typically called Development, Staging, and Production."), + noBuildArg, + noDependenciesArg, + new Arg("NoLaunchProfile", "--no-launch-profile", "bool?", "Doesn't try to use launchSettings.json to configure the application."), + noRestoreArg, + osArg, + runtimeArg, + terminalLoggerArg, + verbosityArg + ] + ) + }; +#> +using Internal.DotNet; + +<# + foreach (var command in commands) + { + var name = command.Name; + var commandArgs = new List(); + foreach (var arg in command.CommandArgs) + { + if (arg.StartsWith("$")) + { + var curArg = arg.Substring(1); + var notEmpty = command.Args.FirstOrDefault(i => i.PropertyName == curArg && i.IsCollection); + if (notEmpty is not null && !string.IsNullOrWhiteSpace(notEmpty.PropertyName)) + { + var compositeArg = $"new [] {{{string.Join(", ", commandArgs)}}}.Concat({curArg}).ToArray()"; + commandArgs.Clear(); + commandArgs.Add(compositeArg); + } + else + { + commandArgs.Add($"{curArg}.ToArg()"); + } + } + else + { + commandArgs.Add($"\"{arg}\""); + } + } +#> +/// +<# + foreach (var comment in command.Comments) + { +#> +/// <#= comment #> +<# + } +#> +/// +/// Specifies the set of command line arguments to use when starting the tool. +/// Specifies the set of environment variables that apply to this process and its child processes. +<# + foreach (var arg in command.Args.Where(i => i.IsCollection)) + { +#> +/// <#= arg.Comments #> +<# + } +#> +/// Overrides the tool executable path. +/// Specifies the working directory for the tool to be started. +<# + foreach (var arg in command.Args.Where(i => !i.IsCollection)) + { +#> +/// <#= arg.Comments #> +<# + } +#> +/// Enables diagnostic output. +/// Specifies a short name for this operation. +[Target] +public partial record <#= command.Name #>( + IEnumerable Args, + IEnumerable<(string name, string value)> Vars, +<# + var initializer = string.Join(", ", new[] {"args", "[]"}.Concat(Enumerable.Repeat("[]", command.Args.Count(i => i.IsCollection)))); + var fullInitializer = string.Join(", ", new[] {"[]", "[]"}.Concat(Enumerable.Repeat("[]", command.Args.Count(i => i.IsCollection)))); + foreach (var arg in command.Args) + { + var type = arg.Type; + var defaultValue = ""; + if (type == "string") + { + defaultValue = " = \"\""; + } + else + { + if (!arg.IsCollection) + { + defaultValue = " = default"; + } + } +#> + <#= type #> <#= arg.PropertyName #><#= defaultValue #>, +<# + } +#> + string ExecutablePath = "", + string WorkingDirectory = "", + bool? Diagnostics = default, + string ShortName = "") +{ + /// + /// Create a new instance of the command. + /// + /// Specifies the set of command line arguments to use when starting the tool. + public <#= name #>(params string[] args) + : this(<#= initializer #>) + { + } + + /// + /// Create a new instance of the command. + /// + public <#= name #>() + : this(<#= fullInitializer #>) + { + } + + /// + public IStartInfo GetStartInfo(IHost host) + { + if (host == null) throw new ArgumentNullException(nameof(host)); + return host.CreateCommandLine(ExecutablePath) + .WithShortName(ToString()) + .WithWorkingDirectory(WorkingDirectory) + .WithVars(Vars.ToArray()) +<# + foreach (var arg in command.CommandArgs) + { + if (arg.StartsWith("$")) + { + var notEmptyArg = arg.Substring(1); + var notEmpty = command.Args.FirstOrDefault(i => i.PropertyName == notEmptyArg && i.IsCollection); + if (notEmpty is not null && !string.IsNullOrWhiteSpace(notEmpty.PropertyName)) + { + notEmptyArg = $"{notEmptyArg}.ToArray()"; + } +#> + .AddNotEmptyArgs(<#= notEmptyArg #>.ToArg()) +<# + } + else + { +#> + .AddArgs("<#= arg #>") +<# + } + } +#> +<# + if ((command.CommandTypes & CommandTypes.Build) == CommandTypes.Build) + { +#> + .AddMSBuildLoggers(host, Verbosity) +<# + } + + if ((command.CommandTypes & CommandTypes.Test) == CommandTypes.Test) + { +#> + .AddTestLoggers(host, Loggers) +<# + } + + foreach (var additionalArg in command.AdditionalArgs) + { +#> + .AddArgs("<#= additionalArg #>") +<# + } + + foreach (var arg in command.Args.Where(i => !i.IsProject).Where(i => i.IsCollection && i.ArgName != "--property")) + { +#> + .AddArgs(<#= arg.PropertyName #>.ToArgs("<#= arg.ArgName #>", "<#= arg.CollectionSeparator #>")) +<# + } + + foreach (var arg in command.Args.Where(i => !i.IsProject).Where(i => !string.IsNullOrWhiteSpace(i.ArgName) && !i.Type.StartsWith("bool") && !i.IsCollection)) + { +#> + .AddArgs(<#= arg.PropertyName #>.ToArgs("<#= arg.ArgName #>", "<#= arg.CollectionSeparator #>")) +<# + } +#> + .AddBooleanArgs( +<# + var boolArgs = command.Args.Where(i => !string.IsNullOrWhiteSpace(i.ArgName) && i.Type.StartsWith("bool")).ToArray(); + for (var i = 0; i < boolArgs.Length; i++) + { + var arg = boolArgs[i]; +#> + ("<#= arg.ArgName #>", <#= arg.PropertyName #>), +<# + } +#> + ("--diagnostics", Diagnostics) + ) +<# + foreach (var arg in command.Args.Where(i => !string.IsNullOrWhiteSpace(i.ArgName) && i.IsCollection && i.ArgName == "--property").ToArray()) + { +#> + .AddProps("--property", <#= arg.PropertyName #>.ToArray()) +<# + } +#> + .AddArgs(Args.ToArray()); + } + + /// + public override string ToString() => "".GetShortName(ShortName, <#= string.Join(", ", commandArgs) #>); +} + +<# + } +#> + +<#+ + public record Arg( + string PropertyName, + string ArgName, + string Type, + string Comments) + { + public string PropertyName { get; } = PropertyName; + public string ArgName { get; } = ArgName; + public string Type { get; } = Type; + public string Comments { get; set; } = Comments; + public bool IsProject { get; set; } + public bool IsCollection { get; set; } + public string CollectionSeparator { get; set; } = ""; + } + + [Flags] + public enum CommandTypes + { + Default = 0, + Build = 1, + Test = 2 + } + + public record Command( + string Name, + string[] Comments, + string[] CommandArgs, + Arg[] Args, + CommandTypes CommandTypes = CommandTypes.Default, + params string[] AdditionalArgs) + { + public string Name { get; } = Name; + public string[] Comments { get; } = Comments; + public string[] CommandArgs { get; } = CommandArgs; + public Arg[] Args { get; } = Args; + public CommandTypes CommandTypes { get; } = CommandTypes; + public string[] AdditionalArgs { get; } = AdditionalArgs; + } +#> \ No newline at end of file diff --git a/CSharpInteractive.HostApi/DotNetLanguage.cs b/CSharpInteractive.HostApi/DotNetLanguage.cs index 7ab8b16..9cae78a 100644 --- a/CSharpInteractive.HostApi/DotNetLanguage.cs +++ b/CSharpInteractive.HostApi/DotNetLanguage.cs @@ -23,12 +23,12 @@ public enum DotNetLanguage /// /// SQL /// - SQL, + Sql, /// /// JSON /// - JSON, + Json, /// /// TypeScript @@ -38,14 +38,15 @@ public enum DotNetLanguage internal static class DotNetLanguageExtensions { - public static string[] ToArgs(this DotNetLanguage? language, string name) => + // ReSharper disable once UnusedParameter.Global + public static string[] ToArgs(this DotNetLanguage? language, string name, string collectionSeparator) => language switch { DotNetLanguage.CSharp => [name, "\"C#\""], DotNetLanguage.FSharp => [name, "\"F#\""], DotNetLanguage.VisualBasic => [name, "VB"], - DotNetLanguage.SQL => [name, "VB"], - DotNetLanguage.JSON => [name, "JSON"], + DotNetLanguage.Sql => [name, "VB"], + DotNetLanguage.Json => [name, "JSON"], DotNetLanguage.TypeScript => [name, "TypeScript"], _ => [] }; diff --git a/CSharpInteractive.HostApi/DotNetNewListColumn.cs b/CSharpInteractive.HostApi/DotNetNewListColumn.cs index f18d743..016d01f 100644 --- a/CSharpInteractive.HostApi/DotNetNewListColumn.cs +++ b/CSharpInteractive.HostApi/DotNetNewListColumn.cs @@ -1,4 +1,5 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// /// @@ -28,7 +29,8 @@ public enum DotNetNewListColumn internal static class DotNetNewListColumnExtensions { - public static string[] ToArgs(this IEnumerable columns, string name) + // ReSharper disable once UnusedParameter.Global + public static string[] ToArgs(this IEnumerable columns, string name, string collectionSeparator) { var columnsStr = string.Join(",", columns.Select(i => i.ToString())); return string.IsNullOrWhiteSpace(columnsStr) ? [] : [name, columnsStr]; diff --git a/CSharpInteractive.HostApi/DotNetRollForward.cs b/CSharpInteractive.HostApi/DotNetRollForward.cs index f97eab9..705e22b 100644 --- a/CSharpInteractive.HostApi/DotNetRollForward.cs +++ b/CSharpInteractive.HostApi/DotNetRollForward.cs @@ -1,4 +1,5 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// /// Controls how roll forward is applied to the app. diff --git a/CSharpInteractive.HostApi/DotNetTemplateType.cs b/CSharpInteractive.HostApi/DotNetTemplateType.cs index 08d5f66..73b3ba6 100644 --- a/CSharpInteractive.HostApi/DotNetTemplateType.cs +++ b/CSharpInteractive.HostApi/DotNetTemplateType.cs @@ -1,4 +1,5 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// /// Template type. diff --git a/CSharpInteractive.HostApi/DotNetTerminalLogger.cs b/CSharpInteractive.HostApi/DotNetTerminalLogger.cs index 5b7bb3c..44d1b9c 100644 --- a/CSharpInteractive.HostApi/DotNetTerminalLogger.cs +++ b/CSharpInteractive.HostApi/DotNetTerminalLogger.cs @@ -1,4 +1,5 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// /// Terminal logger modes. diff --git a/CSharpInteractive.HostApi/Internal/DotNet/DotNetCommandLineExtensions.cs b/CSharpInteractive.HostApi/Internal/DotNet/DotNetCommandLineExtensions.cs index a963181..ea68d1d 100644 --- a/CSharpInteractive.HostApi/Internal/DotNet/DotNetCommandLineExtensions.cs +++ b/CSharpInteractive.HostApi/Internal/DotNet/DotNetCommandLineExtensions.cs @@ -138,20 +138,23 @@ public static CommandLine AddProps(this CommandLine cmd, string propertyName, pa cmd.AddArgs(props.Select(i => $"{propertyName}:{i.name}={i.value}") .ToArray()); - public static string[] ToArgs(this T value, string name) + // ReSharper disable once UnusedParameter.Global + public static string[] ToArgs(this T value, string name, string collectionSeparator) { var valueStr = value?.ToString(); return string.IsNullOrWhiteSpace(valueStr) ? [] : [name, valueStr!]; } - public static string[] ToArgs(this IEnumerable values, string name) => - values.SelectMany(value => string.IsNullOrWhiteSpace(value) ? [] : new [] {name, value}).ToArray(); - - public static string[] ToArgs(this IReadOnlyCollection values, string name) + public static string[] ToArgs(this IEnumerable values, string name, string collectionSeparator) { - var str = string.Join(",", values); + if (string.IsNullOrWhiteSpace(collectionSeparator)) + { + return values.SelectMany(value => string.IsNullOrWhiteSpace(value) ? [] : new[] {name, value}).ToArray(); + } + + var str = string.Join(collectionSeparator, values); return string.IsNullOrWhiteSpace(str) ? [] : [name, str]; } - + public static string ToArg(this T value) => value?.ToString() ?? ""; } \ No newline at end of file diff --git a/CSharpInteractive.HostApi/NuGetAuthenticationType.cs b/CSharpInteractive.HostApi/NuGetAuthenticationType.cs index e94053f..b1bf5e1 100644 --- a/CSharpInteractive.HostApi/NuGetAuthenticationType.cs +++ b/CSharpInteractive.HostApi/NuGetAuthenticationType.cs @@ -1,4 +1,5 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// /// NuGet authentication types. @@ -33,7 +34,8 @@ public enum NuGetAuthenticationType internal static class NuGetAuthenticationTypeExtensions { - public static string[] ToArgs(this IEnumerable authenticationTypes, string name) + // ReSharper disable once UnusedParameter.Global + public static string[] ToArgs(this IEnumerable authenticationTypes, string name, string collectionSeparator) { var authenticationTypesStr = string.Join(",", authenticationTypes.Select(i => i.ToString().ToLowerInvariant())); return string.IsNullOrWhiteSpace(authenticationTypesStr) ? [] : [name, authenticationTypesStr]; diff --git a/CSharpInteractive.HostApi/NuGetCertificateAlgorithm.cs b/CSharpInteractive.HostApi/NuGetCertificateAlgorithm.cs index 84ec59c..1a04c0e 100644 --- a/CSharpInteractive.HostApi/NuGetCertificateAlgorithm.cs +++ b/CSharpInteractive.HostApi/NuGetCertificateAlgorithm.cs @@ -1,29 +1,31 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// -/// +/// NuGet certificate algorithm. /// public enum NuGetCertificateAlgorithm { /// - /// + /// Sha256 /// Sha256, /// - /// + /// Sha384 /// Sha384, /// - /// + /// Sha512 /// Sha512 } internal static class NuGetCertificateAlgorithmExtensions { - public static string[] ToArgs(this NuGetCertificateAlgorithm? algorithm, string name) + // ReSharper disable once UnusedParameter.Global + public static string[] ToArgs(this NuGetCertificateAlgorithm? algorithm, string name, string collectionSeparator) { var algorithmStr = algorithm?.ToString().ToUpperInvariant(); return algorithmStr is null ? [] : [name, algorithmStr]; diff --git a/CSharpInteractive.HostApi/NuGetListFormat.cs b/CSharpInteractive.HostApi/NuGetListFormat.cs index 53db024..f62b3de 100644 --- a/CSharpInteractive.HostApi/NuGetListFormat.cs +++ b/CSharpInteractive.HostApi/NuGetListFormat.cs @@ -1,4 +1,5 @@ -namespace HostApi; +// ReSharper disable UnusedMember.Global +namespace HostApi; /// /// The format of the nuget list command output. diff --git a/CSharpInteractive.HostApi/SimpleDotNetCommands.tt b/CSharpInteractive.HostApi/SimpleDotNetCommands.tt deleted file mode 100644 index 934db24..0000000 --- a/CSharpInteractive.HostApi/SimpleDotNetCommands.tt +++ /dev/null @@ -1,1096 +0,0 @@ -<#@ import namespace="System.Linq" #> -<#@ import namespace="System.Collections.Generic" #> -// ReSharper disable InconsistentNaming -namespace HostApi; - -<# - const string ps = "

"; - const string pf = "

"; - string CreateRef(string command) - { - return $"
.NET CLI command
"; - } - - bool IsCollection(string type) - { - return type.StartsWith("IEnumerable<") || type.StartsWith("IReadOnlyCollection<"); - } - - (string PropertyName, string ArgName, string Type, bool IsProject, string Comments)[] commonArgs = - [ - ("Project", "", "string", true, "The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown."), - ("Props", "--property", "IEnumerable<(string name, string value)>", false, "MSBuild options for setting properties."), - ("Verbosity", "--verbosity", "DotNetVerbosity?", false, "Sets the verbosity level of the command. Allowed values are , , , , and . The default is . For more information, see ."), - ("PathToApplication", "", "string", true, "Specifies the path to an application .dll file to run the application. To run the application means to find and execute the entry point, which in the case of console apps is the Main method. For example, dotnet myapp. dll runs the myapp application."), - ("RollForward", "--roll-forward", "DotNetRollForward?", false, "Controls how roll forward is applied to the app. The SETTING can be one of the following values. If not specified, is the default."), - ("AdditionalProbingPaths", "--additionalprobingpath", "IEnumerable", false, "Paths containing probing policy and assemblies to probe."), - ("AdditionalDeps", "--additional-deps", "string", false, "Path to an additional .deps.json file. A deps.json file contains a list of dependencies, compilation dependencies, and version information used to address assembly conflicts."), - ("FxVersion", "--fx-version", "string", false, "Version of the .NET runtime to use to run the application."), - ("Framework", "--framework", "string", false, "Builds and runs the app using the specified framework. The framework must be specified in the project file."), - ("Configuration", "--configuration", "string", false, "Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project."), - ("Runtime", "--runtime", "string", false, "Specifies the target runtime to restore packages for. For a list of Runtime Identifiers (RIDs), see the RID catalog. -r short option available since .NET Core 3.0 SDK."), - ("NoBuild", "--no-build", "bool?", false, "Doesn't build the project before running. It also implicit sets the --no-restore flag."), - ("NoRestore", "--no-restore", "bool?", false, "Adds a package reference without performing a restore preview and compatibility check."), - ("NoDependencies", "--no-dependencies", "bool?", false, "When restoring a project with project-to-project (P2P) references, restores the root project and not the references."), - ("NoIncremental", "--no-incremental", "bool?", false, "Marks the build as unsafe for incremental build. This flag turns off incremental compilation and forces a clean rebuild of the project's dependency graph."), - ("NoLogo", "--nologo", "bool?", false, "Doesn't display the startup banner or the copyright message."), - ("NoSelfContained", "--no-self-contained", "bool?", false, "Publishes the application as a framework dependent application. A compatible .NET runtime must be installed on the target machine to run the application. Available since .NET 6 SDK."), - ("SelfContained", "--self-contained", "bool?", false, "Publishes the .NET runtime with the application so the runtime doesn't need to be installed on the target machine. The default is true if a runtime identifier is specified. Available since .NET 6."), - ("Force", "--force", "bool?", false, "Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file."), - ("Arch", "--arch", "string", false, "Specifies the target architecture. This is a shorthand syntax for setting the Runtime Identifier (RID), where the provided value is combined with the default RID. For example, on a win-x64 machine, specifying --arch x86 sets the RID to win-x86. If you use this option, don't use the -r|--runtime option. Available since .NET 6 Preview 7."), - ("OS", "--os", "string", false, "Specifies the target operating system (OS). This is a shorthand syntax for setting the Runtime Identifier (RID), where the provided value is combined with the default RID. For example, on a win-x64 machine, specifying --os linux sets the RID to linux-x64. If you use this option, don't use the -r|--runtime option. Available since .NET 6."), - ("TerminalLogger", "--tl", "DotNetTerminalLogger?", false, "Specifies whether the terminal logger should be used for the build output."), - ("ArtifactsPath", "--artifacts-path", "string", false, "All build output files from the executed command will go in subfolders under the specified path, separated by project."), - ("DisableBuildServers", "--disable-build-servers", "bool?", false, "Forces the command to ignore any persistent build servers. This option provides a consistent way to disable all use of build caching, which forces a build from scratch. A build that doesn't rely on caches is useful when the caches might be corrupted or incorrect for some reason. Available since .NET 7 SDK."), - ("Output", "--output", "string", false, "Directory in which to place the built binaries. If not specified, the default path is ./bin/<configuration>/<framework>/. For projects with multiple target frameworks (via the TargetFrameworks property), you also need to define --framework when you specify this option."), - ("UseCurrentRuntime", "--use-current-runtime", "bool?", false, "Sets the RuntimeIdentifier to a platform portable RuntimeIdentifier based on the one of your machine. This happens implicitly with properties that require a RuntimeIdentifier, such as SelfContained, PublishAot, PublishSelfContained, PublishSingleFile, and PublishReadyToRun. If the property is set to false, that implicit resolution will no longer occur."), - ("VersionSuffix", "--version-suffix", "string", false, "Sets the value of the $(VersionSuffix) property to use when building the project. This only works if the $(Version) property isn't set. Then, $(Version) is set to the $(VersionPrefix) combined with the $(VersionSuffix), separated by a dash."), - ("TemplateName", "", "string", true, "The template to instantiate when the command is invoked. Each template might have specific options you can pass."), - ("Language", "--language", "DotNetLanguage?", false, ""), - ]; - - var commands = new ( - string Name, - string[] Comments, - string[] CommandArgs, - (string PropertyName, string ArgName, string Type, bool IsProject, string Comments)[] Args, - bool IsBuild, - bool IsTests, - string[] AdditionalArgs) - [] { - ( - "DotNet", - [ - "Runs a dotnet application.", - ps, - "You specify the path to an application .dll file to run the application. To run the application means to find and execute the entry point, which in the case of console apps is the Main method. For example, dotnet myapp.dll runs the myapp application.", - pf, - CreateRef("dotnet") - ], - ["$PathToApplication"], - [ - ("#AdditionalProbingPaths", "", "", false, ""), - ("#PathToApplication", "", "", false, ""), - ("#AdditionalDeps", "", "", false, ""), - ("#FxVersion", "", "", false, ""), - ("#RollForward", "", "RollForward", false, "") - ], - false, false, [] - ), - ( - "DotNetExec", - [ - "Executes a dotnet application.", - ps, - "You specify the path to an application .dll file to run the application. To run the application means to find and execute the entry point, which in the case of console apps is the Main method. For example, dotnet myapp.dll runs the myapp application.", - pf, - CreateRef("dotnet") - ], - ["exec", "$PathToApplication"], - [ - ("#AdditionalProbingPaths", "", "", false, ""), - ("#PathToApplication", "", "", false, ""), - ("DepsFile", "--depsfile", "string", false, "Path to a deps.json file. A deps.json file is a configuration file that contains information about dependencies necessary to run the application. This file is generated by the .NET SDK."), - ("#AdditionalDeps", "", "", false, ""), - ("#FxVersion", "", "", false, ""), - ("#RollForward", "", "RollForward", false, ""), - ("RuntimeConfig", "--runtimeconfig", "string", false, "Path to a runtimeconfig.json file. A runtimeconfig.json file contains run-time settings and is typically named <applicationname>.runtimeconfig.json."), - ], - false, false, [] - ), - ( - "DotNetAddPackage", - [ - "Adds or updates a package reference in a project file.", - ps, - "This command provides a convenient option to add or update a package reference in a project file. When you run the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes and the package isn't referenced in the project file, a <PackageReference> element is added to the project file. If the check passes and the package is already referenced in the project file, the <PackageReference> element is updated to the latest compatible version. After the project file is updated, dotnet restore is run.", - pf, - CreateRef("dotnet-add-package") - ], - ["add", "$Project", "package", "$PackageName"], - [ - ("Sources", "--source", "IEnumerable", false, "The URI of the NuGet package source to use during the restore operation."), - ("#Project", "", "", false, ""), - ("PackageName", "", "string", false, "The package reference to add."), - ("#Framework", "", "", false, "Adds a package reference only when targeting a specific framework."), - ("#NoRestore", "", "", false, ""), - ("PackageDirectory", "--package-directory", "string", false, @"The directory where to restore the packages. The default package restore location is %userprofile%\.nuget\packages on Windows and ~/.nuget/packages on macOS and Linux."), - ("Prerelease", "--prerelease", "bool?", false, "Allows prerelease packages to be installed. Available since .NET Core 5 SDK."), - ("Version", "--version", "string", false, "Version of the package"), - ], - false, false, [] - ), - ( - "DotNetListPackage", - [ - "Lists the package references for a project or solution.", - ps, - "This command provides a convenient option to list all NuGet package references for a specific project or a solution. You first need to build the project in order to have the assets needed for this command to process.", - pf, - CreateRef("dotnet-list-package") - ], - ["list", "$Project", "package"], - [ - ("Frameworks", "--framework", "IEnumerable", false, "Displays only the packages applicable for the specified target framework."), - ("Sources", "--source", "IEnumerable", false, "The NuGet sources to use when searching for newer packages. Requires the --outdated or --deprecated option."), - ("#Project", "", "", false, ""), - ("Config", "--config", "string", false, "The NuGet sources to use when searching for newer packages. Requires the --outdated option."), - ("Deprecated", "--deprecated", "bool?", false, "Displays packages that have been deprecated."), - ("HighestMinor", "--highest-minor", "bool?", false, "Considers only the packages with a matching major version number when searching for newer packages. Requires the --outdated or --deprecated option."), - ("HighestPatch", "--highest-patch", "bool?", false, "Considers only the packages with a matching major and minor version numbers when searching for newer packages. Requires the --outdated or --deprecated option."), - ("IncludePrerelease", "--include-prerelease", "bool?", false, "Considers packages with prerelease versions when searching for newer packages. Requires the --outdated or --deprecated option."), - ("IncludeTransitive", "--include-transitive", "bool?", false, "Lists transitive packages, in addition to the top-level packages. When specifying this option, you get a list of packages that the top-level packages depend on."), - ("Outdated", "--outdated", "bool?", false, "Lists packages that have newer versions available."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetRemovePackage", - [ - "Removes package reference from a project file.", - ps, - "This command provides a convenient option to remove a NuGet package reference from a project.", - pf, - CreateRef("dotnet-remove-package") - ], - ["remove", "$Project", "package", "$PackageName"], - [ - ("#Project", "", "", false, ""), - ("PackageName", "", "string", false, "The package reference to add."), - ], - false, false, [] - ), - ( - "DotNetAddReference", - [ - "Adds project-to-project (P2P) references.", - ps, - "This command provides a convenient option to add project references to a project. After running the command, the <ProjectReference> elements are added to the project file.", - pf, - CreateRef("dotnet-add-reference") - ], - ["add", "$Project", "reference", "$References"], - [ - ("References", "--source", "IEnumerable", false, "Project-to-project (P2P) references to add. Specify one or more projects. Glob patterns are supported on Unix/Linux-based systems."), - ("#Project", "", "", false, ""), - ("#Framework", "", "", false, "Adds project references only when targeting a specific framework using the TFM format.") - ], - false, false, [] - ), - ( - "DotNetListReference", - [ - "Lists project-to-project references.", - ps, - "This command provides a convenient option to list project references for a given project.", - pf, - CreateRef("dotnet-list-reference") - ], - ["list", "$Project"], - [ - ("#Project", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetRemoveReference", - [ - "Removes project-to-project (P2P) references.", - ps, - "This command provides a convenient option to remove project references from a project.", - pf, - CreateRef("dotnet-remove-reference") - ], - ["remove", "$Project", "reference", "$References"], - [ - ("References", "--source", "IEnumerable", false, "Project-to-project (P2P) references to remove. You can specify one or multiple projects. Glob patterns are supported on Unix/Linux based terminals."), - ("#Project", "", "", false, ""), - ("#Framework", "", "", false, "Removes the reference only when targeting a specific framework using the TFM format.") - ], - false, false, [] - ), - ( - "DotNetBuild", - [ - "Builds a project and all of its dependencies.", - ps, - "This command builds the project and its dependencies into a set of binaries. The binaries include the project's code in Intermediate Language (IL) files with a .dll extension. For executable projects targeting versions earlier than .NET Core 3.0, library dependencies from NuGet are typically NOT copied to the output folder. They're resolved from the NuGet global packages folder at run time. With that in mind, the product of dotnet build isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the dotnet publish command). For more information, see .NET Application Deployment.", - pf, - ps, - "For executable projects targeting .NET Core 3.0 and later, library dependencies are copied to the output folder. This means that if there isn't any other publish-specific logic (such as Web projects have), the build output should be deployable.", - pf, - "", - "", - "var configuration = Props.Get(\"configuration\", \"Release\");", - "", - "", - "new DotNetBuild().WithConfiguration(configuration)", - " .Build().EnsureSuccess();", - "", - "", - CreateRef("dotnet-build") - ], - ["build", "$Project"], - [ - ("Sources", "--source", "IEnumerable", false, "The URI of the NuGet package source to use during the restore operation."), - ("#Project", "", "", false, ""), - ("#Arch", "", "", false, ""), - ("#ArtifactsPath", "", "", false, ""), - ("#Configuration", "", "", false, ""), - ("#DisableBuildServers", "", "", false, ""), - ("#Framework", "", "", false, ""), - ("#Force", "", "", false, ""), - ("#NoDependencies", "", "", false, ""), - ("#NoIncremental", "", "", false, ""), - ("#NoRestore", "", "", false, ""), - ("#NoLogo", "", "", false, ""), - ("#NoSelfContained", "", "", false, ""), - ("#Output", "", "", false, ""), - ("#OS", "", "", false, ""), - ("#Runtime", "", "", false, ""), - ("#SelfContained", "", "", false, ""), - ("#TerminalLogger", "", "", false, ""), - ("#Verbosity", "", "", false, ""), - ("#UseCurrentRuntime", "", "", false, ""), - ("#VersionSuffix", "", "", false, ""), - ], - true, false, [] - ), - ( - "DotNetBuildServerShutdown", - [ - "Shuts down build servers that are started from dotnet.", - ps, - "By default, all servers are shut down.", - pf, - CreateRef("dotnet-build-server") - ], - ["build-server", "shutdown"], - [ - ("Servers", "", "IEnumerable", false, "Shuts down build servers that are started from dotnet. By default, all servers are shut down."), - ], - false, false, [] - ), - ( - "DotNetClean", - [ - "Cleans the output of a project.", - ps, - "This command cleans the output of the previous build. It's implemented as an MSBuild target, so the project is evaluated when the command is run. Only the outputs created during the build are cleaned. Both intermediate (obj) and final output (bin) folders are cleaned.", - pf, - CreateRef("dotnet-clean") - ], - ["clean", "$Project"], - [ - ("#Props", "", "", false, ""), - ("#Project", "", "", false, ""), - ("#ArtifactsPath", "", "", false, ""), - ("#Configuration", "", "", false, ""), - ("#Framework", "", "", false, ""), - ("#NoLogo", "", "", false, ""), - ("#Output", "", "", false, ""), - ("#Runtime", "", "", false, ""), - ("#TerminalLogger", "", "", false, ""), - ("#Verbosity", "", "", false, ""), - ], - true, false, [] - ), - ( - "DotNetDevCertsHttps", - [ - "Generates a self-signed certificate to enable HTTPS use in development.", - ps, - "This command manages a self-signed certificate to enable HTTPS use in local web app development. Its main functions are:", - "
- Generating a certificate for use with HTTPS endpoints during development.", - "
- Trusting the generated certificate on the local machine.", - "
- Removing the generated certificate from the local machine.", - "
- Exporting a certificate in various formats so that it can be used by other tools.", - "
- Importing an existing certificate generated by the tool into the local machine.", - pf, - CreateRef("dotnet-dev-certs") - ], - ["dev-certs", "https"], - [ - ("Check", "--check", "bool?", false, "Checks for the existence of the development certificate but doesn't perform any action. Use this option with the --trust option to check if the certificate is not only valid but also trusted."), - ("Clean", "--clean", "bool?", false, "Removes all HTTPS development certificates from the certificate store by using the .NET certificate store API. Doesn't remove any physical files that were created by using the --export-path option. On macOS in .NET 7.0, the dotnet dev-certs command creates the certificate on a path on disk, and the clean operation removes that certificate file."), - ("ExportPath", "--export-path", "string", false, "Exports the certificate to a file so that it can be used by other tools. Specify the full path to the exported certificate file, including the file name."), - ("Format", "--format", "string", false, "When used with --export-path, specifies the format of the exported certificate file. Valid values are PFX and PEM, case-insensitive. PFX is the default. The file format is independent of the file name extension. For example, if you specify --format pfx and --export-path ./cert.pem, you'll get a file named cert.pem in PFX format."), - ("Import", "--import", "string", false, "Imports the provided HTTPS development certificate into the local machine. Requires that you also specify the --clean option, which clears out any existing HTTPS developer certificates."), - ("NoPassword", "--no-password", "bool?", false, "Doesn't use a password for the key when exporting a certificate to PEM format files. The key file is exported in plain text. This option is not applicable to PFX files and is intended for internal testing use only."), - ("Password", "--password", "bool?", false, "Specifies the password to use."), - ("Quiet", "--quiet", "bool?", false, "Display warnings and errors only."), - ("Trust", "--trust", "bool?", false, "rusts the certificate on the local machine. If this option isn't specified, the certificate is added to the certificate store but not to a trusted list. When combined with the --check option, validates that the certificate is trusted."), - ("Verbose", "--verbose", "bool?", false, "Display debug information."), - ], - false, false, [] - ), - ( - "DotNetNew", - [ - "Creates a new project, configuration file, or solution based on the specified template.", - ps, - "This command creates a .NET project or other artifacts based on a template. The command calls the template engine to create the artifacts on disk based on the specified template and options.", - pf, - CreateRef("dotnet-new") - ], - ["new", "$TemplateName"], - [ - ("#TemplateName", "", "", false, "The template to instantiate when the command is invoked. Each template might have specific options you can pass."), - ("DryRun", "--dry-run", "bool?", false, "Displays a summary of what would happen if the given command were run if it would result in a template creation. Available since .NET Core 2.2 SDK."), - ("Force", "--force", "bool?", false, "Forces content to be generated even if it would change existing files. This is required when the template chosen would override existing files in the output directory."), - ("#Language", "", "", false, "The language of the template to create. The language accepted varies by the template (see defaults in the arguments section). Not valid for some templates."), - ("Name", "--name", "string", false, "The name for the created output. If no name is specified, the name of the current directory is used."), - ("#Framework", "", "", false, "Specifies the target framework. It expects a target framework moniker (TFM). Examples: \"net6.0\", \"net7.0-macos\". This value will be reflected in the project file."), - ("NoUpdateCheck", "-no-update-check", "bool?", false, "Disables checking for template package updates when instantiating a template. Available since .NET SDK 6.0.100."), - ("#Output", "", "", false, "Location to place the generated output. The default is the current directory."), - ("Project", "--project", "string", false, "The project that the template is added to. This project is used for context evaluation. If not specified, the project in the current or parent directories will be used. Available since .NET SDK 7.0.100."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNewList", - [ - "Lists available templates to be run using dotnet new.", - ps, - "This command lists available templates to use with dotnet new. If the <TEMPLATE_NAME> is specified, lists templates containing the specified name. This option lists only default and installed templates. To find templates in NuGet that you can install locally, use the search command.", - pf, - CreateRef("dotnet-new-list") - ], - ["new", "list", "$TemplateName"], - [ - ("Columns", "--columns", "IEnumerable", false, "Columns to display in the output."), - ("#TemplateName", "", "", false, "If the argument is specified, only the templates containing TEMPLATE_NAME in template name or short name will be shown."), - ("Author", "--author", "string", false, "Filters templates based on template author. Partial match is supported. Available since .NET SDK 5.0.300."), - ("ColumnsAll", "--columns-all", "bool?", false, "Displays all columns in the output. Available since .NET SDK 5.0.300."), - ("IgnoreConstraints", "--ignore-constraints", "bool?", false, "Disables checking if the template meets the constraints to be run. Available since .NET SDK 7.0.100."), - ("#Language", "", "", false, "Filters templates based on language supported by the template. The language accepted varies by the template. Not valid for some templates."), - ("#Output", "", "", false, "Location to place the generated output. The default is the current directory. For the list command, it might be necessary to specify the output directory to correctly evaluate constraints for the template. Available since .NET SDK 7.0.100."), - ("Project", "--project", "string", false, "The project that the template is added to. For the list command, it might be needed to specify the project the template is being added to to correctly evaluate constraints for the template. Available since .NET SDK 7.0.100."), - ("Tag", "--tag", "string", false, "Filters templates based on template tags. To be selected, a template must have at least one tag that exactly matches the criteria. Available since .NET SDK 5.0.300."), - ("Type", "--type", "DotNetTemplateType?", false, "Filters templates based on template type."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNewSearch", - [ - "Searches for the templates supported by dotnet new on NuGet.org.", - ps, - "This command searches for templates supported by dotnet new on NuGet.org. When the <TEMPLATE_NAME> is specified, searches for templates containing the specified name.", - pf, - CreateRef("dotnet-new-search") - ], - ["new", "search", "$TemplateName"], - [ - ("Columns", "--columns", "IEnumerable", false, "Columns to display in the output."), - ("#TemplateName", "", "", false, "If the argument is specified, only the templates containing TEMPLATE_NAME in template name or short name will be shown."), - ("Author", "--author", "string", false, "Filters templates based on template author. Partial match is supported. Available since .NET SDK 5.0.300."), - ("ColumnsAll", "--columns-all", "bool?", false, "Displays all columns in the output. Available since .NET SDK 5.0.300."), - ("#Language", "", "", false, "Filters templates based on language supported by the template."), - ("Package", "--package", "string", false, "Filters templates based on NuGet package ID. A partial match is supported."), - ("Tag", "--tag", "string", false, "Filters templates based on template tags. To be selected, a template must have at least one tag that exactly matches the criteria."), - ("Type", "--type", "DotNetTemplateType?", false, "Filters templates based on template type."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNewDetails", - [ - "Displays template package metadata.", - ps, - "This command displays the metadata of the template package from the package name provided. By default, the command searches for the latest available version. If the package is installed locally or is found on the official NuGet website, it also displays the templates that the package contains, otherwise it only displays basic metadata.", - pf, - CreateRef("dotnet-new-details") - ], - ["new", "details", "$TemplateName"], - [ - ("Sources", "--add-source", "IEnumerable", false, "By default, dotnet new details uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If --nuget-source is specified, the source is added to the list of sources to be checked."), - ("#TemplateName", "", "", false, "If the argument is specified, only the templates containing TEMPLATE_NAME in template name or short name will be shown."), - ("#Force", "", "", false, ""), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNewInstall", - [ - "Installs a template package.", - ps, - "This command installs a template package from the PATH or NUGET_ID provided. If you want to install a specific version or prerelease version of a template package, specify the version in the format <package-name>::<package-version>. By default, dotnet new passes * for the version, which represents the latest stable package version.", - pf, - CreateRef("dotnet-new-install") - ], - ["new", "install", "$Package"], - [ - ("Sources", "--add-source", "IEnumerable", false, "By default, dotnet new details uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If --nuget-source is specified, the source is added to the list of sources to be checked."), - ("Package", "", "string", true, "The folder on the file system or the NuGet package identifier to install the template package from. dotnet new attempts to install the NuGet package from the NuGet sources available for the current working directory and the sources specified via the --add-source option. If you want to install a specific version or prerelease version of a template package from NuGet source, specify the version in the format <package-name>::<package-version>."), - ("#Force", "", "", false, ""), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNewUninstall", - [ - "Uninstalls a template package.", - ps, - "This command uninstalls a template package at the PATH or NUGET_ID provided. When the <PATH|NUGET_ID> value isn't specified, all currently installed template packages and their associated templates are displayed. When specifying NUGET_ID, don't include the version number.", - pf, - CreateRef("dotnet-new-uninstall") - ], - ["new", "uninstall", "$Package"], - [ - ("Package", "", "string", true, "The folder on the file system or the NuGet package identifier the package was installed from. Note that the version for the NuGet package should not be specified."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNewUpdate", - [ - "Updates installed template packages.", - ps, - "This command updates installed template packages. The dotnet new update command with --check-only option checks for available updates for installed template packages without applying them.", - pf, - CreateRef("dotnet-new-update") - ], - ["new", "update"], - [ - ("Sources", "--add-source", "IEnumerable", false, "By default, dotnet new install uses the hierarchy of NuGet configuration files from the current directory to determine the NuGet source the package can be installed from. If Sources is specified, the source will be added to the list of sources to be checked. To check the configured sources for the current directory use dotnet nuget list source. Available since .NET SDK 7.0.100."), - ("CheckOnly", "--check-only", "bool?", false, "Only checks for updates and displays the template packages to be updated, without applying any updates."), - ("DryRun", "--dry-run", "bool?", false, "Only checks for updates and displays the template packages to be updated, without applying any updates."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetDelete", - [ - "Deletes or unlists a package from the server.", - ps, - "This command deletes or unlists a package from the server. For nuget.org, the action is to unlist the package.", - pf, - CreateRef("dotnet-nuget-delete") - ], - ["nuget", "delete", "$PackageName", "$PackageVersion"], - [ - ("PackageName", "", "string", true, "Name/ID of the package to delete."), - ("PackageVersion", "", "string", true, "Version of the package to delete."), - ("ForceEnglishOutput", "--force-english-output", "bool?", false, "Forces the application to run using an invariant, English-based culture."), - ("ApiKey", "--api-key", "string", false, "The API key for the server."), - ("NoServiceEndpoint", "--no-service-endpoint", "bool?", false, "Doesn't append \"api/v2/package\" to the source URL."), - ("Source", "--source", "string", false, "Specifies the server URL. NuGet identifies a UNC or local folder source and simply copies the file there instead of pushing it using HTTP."), - ], - false, false, ["--non-interactive"] - ), - ( - "DotNetNuGetLocalsClear", - [ - "Clears local NuGet resources.", - ps, - "This command clears local NuGet resources in the http-request cache, temporary cache, or machine-wide global packages folder.", - pf, - CreateRef("dotnet-nuget-locals") - ], - ["nuget", "locals", "$CacheLocation"], - [ - ("CacheLocation", "", "NuGetCacheLocation?", true, "The cache location to clear."), - ("ForceEnglishOutput", "--force-english-output", "bool?", false, "Forces the application to run using an invariant, English-based culture."), - ], - false, false, ["--clear"] - ), - ( - "DotNetNuGetLocalsList", - [ - "Lists local NuGet resources.", - ps, - "This command lists local NuGet resources in the http-request cache, temporary cache, or machine-wide global packages folder.", - pf, - CreateRef("dotnet-nuget-locals") - ], - ["nuget", "locals", "$CacheLocation"], - [ - ("CacheLocation", "", "NuGetCacheLocation?", true, "The cache location to list."), - ("ForceEnglishOutput", "--force-english-output", "bool?", false, "Forces the application to run using an invariant, English-based culture."), - ], - false, false, ["--list"] - ), - ( - "DotNetNuGetPush", - [ - "Pushes a package to the server and publishes it.", - ps, - @"This command pushes a package to the server and publishes it. The push command uses server and credential details found in the system's NuGet config file or chain of config files. NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.config (Windows) or $HOME/.nuget/NuGet/NuGet.Config (Linux/macOS), then loading any nuget.config or .nuget\nuget.config starting from the root of drive and ending in the current directory.", - pf, - CreateRef("dotnet-nuget-push") - ], - ["nuget", "push", "$Package"], - [ - ("Package", "", "string", true, "Specifies the file path to the package to be pushed."), - ("DisableBuffering", "--disable-buffering", "bool?", false, "Disables buffering when pushing to an HTTP(S) server to reduce memory usage."), - ("ForceEnglishOutput", "--force-english-output", "bool?", false, "Forces the application to run using an invariant, English-based culture."), - ("ApiKey", "--api-key", "string", false, "The API key for the server."), - ("NoSymbols", "--no-symbols", "bool?", false, "Doesn't push symbols (even if present)."), - ("NoServiceEndpoint", "--no-service-endpoint", "bool?", false, "Doesn't append \"api/v2/package\" to the source URL."), - ("Source", "--source", "string", false, "Specifies the server URL. NuGet identifies a UNC or local folder source and simply copies the file there instead of pushing it using HTTP."), - ("SkipDuplicate", "--skip-duplicate", "bool?", false, "When pushing multiple packages to an HTTP(S) server, treats any 409 Conflict response as a warning so that other pushes can continue."), - ("SymbolApiKey", "--symbol-api-key", "string", false, "The API key for the symbol server."), - ("SymbolSource", "--symbol-source", "string", false, "Specifies the symbol server URL."), - ("Timeout", "--timeout", "int?", false, "Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes). Specifying 0 applies the default value."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetAddSource", - [ - "Add a NuGet source.", - ps, - "This command adds a new package source to your NuGet configuration files. When adding multiple package sources, be careful not to introduce a dependency confusion vulnerability.", - pf, - CreateRef("dotnet-nuget-add-source") - ], - ["nuget", "add", "source", "$PackageSourcePath"], - [ - ("ValidAuthenticationTypes", "--valid-authentication-types", "IEnumerable", false, "List of valid authentication types for this source. Set this to basic if the server advertises NTLM or Negotiate and your credentials must be sent using the Basic mechanism, for instance when using a PAT with on-premises Azure DevOps Server. Other valid values include negotiate, kerberos, ntlm, and digest, but these values are unlikely to be useful."), - ("PackageSourcePath", "", "string", true, "Path to the package source."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("AllowInsecureConnections", "--allow-insecure-connections", "bool?", false, "Allows HTTP connections for adding or updating packages. This method is not secure. Available since .NET 9 SDK."), - ("Name", "--name", "string", false, "Name of the source."), - ("Password", "--password", "string", false, "Password to be used when connecting to an authenticated source."), - ("StorePasswordInClearText", "--store-password-in-clear-text", "bool?", false, "Enables storing portable package source credentials by disabling password encryption. Storing passwords in clear text is strongly discouraged."), - ("Username", "--username", "string", false, "Username to be used when connecting to an authenticated source."), - ], - false, false, [] - ), - ( - "DotNetNuGetDisableSource", - [ - "Disable a NuGet source.", - ps, - "This command disables an existing source in your NuGet configuration files.", - pf, - CreateRef("dotnet-nuget-disable-source") - ], - ["nuget", "disable", "source", "$Name"], - [ - ("Name", "--name", "string", true, "Name of the source."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations."), - ], - false, false, [] - ), - ( - "DotNetNuGetEnableSource", - [ - "Enable a NuGet source.", - ps, - "This command enables an existing source in your NuGet configuration files.", - pf, - CreateRef("dotnet-nuget-enable-source") - ], - ["nuget", "enable", "source", "$Name"], - [ - ("Name", "--name", "string", true, "Name of the source."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ], - false, false, [] - ), - ( - "DotNetNuGetListSource", - [ - "Lists all configured NuGet sources.", - ps, - "This command lists all existing sources from your NuGet configuration files.", - pf, - CreateRef("dotnet-nuget-list-source") - ], - ["nuget", "list", "source"], - [ - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations."), - ("Format", "--format", "NuGetListFormat?", false, "The format of the list command output: Detailed (the default) and Short."), - ], - false, false, [] - ), - ( - "DotNetNuGetRemoveSource", - [ - "Remove a NuGet source.", - ps, - "This command removes an existing source from your NuGet configuration files.", - pf, - CreateRef("dotnet-nuget-remove-source") - ], - ["nuget", "remove", "source", "$Name"], - [ - ("Name", "--name", "string", true, "Name of the source."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used. For more information, see Common NuGet Configurations."), - ], - false, false, [] - ), - ( - "DotNetNuGetUpdateSource", - [ - "Update a NuGet source.", - ps, - "This command updates an existing source in your NuGet configuration files.", - pf, - CreateRef("dotnet-nuget-update-source") - ], - ["nuget", "update", "source", "$Name"], - [ - ("ValidAuthenticationTypes", "--valid-authentication-types", "IEnumerable", false, "List of valid authentication types for this source. Set this to basic if the server advertises NTLM or Negotiate and your credentials must be sent using the Basic mechanism, for instance when using a PAT with on-premises Azure DevOps Server. Other valid values include negotiate, kerberos, ntlm, and digest, but these values are unlikely to be useful."), - ("Name", "--name", "string", true, "Name of the source."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("Password", "--password", "string", false, "Password to be used when connecting to an authenticated source."), - ("Source", "", "string", true, "Path to the package source."), - ("StorePasswordInClearText", "--store-password-in-clear-text", "bool?", false, "Enables storing portable package source credentials by disabling password encryption. Storing passwords in clear text is strongly discouraged."), - ("Username", "--username", "string", false, "Username to be used when connecting to an authenticated source."), - ], - false, false, [] - ), - ( - "DotNetNuGetVerify", - [ - "Verifies a signed NuGet package.", - ps, - "This command verifies a signed NuGet package. This command requires a certificate root store that is valid for both code signing and timestamping. Also, this command may not be supported on some combinations of operating system and .NET SDK.", - pf, - CreateRef("dotnet-nuget-verify") - ], - ["nuget", "verify", "$Packages"], - [ - ("Packages", "", "IEnumerable", false, "Specifies the file path to the package(s) to be verified."), - ("Fingerprints", "--certificate-fingerprint", "IEnumerable", false, "Verify that the signer certificate matches with one of the specified SHA256 fingerprints. This option can be supplied multiple times to provide multiple fingerprints."), - ("All", "--all", "bool?", false, "Specifies that all verifications possible should be performed on the package(s). By default, only signatures are verified."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustList", - [ - "Lists all the trusted signers in the configuration.", - ps, - "This option will include all the certificates (with fingerprint and fingerprint algorithm) each signer has. If a certificate has a preceding [U], it means that certificate entry has allowUntrustedRoot set as true.", - pf, - CreateRef("dotnet-nuget-trust#list") - ], - ["nuget", "trust", "list"], - [ - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustSync", - [ - "Deletes the current list of certificates and replaces them with an up-to-date list from the repository.", - CreateRef("dotnet-nuget-trust#sync") - ], - ["nuget", "trust", "sync", "$Name"], - [ - ("Name", "", "string", true, "The name of the existing trusted signer to sync."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustRemove", - [ - "Removes any trusted signers that match the given name.", - CreateRef("dotnet-nuget-trust#sync") - ], - ["nuget", "trust", "remove", "$Name"], - [ - ("Name", "", "string", true, "The name of the existing trusted signer to remove."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustAuthor", - [ - "Adds a trusted signer with the given name, based on the author signature of the package.", - CreateRef("dotnet-nuget-trust#author") - ], - ["nuget", "trust", "author", "$Name", "$Package"], - [ - ("Name", "", "string", true, "The name of the trusted signer to add. If NAME already exists in the configuration, the signature is appended."), - ("Package", "", "string", true, "The given PACKAGE should be a local path to the signed .nupkg file."), - ("AllowUntrustedRoot", "--allow-untrusted-root", "bool?", false, "Specifies if the certificate for the trusted signer should be allowed to chain to an untrusted root. This is not recommended."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustRepository", - [ - "Adds a trusted signer with the given name, based on the repository signature or countersignature of a signed package.", - CreateRef("dotnet-nuget-trust#repository") - ], - ["nuget", "trust", "repository", "$Name", "$Package"], - [ - ("Owners", "--owners", "IReadOnlyCollection", false, "List of trusted owners to further restrict the trust of a repository."), - ("Name", "", "string", true, "The name of the trusted signer to add. If NAME already exists in the configuration, the signature is appended."), - ("Package", "", "string", true, "The given PACKAGE should be a local path to the signed .nupkg file."), - ("AllowUntrustedRoot", "--allow-untrusted-root", "bool?", false, "Specifies if the certificate for the trusted signer should be allowed to chain to an untrusted root. This is not recommended."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustCertificate", - [ - "Adds a trusted signer with the given name, based on a certificate fingerprint.", - CreateRef("dotnet-nuget-trust#certificate") - ], - ["nuget", "trust", "certificate", "$Name", "$Fingerprint"], - [ - ("Name", "", "string", true, "The name of the trusted signer to add. If a trusted signer with the given name already exists, the certificate item is added to that signer. Otherwise a trusted author is created with a certificate item from the given certificate information."), - ("Fingerprint", "", "string", true, "The fingerprint of the certificate."), - ("Algorithm", "--algorithm", "NuGetCertificateAlgorithm?", false, "Specifies the hash algorithm used to calculate the certificate fingerprint. Defaults to SHA256. Values supported are SHA256, SHA384 and SHA512."), - ("AllowUntrustedRoot", "--allow-untrusted-root", "bool?", false, "Specifies if the certificate for the trusted signer should be allowed to chain to an untrusted root. This is not recommended."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetTrustSource", - [ - "Adds a trusted signer based on a given package source.", - CreateRef("dotnet-nuget-trust#source") - ], - ["nuget", "trust", "source", "$Name" ], - [ - ("Owners", "--owners", "IReadOnlyCollection", false, "List of trusted owners to further restrict the trust of a repository."), - ("Name", "", "string", true, "The name of the trusted signer to add. If only <NAME> is provided without --<source-url>, the package source from your NuGet configuration files with the same name is added to the trusted list. If <NAME> already exists in the configuration, the package source is appended to it."), - ("ConfigFile", "--configfile", "string", false, "The NuGet configuration file (nuget.config) to use. If specified, only the settings from this file will be used. If not specified, the hierarchy of configuration files from the current directory will be used."), - ("SourceUrl", "--source-url", "string", false, "If a source-url is provided, it must be a v3 package source URL (like https://api.nuget.org/v3/index.json). Other package source types are not supported."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetSign", - [ - "Signs all the NuGet packages matching the first argument with a certificate.", - ps, - "This command signs all the packages matching the first argument with a certificate. The certificate with the private key can be obtained from a file or from a certificate installed in a certificate store by providing a subject name or a SHA-1 fingerprint. This command requires a certificate root store that is valid for both code signing and timestamping. Also, this command may not be supported on some combinations of operating system and .NET SDK.", - pf, - CreateRef("dotnet-nuget-sign") - ], - ["nuget", "sign", "$Packages"], - [ - ("Packages", "--owners", "IEnumerable", true, "Specifies the file path to the packages to be signed."), - ("CertificatePath", "--certificate-path", "string", false, "Specifies the file path to the certificate to be used in signing the package. This option currently supports only PKCS12 (PFX) files that contain the certificate's private key."), - ("CertificateStoreName", "--certificate-store-name", "string", false, "Specifies the name of the X.509 certificate store to use to search for the certificate. Defaults to \"My\", the X.509 certificate store for personal certificates. This option should be used when specifying the certificate via --certificate-subject-name or --certificate-fingerprint options."), - ("CertificateStoreLocation", "--certificate-store-location", "string", false, "Specifies the name of the X.509 certificate store use to search for the certificate. Defaults to \"CurrentUser\", the X.509 certificate store used by the current user. This option should be used when specifying the certificate via --certificate-subject-name or --certificate-fingerprint options."), - ("CertificateSubjectName", "--certificate-subject-name", "string", false, "Specifies the subject name of the certificate used to search a local certificate store for the certificate. The search is a case-insensitive string comparison using the supplied value, which finds all certificates with the subject name containing that string, regardless of other subject values. The certificate store can be specified by --certificate-store-name and --certificate-store-location options. This option currently supports only a single matching certificate in the result. If there are multiple matching certificates in the result, or no matching certificate in the result, the sign command will fail."), - ("CertificateFingerprint", "--certificate-fingerprint", "string", false, "Specifies the fingerprint of the certificate used to search a local certificate store for the certificate. Starting with .NET 9, this option can be used to specify the SHA-1, SHA-256, SHA-384, or SHA-512 fingerprint of the certificate. However, a NU3043 warning is raised when a SHA-1 certificate fingerprint is used because it is no longer considered secure. All the previous versions of the .NET SDK continue to accept only SHA-1 certificate fingerprint."), - ("CertificatePassword", "--certificate-password", "string", false, "Specifies the certificate password, if needed. If a certificate is password protected but no password is provided, the sign command will fail."), - ("HashAlgorithm", "--hash-algorithm", "NuGetCertificateAlgorithm?", false, "Hash algorithm to be used to sign the package. Defaults to SHA256. Possible values are SHA256, SHA384, and SHA512."), - ("Output", "--output", "string", false, "Specifies the directory where the signed package should be saved. If this option isn't specified, by default the original package is overwritten by the signed package."), - ("Overwrite", "--overwrite", "bool?", false, "Indicate that the current signature should be overwritten. By default the command will fail if the package already has a signature."), - ("TimestampHashAlgorithm", "--timestamp-hash-algorithm", "NuGetCertificateAlgorithm?", false, "Hash algorithm to be used by the RFC 3161 timestamp server. Defaults to SHA256."), - ("TimestampingServer", "--timestamper", "string", false, "URL to an RFC 3161 timestamping server."), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ), - ( - "DotNetNuGetWhy", - [ - "Shows the dependency graph for a particular package.", - ps, - @"This command shows the dependency graph for a particular package for a given project or solution. Starting from the .NET 9 SDK, it's possible to pass a NuGet assets file in place of the project file, in order to use the command with projects that can't be restored with the .NET SDK. First, restore the project in Visual Studio, or msbuild.exe. By default the assets file is in the project's obj\ directory, but you can find the location with msbuild.exe path\to\project.proj -getProperty:ProjectAssetsFile. Finally, run dotnet nuget why path\to\project.assets.json SomePackage.", - pf, - CreateRef("dotnet-nuget-why") - ], - ["nuget", "why", "$Project", "$Package"], - [ - ("Frameworks", "--framework", "IEnumerable", false, "The target frameworks for which dependency graphs are shown."), - ("Project", "", "string", true, "The project or solution file to operate on. If a directory is specified, the command searches the directory for a project or solution file. If more than one project or solution is found, an error is thrown."), - ("Package", "", "string", true, "The package name to look up in the dependency graph."), - ], - false, false, [] - ), - ( - "DotNetRun", - [ - "Runs source code without any explicit compile or launch commands.", - ps, - "This command provides a convenient option to run your application from the source code with one command. It's useful for fast iterative development from the command line. The command depends on the dotnet build command to build the code. Any requirements for the build apply to dotnet run as well.", - pf, - ps, - "To run the application, the dotnet run command resolves the dependencies of the application that are outside of the shared runtime from the NuGet cache. Because it uses cached dependencies, it's not recommended to use dotnet run to run applications in production. Instead, create a deployment using the dotnet publish command and deploy the published output.", - pf, - "", - "", - "var result = new DotNetNew(\"console\", \"-n\", \"MyApp\", \"--force\")", - " .Build().EnsureSuccess();", - "", - "", - "new DotNetRun().WithWorkingDirectory(\"MyApp\")", - " .Build().EnsureSuccess();", - "", - "", - CreateRef("dotnet-run") - ], - ["run", "$Project"], - [ - ("#Props", "", "", false, ""), - ("#Project", "", "", false, ""), - ("#Arch", "", "", false, ""), - ("#Configuration", "", "", false, ""), - ("#Framework", "", "", false, ""), - ("#Force", "", "", false, ""), - ("LaunchProfile", "--launch-profile", "string", false, "The name of the launch profile (if any) to use when launching the application. Launch profiles are defined in the launchSettings.json file and are typically called Development, Staging, and Production."), - ("#NoBuild", "", "", false, ""), - ("#NoDependencies", "", "", false, ""), - ("NoLaunchProfile", "--no-launch-profile", "bool?", false, "Doesn't try to use launchSettings.json to configure the application."), - ("#NoRestore", "", "", false, ""), - ("#OS", "", "", false, ""), - ("#Runtime", "", "", false, ""), - ("#TerminalLogger", "", "", false, ""), - ("#Verbosity", "", "", false, ""), - ], - false, false, [] - ) - }; -#> -using Internal.DotNet; - -<# - var args = commonArgs.ToDictionary(i => i.PropertyName, i => i); - foreach (var command in commands) - { - for (var i = 0; i < command.Args.Length; i++) - { - var arg = command.Args[i]; - if (arg.PropertyName.StartsWith("#") && args.TryGetValue(arg.PropertyName.Substring(1), out var newArg)) - { - var comments = arg.Comments; - if (!string.IsNullOrWhiteSpace(comments)) - { - newArg.Comments = comments; - } - - command.Args[i] = newArg; - } - } - - var name = command.Name; - var commandArgs = new List(); - foreach (var arg in command.CommandArgs) - { - if (arg.StartsWith("$")) - { - var curArg = arg.Substring(1); - var notEmpty = command.Args.FirstOrDefault(i => i.PropertyName == curArg && IsCollection(i.Type)); - if (!string.IsNullOrWhiteSpace(notEmpty.PropertyName)) - { - var compositeArg = $"new [] {{{string.Join(", ", commandArgs)}}}.Concat({curArg}).ToArray()"; - commandArgs.Clear(); - commandArgs.Add(compositeArg); - } - else - { - commandArgs.Add($"{curArg}.ToArg()"); - } - } - else - { - commandArgs.Add($"\"{arg}\""); - } - } -#> -/// -<# - foreach (var comment in command.Comments) - { -#> -/// <#= comment #> -<# - } -#> -/// -/// Specifies the set of command line arguments to use when starting the tool. -/// Specifies the set of environment variables that apply to this process and its child processes. -<# - foreach (var arg in command.Args.Where(i => IsCollection(i.Type))) - { -#> -/// <#= arg.Comments #> -<# - } -#> -/// Overrides the tool executable path. -/// Specifies the working directory for the tool to be started. -<# - foreach (var arg in command.Args.Where(i => !IsCollection(i.Type))) - { -#> -/// <#= arg.Comments #> -<# - } -#> -/// Enables diagnostic output. -/// Specifies a short name for this operation. -[Target] -public partial record <#= command.Name #>( - IEnumerable Args, - IEnumerable<(string name, string value)> Vars, -<# - var initializer = string.Join(", ", new [] {"args", "[]"}.Concat(Enumerable.Repeat("[]", command.Args.Count(i => IsCollection(i.Type))))); - var fullInitializer = string.Join(", ", new [] {"[]", "[]"}.Concat(Enumerable.Repeat("[]", command.Args.Count(i => IsCollection(i.Type))))); - foreach (var arg in command.Args) - { - var type = arg.Type; - var defaultValue = ""; - if (type == "string") - { - defaultValue = " = \"\""; - } - else - { - if (!IsCollection(type)) - { - defaultValue = " = default"; - } - } -#> - <#= type #> <#= arg.PropertyName #><#= defaultValue #>, -<# - } -#> - string ExecutablePath = "", - string WorkingDirectory = "", - bool? Diagnostics = default, - string ShortName = "") -{ - /// - /// Create a new instance of the command. - /// - /// Specifies the set of command line arguments to use when starting the tool. - public <#= name #>(params string[] args) - : this(<#= initializer #>) - { - } - - /// - /// Create a new instance of the command. - /// - public <#= name #>() - : this(<#= fullInitializer #>) - { - } - - /// - public IStartInfo GetStartInfo(IHost host) - { - if (host == null) throw new ArgumentNullException(nameof(host)); - return host.CreateCommandLine(ExecutablePath) - .WithShortName(ToString()) - .WithWorkingDirectory(WorkingDirectory) - .WithVars(Vars.ToArray()) -<# - foreach (var arg in command.CommandArgs) - { - if (arg.StartsWith("$")) - { - var notEmptyArg = arg.Substring(1); - var notEmpty = command.Args.FirstOrDefault(i => i.PropertyName == notEmptyArg && IsCollection(i.Type)); - if (!string.IsNullOrWhiteSpace(notEmpty.PropertyName)) - { - notEmptyArg = $"{notEmptyArg}.ToArray()"; - } -#> - .AddNotEmptyArgs(<#= notEmptyArg #>.ToArg()) -<# - } - else - { -#> - .AddArgs("<#= arg #>") -<# - } - } -#> -<# - if (command.IsBuild) - { -#> - .AddMSBuildLoggers(host, Verbosity) -<# - } - - if (command.IsTests) - { -#> - .AddTestLoggers(host, Loggers) -<# - } - - foreach (var additionalArg in command.AdditionalArgs) - { -#> - .AddArgs("<#= additionalArg #>") -<# - } - - foreach (var arg in command.Args.Where(i => !i.IsProject).Where(i => IsCollection(i.Type) && i.ArgName != "--property")) - { -#> - .AddArgs(<#= arg.PropertyName #>.ToArgs("<#= arg.ArgName #>")) -<# - } - - foreach(var arg in command.Args.Where(i => !i.IsProject).Where(i => !string.IsNullOrWhiteSpace(i.ArgName) && !i.Type.StartsWith("bool") && !IsCollection(i.Type))) - { -#> - .AddArgs(<#= arg.PropertyName #>.ToArgs("<#= arg.ArgName #>")) -<# - } -#> - .AddBooleanArgs( -<# - var boolArgs = command.Args.Where(i => !string.IsNullOrWhiteSpace(i.ArgName) && i.Type.StartsWith("bool")).ToArray(); - for (var i = 0; i < boolArgs.Length; i++) - { - var arg = boolArgs[i]; -#> - ("<#= arg.ArgName #>", <#= arg.PropertyName #>), -<# - } -#> - ("--diagnostics", Diagnostics) - ) -<# - foreach (var arg in command.Args.Where(i => !string.IsNullOrWhiteSpace(i.ArgName) && IsCollection(i.Type) && i.ArgName == "--property").ToArray()) - { -#> - .AddProps("--property", <#= arg.PropertyName #>.ToArray()) -<# - } -#> - .AddArgs(Args.ToArray()); - } - - /// - public override string ToString() => "".GetShortName(ShortName, <#= string.Join(", ", commandArgs) #>); -} - -<# - } -#> diff --git a/CSharpInteractive.Tests/README_TEMPLATE.md b/CSharpInteractive.Tests/README_TEMPLATE.md index e3f7278..9605185 100644 --- a/CSharpInteractive.Tests/README_TEMPLATE.md +++ b/CSharpInteractive.Tests/README_TEMPLATE.md @@ -486,15 +486,16 @@ var result = new DockerRun(cmd, "mcr.microsoft.com/dotnet/sdk") using HostApi; // Creates a new library project, running a command like: "dotnet new classlib -n MyLib --force" -new DotNetNew("xunit", "-n", "MyLib", "--force") - .Build() - .EnsureSuccess(); +new DotNetNew() + .WithTemplateName("xunit") + .WithName("MyLib") + .WithForce(true) + .Build().EnsureSuccess(); // Builds the library project, running a command like: "dotnet build" from the directory "MyLib" var result = new DotNetBuild() .WithWorkingDirectory("MyLib") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); // The "result" variable provides details about a build result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(); @@ -522,25 +523,25 @@ result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); using HostApi; // Creates a new library project, running a command like: "dotnet new classlib -n MyLib --force" -var result = new DotNetNew("classlib", "-n", "MyLib", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("classlib") + .WithName("MyLib") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); // Builds the library project, running a command like: "dotnet build" from the directory "MyLib" result = new DotNetBuild() .WithWorkingDirectory("MyLib") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); // Clean the project, running a command like: "dotnet clean" from the directory "MyLib" result = new DotNetClean() .WithWorkingDirectory("MyLib") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); // The "result" variable provides details about a build result.ExitCode.ShouldBe(0); @@ -576,23 +577,24 @@ version.ShouldNotBeNull(); using HostApi; // Creates a new test project, running a command like: "dotnet new mstest -n MyTests --force" -var result = new DotNetNew("mstest", "-n", "MyTests", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("mstest") + .WithName("MyTests") + .WithForce(true) + .Build().EnsureSuccess(); -result.ExitCode.ShouldBe(0); +result.ExitCode.ShouldBe(0, result.ToString()); // Runs tests via a command like: "dotnet msbuild /t:VSTest" from the directory "MyTests" result = new MSBuild() .WithTarget("VSTest") .WithWorkingDirectory("MyTests") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); // The "result" variable provides details about a build -result.ExitCode.ShouldBe(0); -result.Summary.Tests.ShouldBe(1); -result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); +result.ExitCode.ShouldBe(0, result.ToString()); +result.Summary.Tests.ShouldBe(1, result.ToString()); +result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1, result.ToString()); ``` @@ -606,9 +608,11 @@ result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); using HostApi; // Creates a new library project, running a command like: "dotnet new classlib -n MyLib --force" -var result = new DotNetNew("classlib", "-n", "MyLib", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("classlib") + .WithName("MyLib") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -616,8 +620,7 @@ result.ExitCode.ShouldBe(0); result = new DotNetPack() .WithWorkingDirectory("MyLib") .AddProps(("version", "1.2.3")) - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); ``` @@ -633,9 +636,12 @@ result.ExitCode.ShouldBe(0); using HostApi; // Creates a new library project, running a command like: "dotnet new classlib -n MyLib --force" -var result = new DotNetNew("classlib", "-n", "MyLib", "--force", "-f", "net8.0") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("classlib") + .AddArgs("-f", "net8.0") + .WithName("MyLib") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -643,8 +649,7 @@ result.ExitCode.ShouldBe(0); result = new DotNetPublish() .WithWorkingDirectory("MyLib") .WithFramework("net8.0") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); ``` @@ -660,17 +665,18 @@ result.ExitCode.ShouldBe(0); using HostApi; // Creates a new library project, running a command like: "dotnet new classlib -n MyLib --force" -var result = new DotNetNew("classlib", "-n", "MyLib", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("classlib") + .WithName("MyLib") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); // Restore the project, running a command like: "dotnet restore" from the directory "MyLib" result = new DotNetRestore() .WithWorkingDirectory("MyLib") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); ``` @@ -686,9 +692,11 @@ result.ExitCode.ShouldBe(0); using HostApi; // Creates a new console project, running a command like: "dotnet new console -n MyApp --force" -var result = new DotNetNew("console", "-n", "MyApp", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("console") + .WithName("MyApp") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -715,9 +723,11 @@ stdOut.ShouldBe(new[] {"Hello, World!"}); using HostApi; // Creates a new test project, running a command like: "dotnet new mstest -n MyTests --force" -var result = new DotNetNew("mstest", "-n", "MyTests", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("mstest") + .WithName("MyTests") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -744,20 +754,21 @@ result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); using HostApi; // Creates a new test project, running a command like: "dotnet new mstest -n MyTests --force" -new DotNetNew("mstest", "-n", "MyTests", "--force") - .Run() - .EnsureSuccess(); +new DotNetNew() + .WithTemplateName("mstest") + .WithName("MyTests") + .WithForce(true) + .Run().EnsureSuccess(); // Creates the tool manifest and installs the dotCover tool locally // It is better to run the following 2 commands manually // and commit these changes to a source control -new DotNetNew("tool-manifest") - .Run() - .EnsureSuccess(); +new DotNetNew() + .WithTemplateName("tool-manifest") + .Run().EnsureSuccess(); new DotNetCustom("tool", "install", "--local", "JetBrains.dotCover.GlobalTool") - .Run() - .EnsureSuccess(); + .Run().EnsureSuccess(); // Creates a test command var test = new DotNetTest() @@ -778,8 +789,7 @@ var testUnderDotCover = test.Customize(cmd => // Runs tests under dotCover via a command like: "dotnet dotcover test ..." var result = testUnderDotCover - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); // The "result" variable provides details about a build result.ExitCode.ShouldBe(0); @@ -807,7 +817,8 @@ var projectDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()[..4] Directory.CreateDirectory(projectDir); // Creates a local tool manifest -new DotNetNew("tool-manifest") +new DotNetNew() + .WithTemplateName("tool-manifest") .WithWorkingDirectory(projectDir) .Run() .EnsureSuccess(); @@ -830,9 +841,11 @@ new DotNetToolRestore() using HostApi; // Creates a new test project, running a command like: "dotnet new mstest -n MyTests --force" -var result = new DotNetNew("mstest", "-n", "MyTests", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("mstest") + .WithName("MyTests") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -841,8 +854,7 @@ result = new DotNetBuild() .WithWorkingDirectory("MyTests") .WithConfiguration("Release") .WithOutput("MyOutput") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -850,8 +862,7 @@ result.ExitCode.ShouldBe(0); result = new VSTest() .AddTestFileNames(Path.Combine("MyOutput", "MyTests.dll")) .WithWorkingDirectory("MyTests") - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); // The "result" variable provides details about a build result.ExitCode.ShouldBe(0); @@ -870,9 +881,11 @@ result.Tests.Count(test => test.State == TestState.Finished).ShouldBe(1); using HostApi; // Creates a new library project, running a command like: "dotnet new classlib -n MyLib --force" -var result = new DotNetNew("classlib", "-n", "MyLib", "--force") - .Build() - .EnsureSuccess(); +var result = new DotNetNew() + .WithTemplateName("classlib") + .WithName("MyLib") + .WithForce(true) + .Build().EnsureSuccess(); result.ExitCode.ShouldBe(0); @@ -883,8 +896,7 @@ result = new MSBuild() .WithRestore(true) .AddProps(("configuration", "Release")) .WithVerbosity(DotNetVerbosity.Detailed) - .Build() - .EnsureSuccess(); + .Build().EnsureSuccess(); // The "result" variable provides details about a build result.Errors.Any(message => message.State == BuildMessageState.StdError).ShouldBeFalse(); diff --git a/CSharpInteractive.Tests/README_TEMPLATE.tt b/CSharpInteractive.Tests/README_TEMPLATE.tt index 119cfac..4ad63b1 100644 --- a/CSharpInteractive.Tests/README_TEMPLATE.tt +++ b/CSharpInteractive.Tests/README_TEMPLATE.tt @@ -48,7 +48,7 @@ { var parts = str.Substring(4, str.Length - 4).Split([ '=' - ], 2, StringSplitOptions.RemoveEmptyEntries); + ], 2, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var key = parts[0];