using System; using System.IO; using System.IO.Compression; using System.Media; using System.Net.Http; using System.Threading.Tasks; using Nuke.Common; using Nuke.Common.Execution; using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tools.DotNet; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.Tools.DotNet.DotNetTasks; [UnsetVisualStudioEnvironmentVariables] class Build : NukeBuild { public static int Main() => Execute(x => x.Publish); [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; [Solution] readonly Solution Solution; AbsolutePath OutputDirectory => RootDirectory / "output"; AbsolutePath SourceDirectory => RootDirectory / "src"; AbsolutePath LibPath => SourceDirectory / "Website/wwwroot/lib"; AbsolutePath FontAwesomePath => SourceDirectory / "Website/wwwroot/lib/fontawesome"; private void DeleteExistingFontAwesome() { if (Directory.Exists(FontAwesomePath)) Directory.Delete(FontAwesomePath, true); } Target Clean => _ => _ .Before(Restore) .Executes(() => { DeleteExistingFontAwesome(); EnsureCleanDirectory(OutputDirectory); }); private async Task DownloadFontAwesome() { const string fontAwesomeVersion = "6.4.0"; const string zipName = $"fontawesome-free-{fontAwesomeVersion}-web"; var client = new HttpClient(); var response = await client.GetAsync($"https://use.fontawesome.com/releases/v{fontAwesomeVersion}/{zipName}.zip"); var memory = new MemoryStream(); await response.Content.CopyToAsync(memory); var zip = new ZipArchive(memory); zip.ExtractToDirectory(LibPath); Directory.Move(LibPath / zipName, FontAwesomePath); } Target Restore => _ => _ .DependsOn(Clean) .Executes(() => { DownloadFontAwesome().Wait(); DotNetRestore(s => s .SetProjectFile(Solution)); }); Target Compile => _ => _ .DependsOn(Restore) .Executes(() => { DotNetBuild(s => s .SetProjectFile(Solution) .SetConfiguration(Configuration) .EnableNoRestore()); }); Target Test => _ => _ .DependsOn(Compile) .Executes(() => { DotNetTest(s => s .SetProjectFile(Solution) .EnableNoRestore()); }); Target Publish => _ => _ .DependsOn(Test) .Executes(() =>{ DotNetPublish(s => s .SetProject(SourceDirectory / "Website/Website.csproj") .SetConfiguration(Configuration) .SetOutput(OutputDirectory)); }); }