Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #15 from dotnet-campus/t/lindexi/dotnet
Browse files Browse the repository at this point in the history
Support update to prerelease version
  • Loading branch information
lindexi authored Oct 24, 2023
2 parents 6126f7b + 5a78dfd commit a5fc3fe
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<LangVersion>latest</LangVersion>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>The dotnet tool that can update all dotnet tools </Description>
<Copyright>Copyright (c) 2020 dotnet-campus</Copyright>
<Copyright>Copyright (c) 2020-2023 dotnet-campus</Copyright>
<PackageProjectUrl>https://github.com/dotnet-campus/dotnetCampus.UpdateAllDotNetTools</PackageProjectUrl>
<RepositoryUrl>https://github.com/dotnet-campus/dotnetCampus.UpdateAllDotNetTools</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ dotnet tool install --global dotnetCampus.UpdateAllDotNetTools

```
dotnet updatealltools
```
```

Or update all tools to prerelease version by:

```
dotnet UpdateAllTools --prerelease
```
27 changes: 15 additions & 12 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -37,23 +40,23 @@ 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<string> Parse(string command)
Expand Down
18 changes: 11 additions & 7 deletions src/dotnetCampus.UpdateAllDotNetTools.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net6.0</TargetFrameworks>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<PackAsTool>true</PackAsTool>
<ToolCommandName>dotnet-updatealltools</ToolCommandName>
</PropertyGroup>
<!-- [选择要使用哪个 .NET 版本](https://docs.microsoft.com/zh-cn/dotnet/core/versions/selection) -->
<!-- 如果缺少所请求的主要版本,则前滚到下一个可用的更高主要版本和最低的次要版本 -->
<RollForward>Major</RollForward>

<PackAsTool>true</PackAsTool>
<ToolCommandName>dotnet-updatealltools</ToolCommandName>
</PropertyGroup>

</Project>

0 comments on commit a5fc3fe

Please sign in to comment.