From 3dc1ab9e2802fa69afa1656492312318498aadac Mon Sep 17 00:00:00 2001 From: lindexi Date: Fri, 20 Oct 2023 08:56:29 +0800 Subject: [PATCH] Support update to prerelease version https://github.com/dotnet-campus/dotnetCampus.UpdateAllDotNetTools/issues/14 --- Directory.Build.props | 2 +- LICENSE | 2 +- README.md | 8 +++++- src/Program.cs | 28 +++++++++++--------- src/dotnetCampus.UpdateAllDotNetTools.csproj | 19 ++++++++----- 5 files changed, 37 insertions(+), 22 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 3983b4c..7991f11 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -7,7 +7,7 @@ latest false The dotnet tool that can update all dotnet tools - Copyright (c) 2020 dotnet-campus + Copyright (c) 2020-2023 dotnet-campus https://github.com/dotnet-campus/dotnetCampus.UpdateAllDotNetTools https://github.com/dotnet-campus/dotnetCampus.UpdateAllDotNetTools MIT diff --git a/LICENSE b/LICENSE index 6129d93..93cd42e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 dotnet campus +Copyright (c) 2020-2023 dotnet campus Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2a9cb8a..8f1e880 100644 --- a/README.md +++ b/README.md @@ -16,4 +16,10 @@ dotnet tool install --global dotnetCampus.UpdateAllDotNetTools ``` dotnet updatealltools -``` \ No newline at end of file +``` + +Or update all tools to prerelease version by: + +``` +dotnet UpdateAllTools --prerelease +``` diff --git a/src/Program.cs b/src/Program.cs index 31ad684..11ab861 100644 --- a/src/Program.cs +++ b/src/Program.cs @@ -14,7 +14,10 @@ static void Main(string[] args) { Console.WriteLine("Starting update all dotnet tools"); Console.WriteLine("Finding installed tools"); - var self = @"dotnetCampus.UpdateAllDotNetTools"; + const string self = @"dotnetCampus.UpdateAllDotNetTools"; + + bool shouldUpdateToPrerelease = args.Length > 0 && args[0] == "--prerelease"; + foreach (var temp in Parse(Command("dotnet", "tool list -g"))) { if (temp.Equals(self, StringComparison.OrdinalIgnoreCase)) @@ -37,23 +40,24 @@ static void Main(string[] args) } Console.WriteLine("Update finished"); - } - private static void TryUpdate(string toolName) - { - try - { - UpdateTool(toolName); - } - catch (Exception e) + void TryUpdate(string toolName) { - Console.WriteLine(e); + try + { + UpdateTool(toolName, shouldUpdateToPrerelease); + } + catch (Exception e) + { + Console.WriteLine(e); + } } } + - private static void UpdateTool(string tool) + private static void UpdateTool(string tool, bool shouldUpdateToPrerelease) { - Console.WriteLine(Command("dotnet", $"tool update {tool} -g")); + Console.WriteLine(Command("dotnet", $"tool update {tool} -g{(shouldUpdateToPrerelease ? " --prerelease" : "")}")); } private static IEnumerable Parse(string command) diff --git a/src/dotnetCampus.UpdateAllDotNetTools.csproj b/src/dotnetCampus.UpdateAllDotNetTools.csproj index 0cfac61..9361b5a 100644 --- a/src/dotnetCampus.UpdateAllDotNetTools.csproj +++ b/src/dotnetCampus.UpdateAllDotNetTools.csproj @@ -1,13 +1,18 @@ - - Exe - netcoreapp3.1;net6.0 + + Exe + netcoreapp3.1;net6.0 - true + true - true - dotnet-updatealltools - + + + + Major + + true + dotnet-updatealltools +