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

Commit

Permalink
Support update to prerelease version
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Oct 20, 2023
1 parent 6126f7b commit 3dc1ab9
Show file tree
Hide file tree
Showing 5 changed files with 37 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
```
28 changes: 16 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,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<string> Parse(string command)
Expand Down
19 changes: 12 additions & 7 deletions src/dotnetCampus.UpdateAllDotNetTools.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<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>
<!-- 设置支持的运行时版本,当前 dotnet core 设置为 2.0 是古老的版本,需要通过如下配置让只安装新版本的设备可以运行 -->
<!-- [选择要使用哪个 .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 3dc1ab9

Please sign in to comment.