Skip to content

Commit 880be06

Browse files
Use DotNet command template
1 parent 8b85e3f commit 880be06

File tree

3 files changed

+199
-124
lines changed

3 files changed

+199
-124
lines changed

CSharpInteractive.HostApi/DotNetCommands.cs

Lines changed: 148 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public IStartInfo GetStartInfo(IHost host)
170170
/// <param name="Project">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.</param>
171171
/// <param name="PackageName">The package reference to add.</param>
172172
/// <param name="Framework">Adds a package reference only when targeting a specific framework.</param>
173-
/// <param name="NoRestore">Adds a package reference without performing a restore preview and compatibility check.</param>
173+
/// <param name="NoRestore">Doesn't execute an implicit restore when running the command.</param>
174174
/// <param name="PackageDirectory">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.</param>
175175
/// <param name="Prerelease">Allows prerelease packages to be installed. Available since .NET Core 5 SDK.</param>
176176
/// <param name="Version">Version of the package</param>
@@ -615,6 +615,7 @@ public IStartInfo GetStartInfo(IHost host)
615615
/// </summary>
616616
/// <param name="Args">Specifies the set of command line arguments to use when starting the tool.</param>
617617
/// <param name="Vars">Specifies the set of environment variables that apply to this process and its child processes.</param>
618+
/// <param name="Props">MSBuild options for setting properties.</param>
618619
/// <param name="Sources">The URI of the NuGet package source to use during the restore operation.</param>
619620
/// <param name="ExecutablePath">Overrides the tool executable path.</param>
620621
/// <param name="WorkingDirectory">Specifies the working directory for the tool to be started.</param>
@@ -627,7 +628,7 @@ public IStartInfo GetStartInfo(IHost host)
627628
/// <param name="Force">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.</param>
628629
/// <param name="NoDependencies">When restoring a project with project-to-project (P2P) references, restores the root project and not the references.</param>
629630
/// <param name="NoIncremental">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.</param>
630-
/// <param name="NoRestore">Adds a package reference without performing a restore preview and compatibility check.</param>
631+
/// <param name="NoRestore">Doesn't execute an implicit restore when running the command.</param>
631632
/// <param name="NoLogo">Doesn't display the startup banner or the copyright message.</param>
632633
/// <param name="NoSelfContained">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.</param>
633634
/// <param name="Output">Directory in which to place the built binaries. If not specified, the default path is ./bin/&lt;configuration&gt;/&lt;framework&gt;/. For projects with multiple target frameworks (via the TargetFrameworks property), you also need to define --framework when you specify this option.</param>
@@ -644,6 +645,7 @@ public IStartInfo GetStartInfo(IHost host)
644645
public partial record DotNetBuild(
645646
IEnumerable<string> Args,
646647
IEnumerable<(string name, string value)> Vars,
648+
IEnumerable<(string name, string value)> Props,
647649
IEnumerable<string> Sources,
648650
string Project = "",
649651
string Arch = "",
@@ -675,15 +677,15 @@ public partial record DotNetBuild(
675677
/// </summary>
676678
/// <param name="args">Specifies the set of command line arguments to use when starting the tool.</param>
677679
public DotNetBuild(params string[] args)
678-
: this(args, [], [])
680+
: this(args, [], [], [])
679681
{
680682
}
681683

682684
/// <summary>
683685
/// Create a new instance of the command.
684686
/// </summary>
685687
public DotNetBuild()
686-
: this([], [], [])
688+
: this([], [], [], [])
687689
{
688690
}
689691

@@ -721,6 +723,7 @@ public IStartInfo GetStartInfo(IHost host)
721723
("--use-current-runtime", UseCurrentRuntime),
722724
("--diagnostics", Diagnostics)
723725
)
726+
.AddProps("--property", Props.ToArray())
724727
.AddArgs(Args.ToArray());
725728
}
726729

@@ -3251,6 +3254,143 @@ public IStartInfo GetStartInfo(IHost host)
32513254
public override string ToString() => "".GetShortName(ShortName, "nuget", "config", "paths");
32523255
}
32533256

