|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using Nuke.Common; |
| 4 | +using Nuke.Common.Execution; |
| 5 | +using Nuke.Common.Git; |
| 6 | +using Nuke.Common.IO; |
| 7 | +using Nuke.Common.ProjectModel; |
| 8 | +using Nuke.Common.Tooling; |
| 9 | +using Nuke.Common.Tools.DotNet; |
| 10 | +using Nuke.Common.Tools.GitVersion; |
| 11 | +using Nuke.Common.Tools.NuGet; |
| 12 | +using Nuke.Common.Utilities.Collections; |
| 13 | +using static Nuke.Common.EnvironmentInfo; |
| 14 | +using static Nuke.Common.IO.FileSystemTasks; |
| 15 | +using static Nuke.Common.IO.PathConstruction; |
| 16 | +using static Nuke.Common.Tools.DotNet.DotNetTasks; |
| 17 | + |
| 18 | +[CheckBuildProjectConfigurations] |
| 19 | +[UnsetVisualStudioEnvironmentVariables] |
| 20 | +class Build : NukeBuild |
| 21 | +{ |
| 22 | + /// Support plugins are available for: |
| 23 | + /// - JetBrains ReSharper https://nuke.build/resharper |
| 24 | + /// - JetBrains Rider https://nuke.build/rider |
| 25 | + /// - Microsoft VisualStudio https://nuke.build/visualstudio |
| 26 | + /// - Microsoft VSCode https://nuke.build/vscode |
| 27 | + |
| 28 | + public static int Main () => Execute<Build>(x => x.Compile); |
| 29 | + |
| 30 | + protected override void OnBuildInitialized() |
| 31 | + { |
| 32 | + base.OnBuildInitialized(); |
| 33 | + |
| 34 | + ProcessTasks.DefaultLogInvocation = true; |
| 35 | + ProcessTasks.DefaultLogOutput = true; |
| 36 | + } |
| 37 | + |
| 38 | + [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] |
| 39 | + readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; |
| 40 | + |
| 41 | + [Solution] readonly Solution Solution; |
| 42 | + [GitRepository] readonly GitRepository GitRepository; |
| 43 | + [GitVersion] readonly GitVersion GitVersion; |
| 44 | + |
| 45 | + AbsolutePath BuildBinDirectory => RootDirectory / "bin"; |
| 46 | + |
| 47 | + AbsolutePath CurrentBuildOutputDirectory => BuildBinDirectory / Configuration; |
| 48 | + |
| 49 | + AbsolutePath IntermediateOutputDirectory => RootDirectory / ""; |
| 50 | + |
| 51 | + AbsolutePath OutputDirectory => RootDirectory / "output"; |
| 52 | + |
| 53 | + AbsolutePath ChocolateyDirectory => RootDirectory / "chocolatey"; |
| 54 | + |
| 55 | + AbsolutePath PaketDirectory => RootDirectory / ".paket"; |
| 56 | + |
| 57 | + AbsolutePath PackagesDirectory => RootDirectory / "packages"; |
| 58 | + |
| 59 | + AbsolutePath WixDirectory => PackagesDirectory / "wix/tools"; |
| 60 | + |
| 61 | + Target Versions => _ => _ |
| 62 | + .Before() |
| 63 | + .Executes(() => |
| 64 | + { |
| 65 | + Console.WriteLine("Informational Version: {0}", GitVersion.InformationalVersion); |
| 66 | + Console.WriteLine("SemVer Version: {0}", GitVersion.SemVer); |
| 67 | + Console.WriteLine("AssemblySemVer Version: {0}", GitVersion.AssemblySemVer); |
| 68 | + Console.WriteLine("MajorMinorPatch Version: {0}", GitVersion.MajorMinorPatch); |
| 69 | + Console.WriteLine("NuGet Version: {0}", GitVersion.NuGetVersion); |
| 70 | + }); |
| 71 | + |
| 72 | + Target Clean => _ => _ |
| 73 | + .DependsOn(CleanOutput) |
| 74 | + .Executes(() => |
| 75 | + { |
| 76 | + EnsureCleanDirectory(OutputDirectory); |
| 77 | + }); |
| 78 | + |
| 79 | + Target CleanOutput => _ => _ |
| 80 | + .Executes(() => |
| 81 | + { |
| 82 | + EnsureCleanDirectory(OutputDirectory); |
| 83 | + }); |
| 84 | + |
| 85 | + Target Restore => _ => _ |
| 86 | + .Executes(() => |
| 87 | + { |
| 88 | + ProcessTasks.StartProcess(PaketDirectory / "paket.exe", "restore"); |
| 89 | + |
| 90 | + DotNetRestore(s => s |
| 91 | + .SetProjectFile(Solution)); |
| 92 | + }); |
| 93 | + |
| 94 | + Target Compile => _ => _ |
| 95 | + .DependsOn(Restore) |
| 96 | + .Executes(() => |
| 97 | + { |
| 98 | + DotNetBuild(s => s |
| 99 | + .SetProjectFile(Solution) |
| 100 | + .SetConfiguration(Configuration) |
| 101 | + .SetAssemblyVersion(GitVersion.GetNormalizedAssemblyVersion()) |
| 102 | + .SetFileVersion(GitVersion.GetNormalizedFileVersion()) |
| 103 | + .SetInformationalVersion(GitVersion.InformationalVersion) |
| 104 | + .EnableNoRestore()); |
| 105 | + }); |
| 106 | + |
| 107 | + Target Pack => _ => _ |
| 108 | + .DependsOn(CleanOutput) |
| 109 | + .Executes(() => |
| 110 | + { |
| 111 | + // & $nuget pack "$(Join-Path $PSScriptRoot 'chocolatey\snoop.nuspec')" -Version $version -Properties Configuration=$Configuration -OutputDirectory "$outputDirectory" -NoPackageAnalysis |
| 112 | + NuGetTasks.NuGetPack(s => s |
| 113 | + .SetTargetPath(ChocolateyDirectory / "snoop.nuspec") |
| 114 | + .SetVersion(GitVersion.NuGetVersion) |
| 115 | + .SetConfiguration(Configuration) |
| 116 | + .SetOutputDirectory(OutputDirectory) |
| 117 | + .SetNoPackageAnalysis(true)); |
| 118 | + |
| 119 | + var tempDirectory = TemporaryDirectory / "XX"; |
| 120 | + |
| 121 | + var nupkgs = OutputDirectory.GlobFiles("*.nupkg"); |
| 122 | + |
| 123 | + CompressionTasks.UncompressZip(nupkgs.First(), tempDirectory); |
| 124 | + |
| 125 | + CompressionTasks.Compress(tempDirectory / "tools", OutputDirectory / $"snoop.{GitVersion.NuGetVersion}.zip", info => info.Name.Contains("chocolatey") == false && info.Name != "VERIFICATION.txt"); |
| 126 | + }); |
| 127 | + |
| 128 | + Target Setup => _ => _ |
| 129 | + .Executes(() => |
| 130 | + { |
| 131 | + ProcessTasks.StartProcess(WixDirectory / "candle.exe", |
| 132 | + $"snoop.wxs -ext WixUIExtension -o \"{OutputDirectory / "Snoop.wixobj"}\" -dProductVersion=\"{GitVersion.MajorMinorPatch}\" -nologo") |
| 133 | + .WaitForExit(); |
| 134 | + |
| 135 | + ProcessTasks.StartProcess(WixDirectory / "light.exe", |
| 136 | + $"-out \"{OutputDirectory / $"Snoop.{GitVersion.NuGetVersion}.msi"}\" -b \"{CurrentBuildOutputDirectory}\" \"{OutputDirectory / "Snoop.wixobj"}\" -ext WixUIExtension -dProductVersion=\"{GitVersion.MajorMinorPatch}\" -pdbout \"{OutputDirectory / "Snoop.wixpdb"}\" -nologo -sice:ICE61") |
| 137 | + .WaitForExit(); |
| 138 | + }); |
| 139 | + |
| 140 | + Target CI => _ => _ |
| 141 | + .DependsOn(Clean, Compile, Pack, Setup); |
| 142 | +} |
0 commit comments