using System; using System.IO; using System.Linq; using System.Text.Json; using System.Threading.Tasks; using static Bullseye.Targets; using static Centron.Scripts.RunHelper; using static Centron.Scripts.FileHelper; using static Centron.Scripts.CentronPaths; using static Centron.Scripts.CentronConnectionsHelper; namespace Centron.Scripts { public class Program { static async Task Main(string[] args) { Target("clean", () => { var centronConnectionsBytes = File.Exists(CentronNet.DebugCentronConnectionsPath) ? File.ReadAllBytes(CentronNet.DebugCentronConnectionsPath) : null; var simpleWebServiceConfigBytes = File.Exists(WebServiceLinux.DebugSimpleWebServiceConfigPath) ? File.ReadAllBytes(WebServiceLinux.DebugSimpleWebServiceConfigPath) : null; DeleteDirectory(ArtifactsDirectory); Console.WriteLine("Cleaned artifacts directory"); DeleteDirectory(DotNetToolsDirectory); Console.WriteLine("Cleaned dotnet tools directory"); DeleteDirectory(WebServiceInstaller.InstallerInputDirectory); Console.WriteLine("Cleaned c-entron Web-Service installer input directory"); DeleteDirectory(CentronNetInstaller.InstallerInputDirectory); Console.WriteLine("Cleaned c-entron.NET installer input directory"); foreach (var directory in BinAndObjDirectories) { DeleteDirectory(directory); } Console.WriteLine("Cleaned all bin and obj directories"); if (centronConnectionsBytes != null) { Directory.CreateDirectory(Path.GetDirectoryName(CentronNet.DebugCentronConnectionsPath)); File.WriteAllBytes(CentronNet.DebugCentronConnectionsPath, centronConnectionsBytes); Console.WriteLine("Preserved CentronConnections.xml"); } if (simpleWebServiceConfigBytes != null) { Directory.CreateDirectory(Path.GetDirectoryName(WebServiceLinux.DebugSimpleWebServiceConfigPath)); File.WriteAllBytes(WebServiceLinux.DebugSimpleWebServiceConfigPath, simpleWebServiceConfigBytes); Console.WriteLine("Preserved SimpleWebServiceConfig.txt"); } }); Target("setup-versioning", ["clean"], () => { RunDotNet($"tool install nbgv --version 3.0.19-beta --tool-path \"{DotNetToolsDirectory}\""); var version = ReadDotNetTool("nbgv", "get-version -v Version", WebServiceInstaller.DeploymentDirectory).Trim(); var commitId = ReadDotNetTool("nbgv", "get-version -v GitCommitIdShort", WebServiceInstaller.DeploymentDirectory).Trim(); var isDevBuild = EnvironmentHelper.IsDevBuild(); UpdateVersionInfo(DirectoryBuildProps, version, commitId, isDevBuild); if (isDevBuild) Console.WriteLine($"Dev version is {version}"); else Console.WriteLine($"Current version is {version}"); }); Target("create-nuget-packages", ["setup-versioning"], () => { RunDotNet($"pack \"{CentronCore.CsProj}\" -c Release -nodeReuse:false"); MoveFiles(CentronCore.PublishDirectory, NugetArtifactsDirectory, "*.nupkg", SearchOption.TopDirectoryOnly); RunDotNet($"pack \"{CentronInterfaces.CsProj}\" -c Release -nodeReuse:false"); MoveFiles(CentronInterfaces.PublishDirectory, NugetArtifactsDirectory, "*.nupkg", SearchOption.TopDirectoryOnly); RunDotNet($"pack \"{CentronWebServicesCore.CsProj}\" -c Release -nodeReuse:false"); MoveFiles(CentronWebServicesCore.PublishDirectory, NugetArtifactsDirectory, "*.nupkg", SearchOption.TopDirectoryOnly); RunDotNet($"pack \"{CentronControls.CsProj}\" -c Release -nodeReuse:false"); MoveFiles(CentronControls.PublishDirectory, NugetArtifactsDirectory, "*.nupkg", SearchOption.TopDirectoryOnly); Console.WriteLine("Created the nuget package artifacts"); }); Target("build-web-service", ["setup-versioning", "create-nuget-packages"], () => { RunDotNet($"publish \"{WebService.ConnectionManager.CsProj}\" -r win-x64 --self-contained true -c Release -f net10.0-windows -nodeReuse:false"); Console.WriteLine("Finished building the connection-manager"); RunDotNet($"publish \"{WebService.CsProj}\" -r win-x64 --self-contained true -c Release -f net10.0-windows -nodeReuse:false"); Console.WriteLine("Finished building the web-service"); // Move connection-manager into its own subdirectory to avoid DLL conflicts. // Both apps are self-contained and carry their own runtime independently. MoveDirectory(WebService.ConnectionManager.PublishDirectory, WebService.PublishedConnectionManagerDirectory); Console.WriteLine("Moved connection-manager into ConnectionManager subdirectory"); DeleteSubDirectoriesOtherThan(WebService.PublishDirectory, "de", "en", "ConnectionManager"); Console.WriteLine("Deleted unneeded files"); FixNLogConfig(WebService.PublishDirectory); Console.WriteLine("Fixed the nlog.config"); CopyFiles(NugetArtifactsDirectory, WebService.PublishedDevelopmentDirectory, $"{CentronCore.ProjectName}*.nupkg"); CopyFiles(NugetArtifactsDirectory, WebService.PublishedDevelopmentDirectory, $"{CentronInterfaces.ProjectName}*.nupkg"); CopyFiles(NugetArtifactsDirectory, WebService.PublishedDevelopmentDirectory, $"{CentronWebServicesCore.ProjectName}*.nupkg"); Console.WriteLine("Copied the nuget-packages into the development directory"); var dependencies = DependencyGraph.ReadDependencyGraphs(WebService.CsProj, WebService.ConnectionManager.CsProj); DependencyGraph.Write(dependencies, CentronPaths.DependencyGraph.CentronWebServiceArtifactsFile); }); Target("build-web-service-installer", ["build-web-service"], () => { if (WXSHelper.UpdateWebServiceSetupProductHeat()) throw new Exception($"The installer product heat {WebServiceInstaller.ProductHeat} is not up to date. Execute the target update-installer-product-heat and commit the changes."); MoveDirectory(WebService.PublishDirectory, WebServiceInstaller.InstallerInputDirectory); Console.WriteLine("Copied the web-service files into the web-service installer input directory"); RunMsBuild($"\"{WebServiceInstaller.WixProj}\" /t:Build /p:Configuration=Release /m -nodeReuse:false"); Console.WriteLine("Created the web-service installer"); DeleteFiles(WebServiceInstaller.PublishDirectory, "*.wixpdb"); Console.WriteLine("Deleted unneeded files"); ZipDirectory(WebServiceInstaller.PublishDirectory, WebServiceInstaller.ArtifactsFile); Console.WriteLine("Created the web-service installer artifact"); }); Target("build-centron-net", ["setup-versioning"], () => { RunDotNet($"publish \"{CentronNet.CsProj}\" -r win-x64 --self-contained true -c Release -f net10.0-windows -nodeReuse:false"); Console.WriteLine("Finished building the c-entron.NET"); DeleteSubDirectoriesOtherThan(CentronNet.PublishDirectory, "de", "en", "Tools"); Console.WriteLine("Deleted unneeded files"); FixNLogConfig(CentronNet.PublishDirectory); Console.WriteLine("Fixed the nlog.config"); CreateCentronConnections(CentronNet.PublishDirectory); Console.WriteLine("Created the CentronConnections.xml"); var dependencies = DependencyGraph.ReadDependencyGraph(CentronNet.CsProj); DependencyGraph.Write(dependencies, CentronPaths.DependencyGraph.CentronNetArtifactsFile); }); Target("build-centron-net-installer", ["build-centron-net"], () => { if (WXSHelper.UpdateCentronSetupProductHeat()) throw new Exception($"The installer product heat {CentronNetInstaller.ProductHeat} is not up to date. Execute the target update-installer-product-heat and commit the changes."); MoveDirectory(CentronNet.PublishDirectory, CentronNetInstaller.InstallerInputDirectory); Console.WriteLine("Copied the c-entron.NET files into the c-entron.NET installer input directory"); RunMsBuild($"\"{CentronNetInstaller.WixProj}\" /t:Build /p:Configuration=Release /m -nodeReuse:false"); Console.WriteLine("Created the c-entron.NET installer"); DeleteFiles(CentronNetInstaller.PublishDirectory, "*.wixpdb"); Console.WriteLine("Deleted unneeded files"); ZipDirectory(CentronNetInstaller.PublishDirectory, CentronNetInstaller.ArtifactsFile); Console.WriteLine("Created the c-entron.NET installer artifact"); }); Target("build-web-service-only", () => { RunDotNet($"publish \"{WebService.ConnectionManager.CsProj}\" -r win-x64 --self-contained true -c Release -f net10.0-windows -nodeReuse:false"); Console.WriteLine("Finished building the connection-manager"); RunDotNet($"publish \"{WebService.CsProj}\" -r win-x64 --self-contained true -c Release -f net10.0-windows -nodeReuse:false"); Console.WriteLine("Finished building the web-service"); // Move connection-manager into its own subdirectory to avoid DLL conflicts. // Both apps are self-contained and carry their own runtime independently. MoveDirectory(WebService.ConnectionManager.PublishDirectory, WebService.PublishedConnectionManagerDirectory); Console.WriteLine("Moved connection-manager into ConnectionManager subdirectory"); DeleteSubDirectoriesOtherThan(WebService.PublishDirectory, "de", "en", "ConnectionManager"); Console.WriteLine("Deleted unneeded files"); FixNLogConfig(WebService.PublishDirectory); Console.WriteLine("Fixed the nlog.config"); CopyFiles(NugetArtifactsDirectory, WebService.PublishedDevelopmentDirectory, $"{CentronCore.ProjectName}*.nupkg"); CopyFiles(NugetArtifactsDirectory, WebService.PublishedDevelopmentDirectory, $"{CentronInterfaces.ProjectName}*.nupkg"); CopyFiles(NugetArtifactsDirectory, WebService.PublishedDevelopmentDirectory, $"{CentronWebServicesCore.ProjectName}*.nupkg"); Console.WriteLine("Copied the nuget-packages into the development directory"); }); Target("build-web-service-installer-only", () => { if (WXSHelper.UpdateWebServiceSetupProductHeat()) throw new Exception($"The installer product heat {WebServiceInstaller.ProductHeat} is not up to date. Execute the target update-installer-product-heat and commit the changes."); MoveDirectory(WebService.PublishDirectory, WebServiceInstaller.InstallerInputDirectory); Console.WriteLine("Copied the web-service files into the web-service installer input directory"); RunMsBuild($"\"{WebServiceInstaller.WixProj}\" /t:Build /p:Configuration=Release /m -nodeReuse:false"); Console.WriteLine("Created the web-service installer"); DeleteFiles(WebServiceInstaller.PublishDirectory, "*.wixpdb"); Console.WriteLine("Deleted unneeded files"); ZipDirectory(WebServiceInstaller.PublishDirectory, WebServiceInstaller.ArtifactsFile); Console.WriteLine("Created the web-service installer artifact"); }); Target("build-centron-net-only", () => { RunDotNet($"publish \"{CentronNet.CsProj}\" -r win-x64 --self-contained true -c Release -f net10.0-windows -nodeReuse:false"); Console.WriteLine("Finished building the c-entron.NET"); DeleteSubDirectoriesOtherThan(CentronNet.PublishDirectory, "de", "en", "Tools"); Console.WriteLine("Deleted unneeded files"); FixNLogConfig(CentronNet.PublishDirectory); Console.WriteLine("Fixed the nlog.config"); CreateCentronConnections(CentronNet.PublishDirectory); Console.WriteLine("Created the CentronConnections.xml"); }); Target("build-centron-net-installer-only", () => { if (WXSHelper.UpdateCentronSetupProductHeat()) throw new Exception($"The installer product heat {CentronNetInstaller.ProductHeat} is not up to date. Execute the target update-installer-product-heat and commit the changes."); MoveDirectory(CentronNet.PublishDirectory, CentronNetInstaller.InstallerInputDirectory); Console.WriteLine("Copied the c-entron.NET files into the c-entron.NET installer input directory"); RunMsBuild($"\"{CentronNetInstaller.WixProj}\" /t:Build /p:Configuration=Release /m -nodeReuse:false"); Console.WriteLine("Created the c-entron.NET installer"); DeleteFiles(CentronNetInstaller.PublishDirectory, "*.wixpdb"); Console.WriteLine("Deleted unneeded files"); }); Target("set-zip-directory-web-service", () => { ZipDirectory(WebServiceInstaller.PublishDirectory, WebServiceInstaller.ArtifactsFile); Console.WriteLine("Created the web-service installer artifact"); }); Target("set-zip-directory-centron-net", () => { ZipDirectory(CentronNetInstaller.PublishDirectory, CentronNetInstaller.ArtifactsFile); Console.WriteLine("Created the c-entron.NET installer artifact"); }); Target("set-dependencies-web-service", () => { var dependencies = DependencyGraph.ReadDependencyGraphs(WebService.CsProj, WebService.ConnectionManager.CsProj); DependencyGraph.Write(dependencies, CentronPaths.DependencyGraph.CentronWebServiceArtifactsFile); }); Target("set-dependencies-centron-net", () => { var dependencies = DependencyGraph.ReadDependencyGraph(CentronNet.CsProj); DependencyGraph.Write(dependencies, CentronPaths.DependencyGraph.CentronNetArtifactsFile); }); Target("build-web-service-linux", ["clean", "setup-versioning"], () => { RunDotNet($"publish \"{WebServiceLinux.CsProj}\" -r linux-x64 --self-contained false -c Release -f net10.0 -nodeReuse:false"); Console.WriteLine("Finished building the project"); File.Delete(WebServiceLinux.PublishedCentronHostConsoleConfigFile); FixNLogConfig(WebServiceLinux.PublishDirectory); Console.WriteLine("Cleaned up some files"); ZipDirectory(WebServiceLinux.PublishDirectory, WebServiceLinux.ArtifactsFile); Console.WriteLine("Created the web-service linux artifact"); }); Target("build", ["create-nuget-packages", "build-web-service", "build-centron-net"]); Target("build-installer", ["build-web-service-installer", "build-centron-net-installer"]); Target("update-installer-product-heat", ["build"], () => { // If you're adding new DLLs or Open-Source Nuget Packages, // don't forget to also update the file ThirdPartySoftware.cs WXSHelper.UpdateCentronSetupProductHeat(); WXSHelper.UpdateWebServiceSetupProductHeat(); }); Target("end-to-end-tests", ["setup-versioning"], () => { // Separate "dotnet build" call, so we can differentiate between build errors, and test errors RunDotNet($"build \"{EndToEndTests.CsProj}\" -c Release -f net10.0 -nodeReuse:false"); Console.WriteLine("Finished building the EndToEnd Tests project"); RunDotNetTest($"\"{EndToEndTests.CsProj}\" -c Release -f net10.0 --no-build --logger \"trx;LogFileName={EndToEndTests.ArtifactsFileName}\" --results-directory \"{EndToEndTests.ArtifactsDirectory}\" -nodeReuse:false", timeout: TimeSpan.FromMinutes(120)); Console.WriteLine("Executed the EndToEnd Tests"); }); Target("end-to-end-tests-only", () => { // Separate "dotnet build" call, so we can differentiate between build errors, and test errors RunDotNet($"build \"{EndToEndTests.CsProj}\" -c Release -f net10.0 -nodeReuse:false"); Console.WriteLine("Finished building the EndToEnd Tests project"); RunDotNetTest($"\"{EndToEndTests.CsProj}\" -c Release -f net10.0 --no-build --logger \"trx;LogFileName={EndToEndTests.ArtifactsFileName}\" --results-directory \"{EndToEndTests.ArtifactsDirectory}\" -nodeReuse:false", timeout: TimeSpan.FromMinutes(120)); Console.WriteLine("Executed the EndToEnd Tests"); }); Target("default", ["create-nuget-packages", "build-installer"]); await RunTargetsAndExitAsync(args); } } }