WIP dotnet tool

This commit is contained in:
Caelan Sayler
2022-05-22 14:28:36 +01:00
parent 3301d8b7f1
commit 6fa23e2c21
4 changed files with 112 additions and 0 deletions

View File

@@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrel.CommandLine.OSX",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Update.OSX", "src\Update.OSX\Update.OSX.csproj", "{A63B2CDA-5ECC-461C-9B1F-54CF4709ACBD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Squirrel.Tool", "src\Squirrel.Tool\Squirrel.Tool.csproj", "{9E769C7E-A54C-4844-8362-727D37BB1578}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -77,6 +79,10 @@ Global
{A63B2CDA-5ECC-461C-9B1F-54CF4709ACBD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A63B2CDA-5ECC-461C-9B1F-54CF4709ACBD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A63B2CDA-5ECC-461C-9B1F-54CF4709ACBD}.Release|Any CPU.Build.0 = Release|Any CPU
{9E769C7E-A54C-4844-8362-727D37BB1578}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E769C7E-A54C-4844-8362-727D37BB1578}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E769C7E-A54C-4844-8362-727D37BB1578}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E769C7E-A54C-4844-8362-727D37BB1578}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@@ -0,0 +1,75 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
namespace Squirrel.Tool
{
class Program
{
static void Main(string[] args)
{
var packageName = "Clowd.Squirrel";
// var dependencies = Directory.EnumerateFiles(Environment.CurrentDirectory, "*.sln", SearchOption.TopDirectoryOnly)
// .SelectMany(GetProjectsFromSln)
// .Distinct()
// .SelectMany(proj => GetSquirrelVersionsFromProject(packageName, proj))
// .Distinct()
// .ToArray();
var dependencies = GetSquirrelVersionsFromProject(packageName);
if (dependencies.Length == 0)
throw new Exception("Clowd.Squirrel package was not found to be installed in the current solution.");
if (dependencies.Length > 1)
throw new Exception("Found multiple versions of Clowd.Squirrel installed in current solution. " +
"Please consolidate to a single version: " + string.Join(", ", dependencies));
var toolExecutable = SquirrelRuntimeInfo.SystemOsName switch {
"windows" => "Squirrel.exe",
"osx" => "SquirrelMac",
_ => throw new NotSupportedException("OS not supported: " + SquirrelRuntimeInfo.SystemOsName),
};
var packages = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".nuget", "packages");
var toolPath = Path.Combine(packages, packageName.ToLower(), dependencies.First(), "tools", toolExecutable);
Process.Start(toolPath, args);
}
// static string[] GetProjectsFromSln(string solutionFile)
// {
// var result = ProcessUtil.InvokeProcess("dotnet", new[] { "sln", solutionFile, "list" }, null, CancellationToken.None);
// var proj = result.StdOutput
// .Split('\r', '\n')
// .Select(s => s.TrimEnd())
// .Where(s => s.EndsWith(".csproj", StringComparison.InvariantCultureIgnoreCase))
// .Select(s => s.Trim())
// .ToArray();
//
// return proj;
// }
static string[] GetSquirrelVersionsFromProject(string packageName)
{
//dotnet list "$PSScriptRoot\src\Clowd\Clowd.csproj" package
var result = ProcessUtil.InvokeProcess("dotnet", new[] { "list", "package" }, null, CancellationToken.None);
Console.WriteLine(result.StdOutput);
var escapedName = Regex.Escape(packageName);
var matches = Regex.Matches(result.StdOutput, $@"(?m){escapedName}.*\s(\d{{1,3}}\.\d{{1,3}}\.\d.*?)$");
if (matches.Count == 0)
return new string[0];
var outp = matches.Select(m => m.Groups[1].Value.Trim()).Distinct().ToArray();
Console.WriteLine(String.Join(", ", outp));
Console.WriteLine(String.Join(", ", outp));
Console.WriteLine(String.Join(", ", outp));
return outp;
}
}
}

View File

@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net5.0;net6.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<AssemblyName>csq</AssemblyName>
<PackageId>csq</PackageId>
<ToolCommandName>csq</ToolCommandName>
<DevelopmentDependency>true</DevelopmentDependency>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<DebugType>embedded</DebugType>
<DebugSymbols>true</DebugSymbols>
<PathMap>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./</PathMap>
<DevelopmentDependency>true</DevelopmentDependency>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackAsTool>true</PackAsTool>
<PackageProjectUrl>https://github.com/clowd/Clowd.Squirrel</PackageProjectUrl>
<RepositoryUrl>https://github.com/clowd/Clowd.Squirrel</RepositoryUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>A .NET Core Tool that uses the Squirrel framework to create installers and update packages for dotnet applications.</Description>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Squirrel\Squirrel.csproj" />
</ItemGroup>
</Project>

View File

@@ -12,6 +12,7 @@ using System.Runtime.InteropServices;
[assembly: InternalsVisibleTo("UpdateMac, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Update.Windows, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("Update.OSX, PublicKey=" + SNK.SHA1)]
[assembly: InternalsVisibleTo("csq, PublicKey=" + SNK.SHA1)]
internal static class SNK
{