diff --git a/Squirrel.sln b/Squirrel.sln index 5414e433..9fc4783c 100644 --- a/Squirrel.sln +++ b/Squirrel.sln @@ -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 diff --git a/src/Squirrel.Tool/Program.cs b/src/Squirrel.Tool/Program.cs new file mode 100644 index 00000000..02655c17 --- /dev/null +++ b/src/Squirrel.Tool/Program.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/src/Squirrel.Tool/Squirrel.Tool.csproj b/src/Squirrel.Tool/Squirrel.Tool.csproj new file mode 100644 index 00000000..a2d1b7a5 --- /dev/null +++ b/src/Squirrel.Tool/Squirrel.Tool.csproj @@ -0,0 +1,30 @@ + + + + Exe + net5.0;net6.0 + true + csq + csq + csq + true + false + true + embedded + true + $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)'))=./ + true + false + true + true + https://github.com/clowd/Clowd.Squirrel + https://github.com/clowd/Clowd.Squirrel + MIT + A .NET Core Tool that uses the Squirrel framework to create installers and update packages for dotnet applications. + + + + + + + diff --git a/src/Squirrel/Properties/AssemblyInfo.cs b/src/Squirrel/Properties/AssemblyInfo.cs index b9043736..a46d77de 100644 --- a/src/Squirrel/Properties/AssemblyInfo.cs +++ b/src/Squirrel/Properties/AssemblyInfo.cs @@ -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 {