A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
Revert "Removed Build project"
Etienne Baudoux79c33ce3f6bf
diff --git a/src/Build.sln b/src/Build.slnnew file mode 100644index 000000000..6d8aebc3a--- /dev/null+++ b/src/Build.sln@@ -0,0 +1,25 @@++Microsoft Visual Studio Solution File, Format Version 12.00+# Visual Studio Version 17+VisualStudioVersion = 17.9.34607.119+MinimumVisualStudioVersion = 10.0.40219.1+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "build\_build.csproj", "{31D5C875-27D6-460B-AD34-7CCD984A69DD}"+EndProject+Global+ GlobalSection(SolutionConfigurationPlatforms) = preSolution+ Debug|Any CPU = Debug|Any CPU+ Release|Any CPU = Release|Any CPU+ EndGlobalSection+ GlobalSection(ProjectConfigurationPlatforms) = postSolution+ {31D5C875-27D6-460B-AD34-7CCD984A69DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU+ {31D5C875-27D6-460B-AD34-7CCD984A69DD}.Debug|Any CPU.Build.0 = Debug|Any CPU+ {31D5C875-27D6-460B-AD34-7CCD984A69DD}.Release|Any CPU.ActiveCfg = Release|Any CPU+ {31D5C875-27D6-460B-AD34-7CCD984A69DD}.Release|Any CPU.Build.0 = Release|Any CPU+ EndGlobalSection+ GlobalSection(SolutionProperties) = preSolution+ HideSolutionNode = FALSE+ EndGlobalSection+ GlobalSection(ExtensibilityGlobals) = postSolution+ SolutionGuid = {5D3E4460-FF5C-4D38-BBE5-8A51D08F2C29}+ EndGlobalSection+EndGlobaldiff --git a/src/DevToys-Windows.lutconfig b/src/DevToys-Windows.lutconfignew file mode 100644index 000000000..ff7fdf3f6--- /dev/null+++ b/src/DevToys-Windows.lutconfig@@ -0,0 +1,6 @@+<LUTConfig Version="1.0">+ <Repository>..\</Repository>+ <ParallelBuilds>true</ParallelBuilds>+ <ParallelTestRuns>true</ParallelTestRuns>+ <TestCaseTimeout>180000</TestCaseTimeout>+</LUTConfig>\ No newline at end of filediff --git a/src/build/.editorconfig b/src/build/.editorconfignew file mode 100644index 000000000..31e43dcd8--- /dev/null+++ b/src/build/.editorconfig@@ -0,0 +1,11 @@+[*.cs]+dotnet_style_qualification_for_field = false:warning+dotnet_style_qualification_for_property = false:warning+dotnet_style_qualification_for_method = false:warning+dotnet_style_qualification_for_event = false:warning+dotnet_style_require_accessibility_modifiers = never:warning++csharp_style_expression_bodied_methods = true:silent+csharp_style_expression_bodied_properties = true:warning+csharp_style_expression_bodied_indexers = true:warning+csharp_style_expression_bodied_accessors = true:warningdiff --git a/src/build/AppVersion/AppVersionTask.cs b/src/build/AppVersion/AppVersionTask.csnew file mode 100644index 000000000..20491c944--- /dev/null+++ b/src/build/AppVersion/AppVersionTask.cs@@ -0,0 +1,76 @@+using System.Collections.Generic;+using System.IO;+using Nuke.Common.IO;+using Serilog;++internal static class AppVersionTask+{+ internal static void SetAppVersion(AbsolutePath rootDirectory)+ {+ string[] appVersionNumberAppContent = GetAppVersionNumberFileContent(rootDirectory);+ string appVersion = GetAppVersion(appVersionNumberAppContent);+ string sdkVersion = GetSdkVersion(appVersionNumberAppContent);++ var csharpUpdater = new CSharpUpdater(appVersion, sdkVersion);+ IReadOnlyCollection<AbsolutePath> assemblyVersionFiles+ = rootDirectory.GlobFiles("**/*AssemblyVersion.cs");+ foreach (AbsolutePath file in assemblyVersionFiles)+ {+ Log.Information("Updating app version in {File}...", file);+ csharpUpdater.UpdateFile(file);+ }++ var projectUpdater = new ProjectUpdater(sdkVersion);+ IReadOnlyCollection<AbsolutePath> projectFiles+ = rootDirectory.GlobFiles("**/*DevToys.Api.csproj");+ foreach (AbsolutePath file in projectFiles)+ {+ Log.Information("Updating project version in {File}...", file);+ projectUpdater.UpdateFile(file);+ }++ var appxManifestUpdater = new AppxManifestUpdater(appVersion);+ IReadOnlyCollection<AbsolutePath> appxmanifestFiles+ = rootDirectory.GlobFiles("**/*.appxmanifest");+ foreach (AbsolutePath file in appxmanifestFiles)+ {+ Log.Information("Updating app version in {File}...", file);+ appxManifestUpdater.UpdateFile(file);+ }+ }++ private static string[] GetAppVersionNumberFileContent(AbsolutePath rootDirectory)+ {+ AbsolutePath appVersionNumberFile = rootDirectory / "tools" / "app-version-number.txt";+ if (!appVersionNumberFile.FileExists())+ {+ Log.Error("Unable to find the app version number in {AppVersionNumberFile}...", appVersionNumberFile);+ throw new FileNotFoundException("Unable to find the app version number file.", appVersionNumberFile.ToString());+ }++ return File.ReadAllLines(appVersionNumberFile);+ }++ private static string GetAppVersion(string[] appVersionNumberAppContent)+ {+ return GetVersion(appVersionNumberAppContent, "app");+ }++ private static string GetSdkVersion(string[] appVersionNumberAppContent)+ {+ return GetVersion(appVersionNumberAppContent, "sdk");+ }++ private static string GetVersion(string[] appVersionNumberAppContent, string name)+ {+ for (int i = 0; i < appVersionNumberAppContent.Length; i++)+ {+ if (appVersionNumberAppContent[i].StartsWith(name + ":"))+ {+ return appVersionNumberAppContent[i].Substring(name.Length + 1);+ }+ }++ return string.Empty;+ }+}diff --git a/src/build/AppVersion/AppxManifestUpdater.cs b/src/build/AppVersion/AppxManifestUpdater.csnew file mode 100644index 000000000..96a09d5b9--- /dev/null+++ b/src/build/AppVersion/AppxManifestUpdater.cs@@ -0,0 +1,69 @@+using System;+using System.IO;++internal sealed class AppxManifestUpdater+{+ private readonly string _versionRule;++ internal AppxManifestUpdater(string versionRule)+ {+ _versionRule = versionRule;+ }++ public void UpdateFile(string fileName)+ {+ string text = File.ReadAllText(fileName);++ string ouputText = UpdateTextWithRule(text);++ File.WriteAllText(fileName, ouputText);+ }++ public string UpdateTextWithRule(string text)+ {+ Tuple<string, int, int>? g = GetVersionString(text);+ if (g != null)+ {+ if (VersionString.TryParse(g.Item1, out VersionString? v) && v is not null)+ {+ string newVersion = new VersionUpdateRule(_versionRule).Update(v);+ return string.Concat(text.AsSpan(0, g.Item2), newVersion, text.AsSpan(g.Item2 + g.Item3));+ }+ }++ return text;+ }++ public static Tuple<string, int, int>? GetVersionString(string input)+ {+ string identityTagStart = "<Identity";+ string identityTagEnd = ">";+ string versionAttributeStart = "Version=\"";+ string versionAttributeEnd = "\"";++ int identityTagStartPosition = input.IndexOf(identityTagStart);+ if (identityTagStartPosition > -1)+ {+ int identityTagEndPosition = input.IndexOf(identityTagEnd, identityTagStartPosition + identityTagStart.Length);+ if (identityTagEndPosition > -1)+ {+ int versionAttributeStartPosition = input.IndexOf(versionAttributeStart, identityTagStartPosition + identityTagStart.Length);+ if (versionAttributeStartPosition > identityTagStartPosition && versionAttributeStartPosition < identityTagEndPosition)+ {+ int versionAttributeEndPosition = input.IndexOf(versionAttributeEnd, versionAttributeStartPosition + versionAttributeStart.Length);++ if (versionAttributeEndPosition > versionAttributeStartPosition && versionAttributeEndPosition < identityTagEndPosition)+ {+ string oldVersion = input.Substring(versionAttributeStartPosition + versionAttributeStart.Length, versionAttributeEndPosition - (versionAttributeStartPosition + versionAttributeStart.Length));+ return new Tuple<string, int, int>(+ oldVersion,+ versionAttributeStartPosition + versionAttributeStart.Length,+ oldVersion.Length);+ }+ }+ }+ }++ return null;+ }+}diff --git a/src/build/AppVersion/CSharpUpdater.cs b/src/build/AppVersion/CSharpUpdater.csnew file mode 100644index 000000000..4df67d055--- /dev/null+++ b/src/build/AppVersion/CSharpUpdater.cs@@ -0,0 +1,81 @@+using System.Collections.Generic;+using System.Text.RegularExpressions;+using System.IO;+using System;++internal sealed class CSharpUpdater+{+ private readonly List<CSharpVersionUpdateRule> _updateRules;++ internal CSharpUpdater(string appVersion, string sdkVersion)+ {+ _updateRules = new List<CSharpVersionUpdateRule>();+ if (!string.IsNullOrEmpty(appVersion))+ {+ _updateRules.Add(new CSharpVersionUpdateRule("AssemblyVersion", appVersion));+ _updateRules.Add(new CSharpVersionUpdateRule("AssemblyFileVersion", appVersion));+ _updateRules.Add(new CSharpVersionUpdateRule("AssemblyInformationalVersion", sdkVersion));+ }+ }++ public void UpdateFile(string fileName)+ {+ string[] lines = File.ReadAllLines(fileName);++ var outlines = new List<string>();+ foreach (string line in lines)+ {+ outlines.Add(UpdateLine(line));+ }++ File.WriteAllLines(fileName, outlines.ToArray());+ }++ private string UpdateLine(string line)+ {+ foreach (CSharpVersionUpdateRule rule in _updateRules)+ {+ if (UpdateLineWithRule(ref line, rule))+ {+ break;+ }+ }+ return line;+ }++ private static bool UpdateLineWithRule(ref string line, CSharpVersionUpdateRule rule)+ {+ bool updated = false;+ Group? g = GetVersionString(line, rule.AttributeName);+ if (g != null)+ {+ if (VersionString.TryParse(g.Value, out VersionString? v) && v is not null)+ {+ string newVersion = rule.Update(v);+ line = string.Concat(line.AsSpan(0, g.Index), newVersion, line.AsSpan(g.Index + g.Length));+ updated = true;+ }+ }++ return updated;+ }++ private static Group? GetVersionString(string input, string attributeName)+ {+ int commentIndex = input.IndexOf("//");+ if (commentIndex != -1)+ {+ input = input.Substring(0, commentIndex);+ }+ string attributeMatch = string.Format("(?:(?:{0})|(?:{0}Attribute))", attributeName);++ string pattern = @"^\s*\[assembly: " + attributeMatch + @"\(""(?<Version>[0-9(\-\w)?\.\*]+)""\)\]";+ var regex = new Regex(pattern);+ Match m = regex.Match(input);+ if (m.Success)+ {+ return m.Groups["Version"];+ }+ return null;+ }+}diff --git a/src/build/AppVersion/CSharpVersionUpdateRule.cs b/src/build/AppVersion/CSharpVersionUpdateRule.csnew file mode 100644index 000000000..59025e698--- /dev/null+++ b/src/build/AppVersion/CSharpVersionUpdateRule.cs@@ -0,0 +1,11 @@+internal class CSharpVersionUpdateRule+{+ private readonly VersionUpdateRule _updateRule;+ public CSharpVersionUpdateRule(string attributeName, string updateRule)+ {+ AttributeName = attributeName;+ _updateRule = new VersionUpdateRule(updateRule);+ }+ public string AttributeName { get; private set; }+ public string Update(VersionString v) { return _updateRule.Update(v); }+}diff --git a/src/build/AppVersion/ProjectUpdater.cs b/src/build/AppVersion/ProjectUpdater.csnew file mode 100644index 000000000..febdb77ed--- /dev/null+++ b/src/build/AppVersion/ProjectUpdater.cs@@ -0,0 +1,74 @@+using System.Collections.Generic;+using System.Text.RegularExpressions;+using System.IO;+using System;++internal sealed class ProjectUpdater+{+ private readonly List<ProjectVersionUpdateRule> _updateRules;++ internal ProjectUpdater(string sdkVersion)+ {+ _updateRules = new List<ProjectVersionUpdateRule>();+ if (!string.IsNullOrEmpty(sdkVersion))+ {+ _updateRules.Add(new ProjectVersionUpdateRule("Version", sdkVersion));+ }+ }++ public void UpdateFile(string fileName)+ {+ string[] lines = File.ReadAllLines(fileName);++ var outlines = new List<string>();+ foreach (string line in lines)+ {+ outlines.Add(UpdateLine(line));+ }++ File.WriteAllLines(fileName, outlines.ToArray());+ }++ private string UpdateLine(string line)+ {+ foreach (ProjectVersionUpdateRule rule in _updateRules)+ {+ if (UpdateLineWithRule(ref line, rule))+ {+ break;+ }+ }+ return line;+ }++ private static bool UpdateLineWithRule(ref string line, ProjectVersionUpdateRule rule)+ {+ bool updated = false;+ Group? g = GetVersionString(line, rule.ParameterName);+ if (g != null)+ {+ if (VersionString.TryParse(g.Value, out VersionString? v) && v is not null)+ {+ string newVersion = rule.Update(v);+ line = string.Concat(line.AsSpan(0, g.Index), newVersion, line.AsSpan(g.Index + g.Length));+ updated = true;+ }+ }++ return updated;+ }++ private static Group? GetVersionString(string input, string parameterName)+ {+ string parameterMatch = string.Format("(?:(?:{0})|(?:{0}Attribute))", parameterName);++ string pattern = @"^\s*\<" + parameterMatch + @">(?<Version>[0-9(\-\w)?\.\*]+)</" + parameterMatch + ">";+ var regex = new Regex(pattern);+ Match m = regex.Match(input);+ if (m.Success)+ {+ return m.Groups["Version"];+ }+ return null;+ }+}diff --git a/src/build/AppVersion/ProjectVersionUpdateRule.cs b/src/build/AppVersion/ProjectVersionUpdateRule.csnew file mode 100644index 000000000..28f7689d9--- /dev/null+++ b/src/build/AppVersion/ProjectVersionUpdateRule.cs@@ -0,0 +1,11 @@+internal class ProjectVersionUpdateRule+{+ private readonly VersionUpdateRule _updateRule;+ public ProjectVersionUpdateRule(string parameterName, string updateRule)+ {+ ParameterName = parameterName;+ _updateRule = new VersionUpdateRule(updateRule);+ }+ public string ParameterName { get; private set; }+ public string Update(VersionString v) { return _updateRule.Update(v); }+}diff --git a/src/build/AppVersion/VersionString.cs b/src/build/AppVersion/VersionString.csnew file mode 100644index 000000000..a9e3b50f1--- /dev/null+++ b/src/build/AppVersion/VersionString.cs@@ -0,0 +1,64 @@+using System;+using System.Diagnostics.CodeAnalysis;+using System.Text.RegularExpressions;++internal sealed class VersionString+{+ internal VersionString()+ {+ Major = "0";+ Minor = "0";+ Build = "0";+ Revision = "0";+ }++ public VersionString(string version)+ {+ if (!Parse(version))+ {+ throw new ArgumentException("Invalid version string");+ }+ }++ private bool Parse(string input)+ {+ string pattern = @"^(?<Major>\d+)\.(?<Minor>\d+)\.(?:(?:(?<Build>\d+|\d+\-\w*)\.(?<Revision>\*|\d+|\d+\-\w*))|(?<Build>\*|\d+|\d+\-\w*))$";+ var regex = new Regex(pattern);+ Match match = regex.Match(input);+ if (match.Success)+ {+ Major = match.Groups["Major"].Value;+ Minor = match.Groups["Minor"].Value;+ Build = match.Groups["Build"].Value;+ Revision = match.Groups["Revision"].Value;+ }+ return match.Success;+ }++ public static bool TryParse(string input, [MaybeNullWhen(false)] out VersionString? version)+ {+ var temp = new VersionString();+ version = null;+ if (temp.Parse(input))+ {+ version = temp;+ }+ return version != null;+ }++ public string Major { get; set; } = string.Empty;++ public string Minor { get; set; } = string.Empty;++ public string Build { get; set; } = string.Empty;++ public string Revision { get; set; } = string.Empty;++ public override string ToString()+ {+ return string.Format("{0}.{1}{2}{3}",+ Major, Minor,+ string.IsNullOrEmpty(Build) ? "" : "." + Build,+ string.IsNullOrEmpty(Revision) ? "" : "." + Revision);+ }+}diff --git a/src/build/AppVersion/VersionUpdateRule.cs b/src/build/AppVersion/VersionUpdateRule.csnew file mode 100644index 000000000..abe73b564--- /dev/null+++ b/src/build/AppVersion/VersionUpdateRule.cs@@ -0,0 +1,69 @@+using System;+using System.Collections.Generic;++internal sealed class VersionUpdateRule+{+ private readonly string[] _partRules;+ public VersionUpdateRule(string rule)+ {+ _partRules = rule.Split('.');+ if (_partRules.Length < 2 || _partRules.Length > 4)+ {+ throw new ArgumentException("Expecting 2-4 version parts");+ }+ foreach (string partRule in _partRules)+ {+ if (partRule == "+"+ || partRule == "*"+ || partRule == "="+ || partRule.Contains("-pre"))+ {+ // OK, valid rule+ }+ else+ {+ // will throw an exception if not an int+ int.Parse(partRule);+ }+ }+ }++ public string Update(string version)+ {+ return Update(new VersionString(version));+ }++ public string Update(VersionString version)+ {+ var inParts = new List<string>() { version.Major, version.Minor, version.Build, version.Revision };+ var outParts = new List<string>();+ for (int index = 0; index < _partRules.Length; index++)+ {+ string rule = _partRules[index];+ string inPart = inParts[index];+ if (rule == "=")+ {+ if (inPart.Length > 0)+ {+ outParts.Add(inParts[index]);+ }+ }+ else if (rule == "+" || rule == "*")+ {+ if (inPart.Length == 0)+ {+ throw new ArgumentException("Can't increment missing value");+ }+ _ = int.TryParse(inPart, out int inNumber); // * gets turned into a zero+ inNumber++;+ outParts.Add(inNumber.ToString());+ }+ else+ {+ // must be a numeric literal+ outParts.Add(_partRules[index]);+ }+ }+ return string.Join(".", outParts.ToArray());+ }+}diff --git a/src/build/Build.cs b/src/build/Build.csnew file mode 100644index 000000000..c8f1e3555--- /dev/null+++ b/src/build/Build.cs@@ -0,0 +1,378 @@+using System;+using System.Collections.Generic;+using System.Diagnostics;+using System.Linq;+using Nuke.Common;+using Nuke.Common.IO;+using Nuke.Common.ProjectModel;+using Nuke.Common.Tooling;+using Nuke.Common.Tools.DotNet;+using Nuke.Common.Tools.GitVersion;+using Nuke.Common.Tools.MSBuild;+using Nuke.Common.Utilities.Collections;+using Serilog;+using static AppVersionTask;+using static Nuke.Common.Tools.DotNet.DotNetTasks;+using static RestoreTask;+using Project = Nuke.Common.ProjectModel.Project;++class Build : NukeBuild+{+ /// Support plugins are available for:+ /// - JetBrains ReSharper https://nuke.build/resharper+ /// - JetBrains Rider https://nuke.build/rider+ /// - Microsoft VisualStudio https://nuke.build/visualstudio+ /// - Microsoft VSCode https://nuke.build/vscode++ public static int Main() => Execute<Build>(x => x.RunTests);++ [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]+ readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;++ [Solution(SuppressBuildProjectCheck = true)]+ readonly Solution? WindowsSolution;++ [Solution(SuppressBuildProjectCheck = true)]+ readonly Solution? MacSolution;++ [Solution(SuppressBuildProjectCheck = true)]+ readonly Solution? LinuxSolution;++ Target Clean => _ => _+ .Executes(() =>+ {+ RootDirectory+ .GlobDirectories("bin", "obj", "packages", "publish")+ .ForEach(path => path.CreateOrCleanDirectory());+ Log.Information("Cleaned bin, obj, packages and publish folders.");+ });++ Target Restore => _ => _+ .DependsOn(Clean)+ .Executes(async () =>+ {+ if (!Debugger.IsAttached)+ {+ await RestoreDependenciesAsync(RootDirectory);+ }+ });++ Target SetVersion => _ => _+ .After(Restore)+ .OnlyWhenDynamic(() => Configuration == Configuration.Release)+ .Executes(() =>+ {+ SetAppVersion(RootDirectory);+ });++ Target CompileGenerators => _ => _+ .DependsOn(Restore)+ .Executes(() =>+ {+ Log.Information($"Building generators ...");+ RootDirectory+ .GlobFiles("**/generators/**/*.csproj")+ .ForEach(f =>+ DotNetBuild(s => s+ .SetProjectFile(f)+ .SetConfiguration(Configuration)+ .SetSelfContained(true)+ .SetPublishTrimmed(false)+ .SetVerbosity(DotNetVerbosity.quiet)));+ });++ Target Compile => _ => _+ .DependsOn(CompileGenerators)+ .Executes(() =>+ {+ Log.Information($"Building solution ...");++ Solution solution;+ if (OperatingSystem.IsMacOS())+ {+ solution = MacSolution!;+ }+ else if (OperatingSystem.IsWindows())+ {+ solution = WindowsSolution!;+ }+ else if (OperatingSystem.IsLinux())+ {+ solution = LinuxSolution!;+ }+ else+ {+ throw new InvalidOperationException("You must run Windows, macOS or Linux.");+ }++ DotNetBuild(s => s+ .SetProjectFile(solution)+ .SetConfiguration(Configuration)+ .SetVerbosity(DotNetVerbosity.quiet));+ });++ Target RunTests => _ => _+ .DependsOn(Compile)+ .Executes(() =>+ {+ RootDirectory+ .GlobFiles("**/*Tests.csproj")+ .ForEach(f =>+ DotNetTest(s => s+ .SetProjectFile(f)+ .SetConfiguration(Configuration)+ .SetVerbosity(DotNetVerbosity.minimal)));+ });++ Target GenerateSdkNuGet => _ => _+ .Description("Generate the DevToys SDK NuGet package")+ .DependsOn(SetVersion)+ .DependsOn(Restore)+ .DependsOn(CompileGenerators)+ .Executes(() =>+ {+ Log.Information($"Building NuGet packages ...");+ Project project = WindowsSolution!.GetAllProjects("DevToys.Api").Single();+ DotNetPack(s => s+ .SetProject(project)+ .SetConfiguration(Configuration)+ .SetPublishTrimmed(false)+ .SetVerbosity(DotNetVerbosity.quiet)+ .SetProcessArgumentConfigurator(_ => _+ .Add($"/bl:\"{RootDirectory / "publish" / "Sdk"}.binlog\""))+ .SetOutputDirectory(RootDirectory / "publish" / "Sdk"));+ });++ Target PublishApp => _ => _+ .DependsOn(GenerateSdkNuGet)+ .Executes(() =>+ {+ if (OperatingSystem.IsWindows())+ {+ PublishWindowsApp();+ }++ if (OperatingSystem.IsMacOS())+ {+ PublishMacApp();+ }++ if (OperatingSystem.IsLinux())+ {+ PublishLinuxApp();+ }++ PublishCliApp();+ });++ void PublishWindowsApp()+ {+ // DevToys WPF+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForWindowsApp())+ {+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier + (dotnetParameters.Portable ? "-Portable" : string.Empty)} ...");+ DotNetPublish(s => s+ .SetProject(dotnetParameters.ProjectOrSolutionPath)+ .SetConfiguration(Configuration)+ .SetFramework(dotnetParameters.TargetFramework)+ .SetRuntime(dotnetParameters.RuntimeIdentifier)+ .SetPlatform(dotnetParameters.Platform)+ .SetSelfContained(dotnetParameters.Portable)+ .SetPublishSingleFile(false)+ .SetPublishReadyToRun(false)+ .SetPublishTrimmed(false)+ .SetVerbosity(DotNetVerbosity.quiet)+ .SetProcessArgumentConfigurator(_ => _+ .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)+ .Add("/p:Unpackaged=" + dotnetParameters.Portable)+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))+ .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));+ }+ }++ void PublishMacApp()+ {+ // DevToys MAUI Blazor Mac Catalyst+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForMacOSApp())+ {+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");+ DotNetBuild(s => s+ .SetProjectFile(dotnetParameters.ProjectOrSolutionPath)+ .SetConfiguration(Configuration)+ .SetFramework(dotnetParameters.TargetFramework)+ .SetRuntime(dotnetParameters.RuntimeIdentifier)+ .SetPlatform(dotnetParameters.Platform)+ .SetSelfContained(dotnetParameters.Portable)+ .SetPublishSingleFile(false)+ .SetPublishReadyToRun(false)+ .SetPublishTrimmed(true) // HACK: Required for MacOS. However, <LinkMode>None</LinkMode> in the CSPROJ disables trimming.+ .SetVerbosity(DotNetVerbosity.quiet)+ .SetProcessArgumentConfigurator(_ => _+ .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)+ .Add("/p:CreatePackage=True") /* Will create an installable .pkg */+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))+ .SetOutputDirectory(RootDirectory / "publish" / dotnetParameters.OutputPath));+ }+ }++ void PublishLinuxApp()+ {+ // DevToys Linux+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForLinuxApp())+ {+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier + (dotnetParameters.Portable ? "-Portable" : string.Empty)} ...");+ DotNetPublish(s => s+ .SetProject(dotnetParameters.ProjectOrSolutionPath)+ .SetConfiguration(Configuration)+ .SetFramework(dotnetParameters.TargetFramework)+ .SetRuntime(dotnetParameters.RuntimeIdentifier)+ .SetPlatform(dotnetParameters.Platform)+ .SetSelfContained(dotnetParameters.Portable)+ .SetPublishSingleFile(false)+ .SetPublishReadyToRun(false)+ .SetPublishTrimmed(false)+ .SetVerbosity(DotNetVerbosity.quiet)+ .SetProcessArgumentConfigurator(_ => _+ .Add("/p:RuntimeIdentifierOverride=" + dotnetParameters.RuntimeIdentifier)+ .Add("/p:Unpackaged=" + dotnetParameters.Portable)+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))+ .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));+ }+ }++ void PublishCliApp()+ {+ // DevToys CLI+ foreach (DotnetParameters dotnetParameters in GetDotnetParametersForCliApp())+ {+ Log.Information($"Publishing {dotnetParameters.ProjectOrSolutionPath + " - " + dotnetParameters.TargetFramework + " - " + dotnetParameters.RuntimeIdentifier} ...");+ DotNetPublish(s => s+ .SetProject(dotnetParameters.ProjectOrSolutionPath)+ .SetConfiguration(Configuration)+ .SetFramework(dotnetParameters.TargetFramework)+ .SetRuntime(dotnetParameters.RuntimeIdentifier)+ .SetSelfContained(dotnetParameters.Portable)+ .SetPublishSingleFile(dotnetParameters.Portable)+ .SetPublishReadyToRun(false)+ .SetPublishTrimmed(false)+ .SetVerbosity(DotNetVerbosity.quiet)+ .SetProcessArgumentConfigurator(_ => _+ .Add($"/bl:\"{RootDirectory / "publish" / dotnetParameters.OutputPath}.binlog\""))+ .SetOutput(RootDirectory / "publish" / dotnetParameters.OutputPath));+ }+ }++ IEnumerable<DotnetParameters> GetDotnetParametersForCliApp()+ {+ string publishProject = "DevToys.CLI";+ Project project;++ if (OperatingSystem.IsMacOS())+ {+ project = MacSolution!.GetProject(publishProject);+ foreach (string targetFramework in project.GetTargetFrameworks())+ {+ yield return new DotnetParameters(project.Path, "osx-x64", targetFramework, portable: false);+ yield return new DotnetParameters(project.Path, "osx-x64", targetFramework, portable: true);++ yield return new DotnetParameters(project.Path, "osx-arm64", targetFramework, portable: false);+ yield return new DotnetParameters(project.Path, "osx-arm64", targetFramework, portable: true);+ }+ }+ else if (OperatingSystem.IsWindows())+ {+ project = WindowsSolution!.GetAllProjects(publishProject).Single();+ foreach (string targetFramework in project.GetTargetFrameworks())+ {+ yield return new DotnetParameters(project.Path, "win-x64", targetFramework, portable: false);+ yield return new DotnetParameters(project.Path, "win-x64", targetFramework, portable: true);++ yield return new DotnetParameters(project.Path, "win-arm64", targetFramework, portable: false);+ yield return new DotnetParameters(project.Path, "win-arm64", targetFramework, portable: true);++ yield return new DotnetParameters(project.Path, "win-x86", targetFramework, portable: false);+ yield return new DotnetParameters(project.Path, "win-x86", targetFramework, portable: true);+ }+ }+ else if (OperatingSystem.IsLinux())+ {+ project = LinuxSolution!.GetAllProjects(publishProject).Single();+ foreach (string targetFramework in project.GetTargetFrameworks())+ {+ yield return new DotnetParameters(project.Path, "linux-arm", targetFramework, portable: false, platform: "arm");+ yield return new DotnetParameters(project.Path, "linux-x64", targetFramework, portable: false, platform: "x64");++ yield return new DotnetParameters(project.Path, "linux-arm", targetFramework, portable: true, platform: "arm");+ yield return new DotnetParameters(project.Path, "linux-x64", targetFramework, portable: true, platform: "x64");+ }+ }+ }++ IEnumerable<DotnetParameters> GetDotnetParametersForWindowsApp()+ {+ string publishProject = "DevToys.Windows";+ Project project;++ if (OperatingSystem.IsWindows())+ {+ project = WindowsSolution!.GetAllProjects(publishProject).Single();+ foreach (string targetFramework in project.GetTargetFrameworks())+ {+ yield return new DotnetParameters(project.Path, "win-arm64", targetFramework, portable: false, platform: "arm64");+ yield return new DotnetParameters(project.Path, "win-x64", targetFramework, portable: false, platform: "x64");+ yield return new DotnetParameters(project.Path, "win-x86", targetFramework, portable: false, platform: "x86");++ yield return new DotnetParameters(project.Path, "win-arm64", targetFramework, portable: true, platform: "arm64");+ yield return new DotnetParameters(project.Path, "win-x64", targetFramework, portable: true, platform: "x64");+ yield return new DotnetParameters(project.Path, "win-x86", targetFramework, portable: true, platform: "x86");+ }+ }+ else+ {+ throw new NotSupportedException();+ }+ }++ IEnumerable<DotnetParameters> GetDotnetParametersForLinuxApp()+ {+ string publishProject = "DevToys.Linux";+ Project project;++ if (OperatingSystem.IsLinux())+ {+ project = LinuxSolution!.GetAllProjects(publishProject).Single();+ foreach (string targetFramework in project.GetTargetFrameworks())+ {+ yield return new DotnetParameters(project.Path, "linux-arm", targetFramework, portable: false, platform: "arm");+ yield return new DotnetParameters(project.Path, "linux-x64", targetFramework, portable: false, platform: "x64");++ yield return new DotnetParameters(project.Path, "linux-arm", targetFramework, portable: true, platform: "arm");+ yield return new DotnetParameters(project.Path, "linux-x64", targetFramework, portable: true, platform: "x64");+ }+ }+ else+ {+ throw new NotSupportedException();+ }+ }++ IEnumerable<DotnetParameters> GetDotnetParametersForMacOSApp()+ {+ string publishProject = "DevToys.MacOS";+ Project project;++ if (OperatingSystem.IsMacOS())+ {+ project = MacSolution!.GetAllProjects(publishProject).Single();+ foreach (string targetFramework in project.GetTargetFrameworks())+ {+ yield return new DotnetParameters(project.Path, "osx-arm64", targetFramework, portable: true);+ yield return new DotnetParameters(project.Path, "osx-x64", targetFramework, portable: true);+ }+ }+ else+ {+ throw new NotSupportedException();+ }+ }+}diff --git a/src/build/Configuration.cs b/src/build/Configuration.csnew file mode 100644index 000000000..75501889d--- /dev/null+++ b/src/build/Configuration.cs@@ -0,0 +1,14 @@+using System.ComponentModel;+using Nuke.Common.Tooling;++[TypeConverter(typeof(TypeConverter<Configuration>))]+internal sealed class Configuration : Enumeration+{+ public static readonly Configuration Debug = new() { Value = nameof(Debug) };+ public static readonly Configuration Release = new() { Value = nameof(Release) };++ public static implicit operator string(Configuration configuration)+ {+ return configuration.Value;+ }+}diff --git a/src/build/Directory.Build.props b/src/build/Directory.Build.propsnew file mode 100644index 000000000..c81c28b2e--- /dev/null+++ b/src/build/Directory.Build.props@@ -0,0 +1,15 @@+<?xml version="1.0" encoding="utf-8"?>+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">++ <!-- This file prevents unintended imports of unrelated MSBuild files -->+ <!-- Uncomment to include parent Directory.Build.props file -->+ <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />++ <PropertyGroup>+ <BaseOutputPath>bin\$(Configuration)\$(Platform)\</BaseOutputPath>+ <OutputPath>$(BaseOutputPath)$(MSBuildProjectName)\</OutputPath>+ <BaseIntermediateOutputPath>obj\$(Platform)\$(MSBuildProjectName)\</BaseIntermediateOutputPath>+ <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>+ <GeneratedFilesDir>$(BaseIntermediateOutputPath)Generated Files\</GeneratedFilesDir>+ </PropertyGroup>+</Project>diff --git a/src/build/Directory.Build.targets b/src/build/Directory.Build.targetsnew file mode 100644index 000000000..340280a69--- /dev/null+++ b/src/build/Directory.Build.targets@@ -0,0 +1,8 @@+<?xml version="1.0" encoding="utf-8"?>+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">++ <!-- This file prevents unintended imports of unrelated MSBuild files -->+ <!-- Uncomment to include parent Directory.Build.targets file -->+ <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />++</Project>diff --git a/src/build/DotnetParameters.cs b/src/build/DotnetParameters.csnew file mode 100644index 000000000..e0a453385--- /dev/null+++ b/src/build/DotnetParameters.cs@@ -0,0 +1,26 @@+using Nuke.Common.IO;++internal sealed record DotnetParameters+{+ internal readonly AbsolutePath ProjectOrSolutionPath;++ internal readonly string RuntimeIdentifier;++ internal readonly string TargetFramework;++ internal readonly bool Portable;++ internal readonly string? Platform;++ internal readonly string OutputPath;++ public DotnetParameters(AbsolutePath projectOrSolutionPath, string runtimeIdentifier, string targetFramework, bool portable, string? platform = null)+ {+ ProjectOrSolutionPath = projectOrSolutionPath;+ RuntimeIdentifier = runtimeIdentifier;+ TargetFramework = targetFramework;+ Portable = portable;+ Platform = platform;+ OutputPath = $"{ProjectOrSolutionPath.Name}-{TargetFramework}-{RuntimeIdentifier}{(portable ? "-portable" : string.Empty)}";+ }+}diff --git a/src/build/Properties/launchSettings.json b/src/build/Properties/launchSettings.jsonnew file mode 100644index 000000000..e19b2505d--- /dev/null+++ b/src/build/Properties/launchSettings.json@@ -0,0 +1,7 @@+{+ "profiles": {+ "_build": {+ "commandName": "Project"+ }+ }+}\ No newline at end of filediff --git a/src/build/Restore/RestoreTask.cs b/src/build/Restore/RestoreTask.csnew file mode 100644index 000000000..f4a104838--- /dev/null+++ b/src/build/Restore/RestoreTask.cs@@ -0,0 +1,94 @@+using System;+using System.Diagnostics;+using System.Threading.Tasks;+using Nuke.Common.IO;+using Nuke.Common.Tooling;+using Nuke.Common.Tools.PowerShell;+using Serilog;+using Output = Nuke.Common.Tooling.Output;++internal static class RestoreTask+{+ internal static Task RestoreDependenciesAsync(AbsolutePath rootDirectory)+ {+ if (OperatingSystem.IsWindows())+ {+ return RestoreWindowsAsync(rootDirectory);+ }+ else+ {+ return RestoreUnixAsync(rootDirectory);+ }+ }++ private static Task RestoreWindowsAsync(AbsolutePath rootDirectory)+ {+ System.Collections.Generic.IReadOnlyCollection<Output> results+ = PowerShellTasks+ .PowerShell(_ => _+ .SetFile(rootDirectory / "init.ps1")+ .SetProcessLogOutput(true)+ .SetProcessWorkingDirectory(rootDirectory)+ .SetNoLogo(true)+ .SetNoProfile(true));+ return Task.CompletedTask;+ }++ private static Task RestoreUnixAsync(AbsolutePath rootDirectory)+ {+ return Bash(rootDirectory / "init.sh");+ }++ private static async Task<int> Bash(string cmd)+ {+ string bashProgram;+ if (OperatingSystem.IsMacOS())+ {+ bashProgram = "sh";+ }+ else+ {+ bashProgram = "bash";+ }++ var source = new TaskCompletionSource<int>();+ string escapedArgs = cmd.Replace("\"", "\\\"");+ var process = new Process+ {+ StartInfo = new ProcessStartInfo+ {+ FileName = "/bin/bash",+ Arguments = $"-c \"{bashProgram} {escapedArgs}\"",+ UseShellExecute = false,+ CreateNoWindow = true+ },+ EnableRaisingEvents = true+ };+ process.Exited += (sender, args) =>+ {+ if (process.ExitCode == 0)+ {+ source.SetResult(0);+ }+ else+ {+ source.SetException(new Exception($"Command `{cmd}` failed with exit code `{process.ExitCode}`"));+ }++ process.Dispose();+ };++ try+ {+ process.Start();+ await process.WaitForExitAsync();+ }+ catch (Exception e)+ {+ Log.Error(e, "Command {} failed", cmd);+ source.SetException(e);+ }++ return await source.Task;+ }+}diff --git a/src/build/_build.csproj b/src/build/_build.csprojnew file mode 100644index 000000000..960f81079--- /dev/null+++ b/src/build/_build.csproj@@ -0,0 +1,20 @@+<Project Sdk="Microsoft.NET.Sdk">++ <PropertyGroup>+ <Nullable>enable</Nullable>+ <OutputType>Exe</OutputType>+ <TargetFramework>$(NetCore)</TargetFramework>+ <RootNamespace></RootNamespace>+ <NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>+ <NukeRootDirectory>..\..</NukeRootDirectory>+ <NukeScriptDirectory>..\..</NukeScriptDirectory>+ <NukeTelemetryVersion>1</NukeTelemetryVersion>+ <IsPackable>false</IsPackable>+ <EnableCentralBuildOutput>false</EnableCentralBuildOutput>+ </PropertyGroup>++ <ItemGroup>+ <PackageReference Include="Nuke.Common" />+ </ItemGroup>++</Project>diff --git a/src/build/_build.csproj.DotSettings b/src/build/_build.csproj.DotSettingsnew file mode 100644index 000000000..7bc28484c--- /dev/null+++ b/src/build/_build.csproj.DotSettings@@ -0,0 +1,27 @@+<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">+ <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=HeapView_002EDelegateAllocation/@EntryIndexedValue">DO_NOT_SHOW</s:String>+ <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=VariableHidesOuterVariable/@EntryIndexedValue">DO_NOT_SHOW</s:String>+ <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ClassNeverInstantiated_002EGlobal/@EntryIndexedValue">DO_NOT_SHOW</s:String>+ <s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MemberCanBeMadeStatic_002ELocal/@EntryIndexedValue">DO_NOT_SHOW</s:String>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_INTERNAL_MODIFIER/@EntryValue">Implicit</s:String>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/DEFAULT_PRIVATE_MODIFIER/@EntryValue">Implicit</s:String>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/METHOD_OR_OPERATOR_BODY/@EntryValue">ExpressionBody</s:String>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_MEMBERS/@EntryValue">0</s:String>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ANONYMOUS_METHOD_DECLARATION_BRACES/@EntryValue">NEXT_LINE</s:String>+ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_USER_LINEBREAKS/@EntryValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_INVOCATION_LPAR/@EntryValue">False</s:Boolean>+ <s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MAX_ATTRIBUTE_LENGTH_FOR_SAME_LINE/@EntryValue">120</s:Int64>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE_EX/@EntryValue">IF_OWNER_IS_SINGLE_LINE</s:String>+ <s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_ARGUMENTS_STYLE/@EntryValue">WRAP_IF_LONG</s:String>+ <s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ANONYMOUSMETHOD_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>+ <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>+ <s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpAttributeForSingleLineMethodUpgrade/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpKeepExistingMigration/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpPlaceEmbeddedOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpRenamePlacementToArrangementMigration/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ECSharpUseContinuousIndentInsideBracesMigration/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002ECSharpPlaceAttributeOnSameLineMigration/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>+ <s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>diff --git a/tools/app-version-number.txt b/tools/app-version-number.txtnew file mode 100644index 000000000..de523f478--- /dev/null+++ b/tools/app-version-number.txt@@ -0,0 +1,3 @@+// A version like "2.0.0.+" will increment automatically.+app:2.0.0.++sdk:2.0.0-pre.+\ No newline at end of file