3257+
/// <summary>
3258+
/// Packs the code into a NuGet package.
3259+
/// <p>
3260+
/// The dotnet pack command builds the project and creates NuGet packages. The result of this command is a NuGet package (that is, a .nupkg file).
3261+
/// </p>
3262+
/// <p>
3263+
/// NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. If the packed project has references to other projects, the other projects aren't included in the package. Currently, you must have a package per project if you have project-to-project dependencies.
3264+
/// </p>
3265+
/// <p>
3266+
/// By default, dotnet pack builds the project first. If you wish to avoid this behavior, pass the --no-build option. This option is often useful in Continuous Integration (CI) build scenarios where you know the code was previously built.
3267+
/// </p>
3268+
/// <example>
3269+
/// <code>
3270+
/// new DotNetPack()
3271+
/// .Build().EnsureSuccess();
3272+
/// </code>
3273+
/// </example>
3274+
/// <br/><a href="https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-pack">.NET CLI command</a><br/>
3275+
/// </summary>
3276+
/// <param name="Args">Specifies the set of command line arguments to use when starting the tool.</param>
3277+
/// <param name="Vars">Specifies the set of environment variables that apply to this process and its child processes.</param>
3278+
/// <param name="Props">MSBuild options for setting properties.</param>
3279+
/// <param name="Sources">The URI of the NuGet package source to use during the restore operation.</param>
3280+
/// <param name="ExecutablePath">Overrides the tool executable path.</param>
3281+
/// <param name="WorkingDirectory">Specifies the working directory for the tool to be started.</param>
3282+
/// <param name="Project">The project or solution to pack. It's either a path to a csproj, vbproj, or fsproj file, or to a solution file or directory. If not specified, the command searches the current directory for a project or solution file.</param>
3283+
/// <param name="ArtifactsPath">All build output files from the executed command will go in subfolders under the specified path, separated by project.</param>
3284+
/// <param name="Configuration">Defines the build configuration. The default for most projects is Debug, but you can override the build configuration settings in your project.</param>
3285+
/// <param name="Force">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.</param>
3286+
/// <param name="IncludeSource">Includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory. The sources files are included in the src folder within the symbols package.</param>
3287+
/// <param name="IncludeSymbols">Includes the debug symbols NuGet packages in addition to the regular NuGet packages in the output directory.</param>
3288+
/// <param name="NoBuild">Doesn't build the project before packing. It also implicitly sets the --no-restore flag.</param>
3289+
/// <param name="NoDependencies">When restoring a project with project-to-project (P2P) references, restores the root project and not the references.</param>
3290+
/// <param name="NoIncremental">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.</param>
3291+
/// <param name="NoRestore">Doesn't execute an implicit restore when running the command.</param>
3292+
/// <param name="NoLogo">Doesn't display the startup banner or the copyright message.</param>
3293+
/// <param name="NoSelfContained">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.</param>
3294+
/// <param name="Output">Directory in which to place the built binaries. If not specified, the default path is ./bin/&lt;configuration&gt;/&lt;framework&gt;/. For projects with multiple target frameworks (via the TargetFrameworks property), you also need to define --framework when you specify this option.</param>
3295+
/// <param name="OS">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&apos;t use the -r|--runtime option. Available since .NET 6.</param>
3296+
/// <param name="Runtime">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.</param>
3297+
/// <param name="SelfContained">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.</param>
3298+
/// <param name="TerminalLogger">Specifies whether the terminal logger should be used for the build output.</param>
3299+
/// <param name="Verbosity">Sets the verbosity level of the command. Allowed values are <see cref="DotNetVerbosity.Quiet"/>, <see cref="DotNetVerbosity.Minimal"/>, <see cref="DotNetVerbosity.Normal"/>, <see cref="DotNetVerbosity.Detailed"/>, and <see cref="DotNetVerbosity.Diagnostic"/>. The default is <see cref="DotNetVerbosity.Minimal"/>. For more information, see <see cref="DotNetVerbosity"/>.</param>
3300+
/// <param name="UseCurrentRuntime">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.</param>
3301+
/// <param name="VersionSuffix">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.</param>
3302+
/// <param name="Diagnostics">Enables diagnostic output.</param>
3303+
/// <param name="ShortName">Specifies a short name for this operation.</param>
3304+
[Target]
3305+
public partial record DotNetPack(
3306+
IEnumerable<string> Args,
3307+
IEnumerable<(string name, string value)> Vars,
3308+
IEnumerable<(string name, string value)> Props,
3309+
IEnumerable<string> Sources,
3310+
string Project = "",
3311+
string ArtifactsPath = "",
3312+
string Configuration = "",
3313+
bool? Force = default,
3314+
string IncludeSource = "",
3315+
string IncludeSymbols = "",
3316+
bool? NoBuild = default,
3317+
bool? NoDependencies = default,
3318+
bool? NoIncremental = default,
3319+
bool? NoRestore = default,
3320+
bool? NoLogo = default,
3321+
bool? NoSelfContained = default,
3322+
string Output = "",
3323+
string OS = "",
3324+
string Runtime = "",
3325+
bool? SelfContained = default,
3326+
DotNetTerminalLogger? TerminalLogger = default,
3327+
DotNetVerbosity? Verbosity = default,
3328+
bool? UseCurrentRuntime = default,
3329+
string VersionSuffix = "",
3330+
string ExecutablePath = "",
3331+
string WorkingDirectory = "",
3332+
bool? Diagnostics = default,
3333+
string ShortName = "")
3334+
{
3335+
/// <summary>
3336+
/// Create a new instance of the command.
3337+
/// </summary>
3338+
/// <param name="args">Specifies the set of command line arguments to use when starting the tool.</param>
3339+
public DotNetPack(params string[] args)
3340+
: this(args, [], [], [])
3341+
{
3342+
}
3343+
3344+
/// <summary>
3345+
/// Create a new instance of the command.
3346+
/// </summary>
3347+
public DotNetPack()
3348+
: this([], [], [], [])
3349+
{
3350+
}
3351+
3352+
/// <inheritdoc/>
3353+
public IStartInfo GetStartInfo(IHost host)
3354+
{
3355+
if (host == null) throw new ArgumentNullException(nameof(host));
3356+
return host.CreateCommandLine(ExecutablePath)
3357+
.WithShortName(ToString())
3358+
.WithWorkingDirectory(WorkingDirectory)
3359+
.WithVars(Vars.ToArray())
3360+
.AddArgs("pack")
3361+
.AddNotEmptyArgs(Project.ToArg())
3362+
.AddMSBuildLoggers(host, Verbosity)
3363+
.AddArgs(Sources.ToArgs("--source", ""))
3364+
.AddArgs(ArtifactsPath.ToArgs("--artifacts-path", ""))
3365+
.AddArgs(Configuration.ToArgs("--configuration", ""))
3366+
.AddArgs(IncludeSource.ToArgs("--include-source", ""))
3367+
.AddArgs(IncludeSymbols.ToArgs("--include-symbols", ""))
3368+
.AddArgs(Output.ToArgs("--output", ""))
3369+
.AddArgs(OS.ToArgs("--os", ""))
3370+
.AddArgs(Runtime.ToArgs("--runtime", ""))
3371+
.AddArgs(TerminalLogger.ToArgs("--tl", ""))
3372+
.AddArgs(Verbosity.ToArgs("--verbosity", ""))
3373+
.AddArgs(VersionSuffix.ToArgs("--version-suffix", ""))
3374+
.AddBooleanArgs(
3375+
("--force", Force),
3376+
("--no-build", NoBuild),
3377+
("--no-dependencies", NoDependencies),
3378+
("--no-incremental", NoIncremental),
3379+
("--no-restore", NoRestore),
3380+
("--nologo", NoLogo),
3381+
("--no-self-contained", NoSelfContained),
3382+
("--self-contained", SelfContained),
3383+
("--use-current-runtime", UseCurrentRuntime),
3384+
("--diagnostics", Diagnostics)
3385+
)
3386+
.AddProps("--property", Props.ToArray())
3387+
.AddArgs(Args.ToArray());
3388+
}
3389+
3390+
/// <inheritdoc/>
3391+
public override string ToString() => "".GetShortName(ShortName, "pack", Project.ToArg());
3392+
}
3393+
32543394
/// <summary>
32553395
/// Runs source code without any explicit compile or launch commands.
32563396
/// <p>
@@ -3285,7 +3425,8 @@ public IStartInfo GetStartInfo(IHost host)
32853425
/// <param name="NoBuild">Doesn't build the project before running. It also implicit sets the --no-restore flag.</param>
32863426
/// <param name="NoDependencies">When restoring a project with project-to-project (P2P) references, restores the root project and not the references.</param>
32873427
/// <param name="NoLaunchProfile">Doesn't try to use launchSettings.json to configure the application.</param>
3288-
/// <param name="NoRestore">Adds a package reference without performing a restore preview and compatibility check.</param>
3428+
/// <param name="NoRestore">Doesn't execute an implicit restore when running the command.</param>
3429+
/// <param name="NoLogo">Doesn't display the startup banner or the copyright message.</param>
32893430
/// <param name="OS">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&apos;t use the -r|--runtime option. Available since .NET 6.</param>
32903431
/// <param name="Runtime">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.</param>
32913432
/// <param name="TerminalLogger">Specifies whether the terminal logger should be used for the build output.</param>
@@ -3307,6 +3448,7 @@ public partial record DotNetRun(
33073448
bool? NoDependencies = default,
33083449
bool? NoLaunchProfile = default,
33093450
bool? NoRestore = default,
3451+
bool? NoLogo = default,
33103452
string OS = "",
33113453
string Runtime = "",
33123454
DotNetTerminalLogger? TerminalLogger = default,
@@ -3357,6 +3499,7 @@ public IStartInfo GetStartInfo(IHost host)
33573499
("--no-dependencies", NoDependencies),
33583500
("--no-launch-profile", NoLaunchProfile),
33593501
("--no-restore", NoRestore),
3502+
("--nologo", NoLogo),
33603503
("--diagnostics", Diagnostics)
33613504
)
33623505
.AddProps("--property", Props.ToArray())

0 commit comments

Comments
 (0)