more cli commands
This commit is contained in:
@@ -3,7 +3,7 @@ using Spectre.Console.Cli;
|
|||||||
|
|
||||||
namespace DotNetSolutionTools.CLI.Commands;
|
namespace DotNetSolutionTools.CLI.Commands;
|
||||||
|
|
||||||
public class UpdateProjectToNet80Command : Command<UpdateProjectToNet80Command.Settings>
|
public class UpdateProjectToNet80Command : AsyncCommand<UpdateProjectToNet80Command.Settings>
|
||||||
{
|
{
|
||||||
public sealed class Settings : CommandSettings
|
public sealed class Settings : CommandSettings
|
||||||
{
|
{
|
||||||
@@ -11,16 +11,15 @@ public class UpdateProjectToNet80Command : Command<UpdateProjectToNet80Command.S
|
|||||||
public required string CsprojFilePath { get; set; }
|
public required string CsprojFilePath { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Execute(CommandContext context, Settings settings)
|
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
|
||||||
{
|
{
|
||||||
// validate a real folder path was passed in
|
|
||||||
if (!Directory.Exists(settings.CsprojFilePath))
|
if (!Directory.Exists(settings.CsprojFilePath))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Invalid folder path");
|
Console.WriteLine("Invalid file path. Please pass in a valid file path to a .csproj file.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
Console.WriteLine("Deleting bin, obj, and node_modules folders");
|
Console.WriteLine("Upgrading project to .NET 8.0");
|
||||||
CleanFolder.DeleteBinObjAndNodeModulesFoldersInFolder(settings.CsprojFilePath);
|
await DotNetUpgrade.UpdateProjectAtPathToNet80(settings.CsprojFilePath);
|
||||||
|
|
||||||
Console.WriteLine("==================================================");
|
Console.WriteLine("==================================================");
|
||||||
Console.WriteLine("Done!");
|
Console.WriteLine("Done!");
|
||||||
|
|||||||
28
DotNetSolutionTools.CLI/Commands/UpdateSlnToNet80Command.cs
Normal file
28
DotNetSolutionTools.CLI/Commands/UpdateSlnToNet80Command.cs
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
using DotNetSolutionTools.Core;
|
||||||
|
using Spectre.Console.Cli;
|
||||||
|
|
||||||
|
namespace DotNetSolutionTools.CLI.Commands;
|
||||||
|
|
||||||
|
public class UpdateSlnToNet80Command : AsyncCommand<UpdateSlnToNet80Command.Settings>
|
||||||
|
{
|
||||||
|
public sealed class Settings : CommandSettings
|
||||||
|
{
|
||||||
|
[CommandArgument(1, "<SolutionFilePath>")]
|
||||||
|
public required string SolutionFilePath { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<int> ExecuteAsync(CommandContext context, Settings settings)
|
||||||
|
{
|
||||||
|
if (!File.Exists(settings.SolutionFilePath))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Invalid file path. Please pass in a valid file path to a .csproj file.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
Console.WriteLine("Upgrading project to .NET 8.0");
|
||||||
|
await DotNetUpgrade.UpdateProjectsInSolutionToNet80(settings.SolutionFilePath);
|
||||||
|
|
||||||
|
Console.WriteLine("==================================================");
|
||||||
|
Console.WriteLine("Done!");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,6 +13,8 @@ app.Configure(config =>
|
|||||||
config.AddCommand<FormatCsprojCommand>("format-csproj");
|
config.AddCommand<FormatCsprojCommand>("format-csproj");
|
||||||
config.AddCommand<TreatWarningsAsErrorsCommand>("warnings-as-errors");
|
config.AddCommand<TreatWarningsAsErrorsCommand>("warnings-as-errors");
|
||||||
config.AddCommand<ClearBinObjCommand>("clear-bin-obj");
|
config.AddCommand<ClearBinObjCommand>("clear-bin-obj");
|
||||||
|
config.AddCommand<UpdateProjectToNet80Command>("update-csproj-net80");
|
||||||
|
config.AddCommand<UpdateSlnToNet80Command>("update-sln-net80");
|
||||||
});
|
});
|
||||||
|
|
||||||
var instance = MSBuildLocator.QueryVisualStudioInstances().OrderByDescending(instance => instance.Version).First();
|
var instance = MSBuildLocator.QueryVisualStudioInstances().OrderByDescending(instance => instance.Version).First();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Various tools to manage a C# solution.
|
Various tools to manage a C# solution.
|
||||||
|
|
||||||
✨ Update a solution to .NET 8 - updates csproj target versions and all Microsoft Nuget Packages
|
✨ Update a solution to .NET 8 - updates csproj target versions and all Microsoft Nuget Packages. Ensure you update the global.json to use the latest SDK version, as this is not done for you.
|
||||||
|
|
||||||
## App
|
## App
|
||||||
The app feels quite self explanatory :)
|
The app feels quite self explanatory :)
|
||||||
@@ -31,6 +31,6 @@ _options_
|
|||||||
|
|
||||||
**clear-bin-obj** `<SolutionFolderPath>` Deletes all bin and obj folders, and node_modules folders in the solution folder.
|
**clear-bin-obj** `<SolutionFolderPath>` Deletes all bin and obj folders, and node_modules folders in the solution folder.
|
||||||
|
|
||||||
**update-sln-net80** `<SolutionFilePath>` **NOT IMPLEMENTED IN CLI YET** Updates all projects and Microsoft NuGet packages in sln to .NET 8.0.
|
**update-sln-net80** `<SolutionFilePath>` Updates all projects and Microsoft NuGet packages in sln to .NET 8.0.
|
||||||
|
|
||||||
**update-csproj-net80** `<SolutionFilePath>` **NOT IMPLEMENTED IN CLI YET** Updates project and Microsoft NuGet packages to .NET 8.0.
|
**update-csproj-net80** `<CsprojFilePath>` Updates project and Microsoft NuGet packages to .NET 8.0.
|
||||||
|
|||||||
Reference in New Issue
Block a user