Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.DotNet.Scaffolding.Core.Model;

/// <summary>
/// Represents a NuGet package with a specified name and optional version.
/// </summary>
/// <param name="Name">The name of the package. Cannot be null.</param>
/// <param name="Version">The version of the package, or null to indicate the latest version.</param>
public sealed record Package(string Name, string? Version = null);
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.CommandLine;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Core.Scaffolders;
using Microsoft.Extensions.Logging;

namespace Microsoft.DotNet.Scaffolding.Core.Steps;

public class AddPackagesStep : ScaffoldStep
{
public required IList<string> PackageNames { get; set; }
/// <summary>
/// Gets or sets the list of package names to add.
/// </summary>
public required IReadOnlyList<Package> Packages { get; set; }

/// <summary>
/// Gets or sets the path to the project file.
/// </summary>
public required string ProjectPath { get; set; }
public bool Prerelease { get; set; } = false;
private readonly ILogger _logger;
Expand All @@ -20,12 +28,14 @@ public AddPackagesStep(ILogger<AddPackagesStep> logger)

public override Task<bool> ExecuteAsync(ScaffolderContext context, CancellationToken cancellationToken = default)
{
foreach (var packageName in PackageNames)
foreach (Package package in Packages)
{
// add package version here
DotnetCommands.AddPackage(
packageName: packageName,
packageName: package.Name,
logger: _logger,
projectFile: ProjectPath,
packageVersion: package.Version,
includePrerelease: Prerelease);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Tools.Scaffold.Aspire;
using Microsoft.DotNet.Tools.Scaffold.Aspire.Helpers;
Expand All @@ -19,7 +20,8 @@ public static IScaffoldBuilder WithCachingAddPackageSteps(this IScaffoldBuilder
if (properties.TryGetValue(nameof(CommandSettings), out var commandSettingsObj) &&
commandSettingsObj is CommandSettings commandSettings)
{
step.PackageNames = [PackageConstants.CachingPackages.AppHostRedisPackageName];
// Set package details for AppHost Redis
step.Packages = [new Package(PackageConstants.CachingPackages.AppHostRedisPackageName)];
step.ProjectPath = commandSettings.AppHostProject;
step.Prerelease = commandSettings.Prerelease;
}
Expand All @@ -44,8 +46,8 @@ public static IScaffoldBuilder WithCachingAddPackageSteps(this IScaffoldBuilder
return;

}

step.PackageNames = [projectPackageName];
// Set package details for the project
step.Packages = [new Package(projectPackageName)];
step.ProjectPath = commandSettings.Project;
step.Prerelease = commandSettings.Prerelease;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.DotNet.Tools.Scaffold.Aspire;
using Microsoft.DotNet.Tools.Scaffold.Aspire.Helpers;
using Microsoft.DotNet.Tools.Scaffold.Aspire.ScaffoldSteps;
using Microsoft.DotNet.Scaffolding.Core.Model;

namespace Microsoft.DotNet.Scaffolding.Core.Hosting;

Expand All @@ -25,7 +26,8 @@ public static IScaffoldBuilder WithDatabaseAddPackageSteps(this IScaffoldBuilder
return;
}

step.PackageNames = [appHostPackageName];
// Set package details for AppHost
step.Packages = [new Package(appHostPackageName)];
step.ProjectPath = commandSettings.AppHostProject;
step.Prerelease = commandSettings.Prerelease;
}
Expand All @@ -51,7 +53,8 @@ public static IScaffoldBuilder WithDatabaseAddPackageSteps(this IScaffoldBuilder

}

step.PackageNames = [projectPackageName];
// Set package details for the API service project
step.Packages = [new Package(projectPackageName)];
step.ProjectPath = commandSettings.Project;
step.Prerelease = commandSettings.Prerelease;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Tools.Scaffold.Aspire;
using Microsoft.DotNet.Tools.Scaffold.Aspire.Helpers;
Expand All @@ -19,7 +20,8 @@ public static IScaffoldBuilder WithStorageAddPackageSteps(this IScaffoldBuilder
if (properties.TryGetValue(nameof(CommandSettings), out var commandSettingsObj) &&
commandSettingsObj is CommandSettings commandSettings)
{
step.PackageNames = [PackageConstants.StoragePackages.AppHostStoragePackageName];
// Set package details for AppHost storage
step.Packages = [new Package(PackageConstants.StoragePackages.AppHostStoragePackageName)];
step.ProjectPath = commandSettings.AppHostProject;
step.Prerelease = commandSettings.Prerelease;
}
Expand All @@ -45,7 +47,8 @@ public static IScaffoldBuilder WithStorageAddPackageSteps(this IScaffoldBuilder

}

step.PackageNames = [projectPackageName];
// Set package details for the project
step.Packages = [new Package(projectPackageName)];
step.ProjectPath = commandSettings.Project;
step.Prerelease = commandSettings.Prerelease;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Scaffolding.TextTemplating;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Common;
Expand Down Expand Up @@ -45,7 +46,7 @@ public static IScaffoldBuilder WithBlazorCrudAddPackagesStep(this IScaffoldBuild
{
var step = config.Step;
var context = config.Context;
var packageList = new List<string>()
var packageNames = new List<string>()
{
PackageConstants.AspNetCorePackages.QuickGridEfAdapterPackageName,
PackageConstants.AspNetCorePackages.AspNetCoreDiagnosticsEfCorePackageName,
Expand All @@ -60,10 +61,10 @@ public static IScaffoldBuilder WithBlazorCrudAddPackagesStep(this IScaffoldBuild
if (!string.IsNullOrEmpty(commandSettings.DatabaseProvider) &&
PackageConstants.EfConstants.EfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? projectPackageName))
{
packageList.Add(projectPackageName);
packageNames.Add(projectPackageName);
}

step.PackageNames = packageList;
step.Packages = [.. packageNames.Select(p => new Package(p))];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.DotNet.Scaffolding.CodeModification;
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Steps;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Scaffolding.TextTemplating;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Common;
Expand Down Expand Up @@ -96,7 +97,7 @@ public static IScaffoldBuilder WithBlazorIdentityAddPackagesStep(this IScaffoldB
{
var step = config.Step;
var context = config.Context;
List<string> packageList = [
List<string> packageNames = [
PackageConstants.AspNetCorePackages.AspNetCoreIdentityEfPackageName,
PackageConstants.AspNetCorePackages.AspNetCoreDiagnosticsEfCorePackageName,
PackageConstants.EfConstants.EfCoreToolsPackageName
Expand All @@ -110,10 +111,10 @@ public static IScaffoldBuilder WithBlazorIdentityAddPackagesStep(this IScaffoldB
if (!string.IsNullOrEmpty(commandSettings.DatabaseProvider) &&
PackageConstants.EfConstants.IdentityEfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? projectPackageName))
{
packageList.Add(projectPackageName);
packageNames.Add(projectPackageName);
}

step.PackageNames = packageList;
step.Packages = packageNames.Select(p => new Package(p)).ToList();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Scaffolding.TextTemplating;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Common;
Expand Down Expand Up @@ -44,7 +45,7 @@ public static IScaffoldBuilder WithEfControllerAddPackagesStep(this IScaffoldBui
{
var step = config.Step;
var context = config.Context;
List<string> packageList = [PackageConstants.EfConstants.EfCoreToolsPackageName];
List<string> packageNames = [PackageConstants.EfConstants.EfCoreToolsPackageName];
if (context.Properties.TryGetValue(nameof(EfControllerSettings), out var commandSettingsObj) &&
commandSettingsObj is EfControllerSettings commandSettings)
{
Expand All @@ -53,10 +54,10 @@ public static IScaffoldBuilder WithEfControllerAddPackagesStep(this IScaffoldBui
if (!string.IsNullOrEmpty(commandSettings.DatabaseProvider) &&
PackageConstants.EfConstants.EfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? projectPackageName))
{
packageList.Add(projectPackageName);
packageNames.Add(projectPackageName);
}

step.PackageNames = packageList;
step.Packages = [.. packageNames.Select(p => new Package(p))];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Scaffolding.TextTemplating;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Common;
Expand All @@ -19,7 +20,7 @@ public static IScaffoldBuilder WithIdentityAddPackagesStep(this IScaffoldBuilder
{
var step = config.Step;
var context = config.Context;
List<string> packageList = [
List<string> packageNames = [
PackageConstants.AspNetCorePackages.AspNetCoreIdentityEfPackageName,
PackageConstants.AspNetCorePackages.AspNetCoreIdentityUiPackageName,
PackageConstants.EfConstants.EfCoreToolsPackageName
Expand All @@ -33,10 +34,10 @@ public static IScaffoldBuilder WithIdentityAddPackagesStep(this IScaffoldBuilder
if (!string.IsNullOrEmpty(commandSettings.DatabaseProvider) &&
PackageConstants.EfConstants.IdentityEfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? dbProviderPackageName))
{
packageList.Add(dbProviderPackageName);
packageNames.Add(dbProviderPackageName);
}

step.PackageNames = packageList;
step.Packages = [.. packageNames.Select(p => new Package(p))];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Common;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Helpers;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static IScaffoldBuilder WithMinimalApiAddPackagesStep(this IScaffoldBuild
var step = config.Step;
var context = config.Context;
//this scaffolder has a non-EF scenario, only add EF packages if DataContext is provided.
List<string> packageList = [];
List<string> packageNames = [];
if (context.Properties.TryGetValue(nameof(MinimalApiSettings), out var commandSettingsObj) &&
commandSettingsObj is MinimalApiSettings commandSettings)
{
Expand All @@ -70,16 +71,16 @@ public static IScaffoldBuilder WithMinimalApiAddPackagesStep(this IScaffoldBuild
!string.IsNullOrEmpty(commandSettings.DatabaseProvider) &&
PackageConstants.EfConstants.EfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? projectPackageName))
{
packageList.Add(PackageConstants.EfConstants.EfCoreToolsPackageName);
packageList.Add(projectPackageName);
packageNames.Add(PackageConstants.EfConstants.EfCoreToolsPackageName);
packageNames.Add(projectPackageName);
}

if (commandSettings.OpenApi)
{
packageList.Add(PackageConstants.AspNetCorePackages.OpenApiPackageName);
packageNames.Add(PackageConstants.AspNetCorePackages.OpenApiPackageName);
}

step.PackageNames = packageList;
step.Packages = [.. packageNames.Select(p => new Package(p))];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.DotNet.Scaffolding.Core.Builder;
using Microsoft.DotNet.Scaffolding.Core.Model;
using Microsoft.DotNet.Scaffolding.Internal;
using Microsoft.DotNet.Scaffolding.TextTemplating;
using Microsoft.DotNet.Tools.Scaffold.AspNet.Common;
Expand Down Expand Up @@ -83,7 +84,7 @@ public static IScaffoldBuilder WithRazorPagesAddPackagesStep(this IScaffoldBuild
{
var step = config.Step;
var context = config.Context;
List<string> packageList = [PackageConstants.EfConstants.EfCoreToolsPackageName];
List<string> packageNames = [PackageConstants.EfConstants.EfCoreToolsPackageName];
if (context.Properties.TryGetValue(nameof(CrudSettings), out var commandSettingsObj) &&
commandSettingsObj is CrudSettings commandSettings)
{
Expand All @@ -92,10 +93,10 @@ public static IScaffoldBuilder WithRazorPagesAddPackagesStep(this IScaffoldBuild
if (!string.IsNullOrEmpty(commandSettings.DatabaseProvider) &&
PackageConstants.EfConstants.EfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? projectPackageName))
{
packageList.Add(projectPackageName);
packageNames.Add(projectPackageName);
}

step.PackageNames = packageList;
step.Packages = [.. packageNames.Select(p => new Package(p))];
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Microsoft.DotNet.Scaffolding.Roslyn.Services;
using Spectre.Console;
using Spectre.Console.Flow;
using InteractivePickerType = Microsoft.DotNet.Scaffolding.Core.ComponentModel.InteractivePickerType;
using Parameter = Microsoft.DotNet.Scaffolding.Core.ComponentModel.Parameter;

namespace Microsoft.DotNet.Tools.Scaffold.Flow.Steps
{
Expand Down