public static string GetMsbuildFilePath() { if (string.IsNullOrWhiteSpace(MsBuildFilePath)) { VisualStudioInstance instance = GetVisualStudioInstance(); if (instance != null) { foreach (string path in MsBuildPathArray) { string file = instance.Path + path; if (File.Exists(file)) { MsBuildFilePath = file; break; } } } } if (string.IsNullOrWhiteSpace(MsBuildFilePath)) { string vswhere = GetVswhereFilePath(); if (string.IsNullOrWhiteSpace(vswhere)) { return(null); } // -latest -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe" string vswhereResult = Win32.ShellExecute( vswhere, "-latest " + "-prerelease " + "-products * " + "-requiresAny " + "-requires Microsoft.Component.MSBuild " + "-property installationPath " ); if (!string.IsNullOrWhiteSpace(vswhereResult)) { foreach (string path in MsBuildPathArray) { string file = vswhereResult + path; if (File.Exists(file)) { MsBuildFilePath = file; break; } } } } return(MsBuildFilePath); }
public static string GetMsbuildFilePath() { string vswhere = string.Empty; if (Environment.Is64BitOperatingSystem) { vswhere = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe"); } else { vswhere = Environment.ExpandEnvironmentVariables("%ProgramFiles%\\Microsoft Visual Studio\\Installer\\vswhere.exe"); } // Note: vswere.exe was only released with build 15.0.26418.1 if (File.Exists(vswhere)) { string vswhereResult = Win32.ShellExecute(vswhere, "-latest " + "-products * " + "-requires Microsoft.Component.MSBuild " + "-property installationPath " ); if (string.IsNullOrEmpty(vswhereResult)) { return(null); } if (File.Exists(vswhereResult + "\\MSBuild\\15.0\\Bin\\MSBuild.exe")) { return(vswhereResult + "\\MSBuild\\15.0\\Bin\\MSBuild.exe"); } return(null); } else { try { VisualStudioInstance instance = FindVisualStudioInstance(); if (instance != null) { if (File.Exists(instance.Path + "\\MSBuild\\15.0\\Bin\\MSBuild.exe")) { return(instance.Path + "\\MSBuild\\15.0\\Bin\\MSBuild.exe"); } } } catch (Exception ex) { Program.PrintColorMessage("[VisualStudioInstance] " + ex, ConsoleColor.Red, true); } return(null); } }
public static string GetMsbuildFilePath() { VisualStudioInstance instance; string vswhere; string vswhereResult; instance = GetVisualStudioInstance(); if (instance != null) { foreach (string path in MsBuildPathArray) { string file = instance.Path + path; if (File.Exists(file)) { return(file); } } } vswhere = GetVswhereFilePath(); if (string.IsNullOrEmpty(vswhere)) { return(null); } vswhereResult = Win32.ShellExecute( vswhere, "-latest " + "-prerelease " + "-products * " + "-requiresAny " + "-requires Microsoft.Component.MSBuild " + "-property installationPath " ); if (string.IsNullOrEmpty(vswhereResult)) { return(null); } foreach (string path in MsBuildPathArray) { string file = vswhereResult + path; if (File.Exists(file)) { return(file); } } return(null); }
public static string GetFilePathFromPath(string FileName) { string where = Environment.ExpandEnvironmentVariables("%windir%\\System32\\where.exe"); if (File.Exists(where)) { string whereResult = Win32.ShellExecute(where, FileName); if (!string.IsNullOrEmpty(whereResult)) { return(whereResult); } } return(null); }
public static bool UploadFile(string FileName) { try { if (!string.IsNullOrWhiteSpace(AppVeyorPath)) { Win32.ShellExecute("appveyor", $"PushArtifact \"{FileName}\" "); } } catch (Exception ex) { Program.PrintColorMessage("[UploadFile] " + ex, ConsoleColor.Red, true); return(false); } return(true); }
public static bool UpdateBuildVersion(string BuildVersion) { try { if (!string.IsNullOrWhiteSpace(AppVeyorPath)) { Win32.ShellExecute("appveyor", $"UpdateBuild -Version \"{BuildVersion}\" "); } } catch (Exception ex) { Program.PrintColorMessage("[VisualStudioInstance] " + ex, ConsoleColor.Red, true); return(false); } return(true); }
public static bool UpdateBuildVersion(string BuildVersion) { try { string AppVeyorFilePath = Win32.SearchFile("appveyor.exe"); if (!string.IsNullOrWhiteSpace(AppVeyorFilePath) && !string.IsNullOrWhiteSpace(BuildVersion)) { Win32.ShellExecute("appveyor", $"UpdateBuild -Version \"{BuildVersion}\" "); return(true); } } catch (Exception ex) { Program.PrintColorMessage("[UpdateBuildVersion] " + ex, ConsoleColor.Red, true); } return(false); }
public static string GetMsbuildFilePath() { string vswhere = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe"); // Note: vswere.exe was only released with build 15.0.26418.1 if (File.Exists(vswhere)) { string vswhereResult = Win32.ShellExecute(vswhere, "-latest " + "-requires Microsoft.Component.MSBuild " + "-property installationPath " ); if (string.IsNullOrEmpty(vswhereResult)) { return(null); } if (File.Exists(vswhereResult + "\\MSBuild\\15.0\\Bin\\MSBuild.exe")) { return(vswhereResult + "\\MSBuild\\15.0\\Bin\\MSBuild.exe"); } return(null); } else { VisualStudioInstance instance = FindVisualStudioInstance(); if (instance != null) { if (File.Exists(instance.Path + "\\MSBuild\\15.0\\Bin\\MSBuild.exe")) { return(instance.Path + "\\MSBuild\\15.0\\Bin\\MSBuild.exe"); } } return(null); } }
public static void BuildAppxPackage(string BuildOutputFolder, string BuildLongVersion, BuildFlags Flags) { string sdkRootPath = string.Empty; string[] cleanupAppxArray = { BuildOutputFolder + "\\AppxManifest32.xml", BuildOutputFolder + "\\AppxManifest64.xml", BuildOutputFolder + "\\package32.map", BuildOutputFolder + "\\package64.map", BuildOutputFolder + "\\bundle.map", BuildOutputFolder + "\\ProcessHacker-44.png", BuildOutputFolder + "\\ProcessHacker-50.png", BuildOutputFolder + "\\ProcessHacker-150.png" }; Program.PrintColorMessage("Building processhacker-build-package.appxbundle...", ConsoleColor.Cyan); using (var view32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) { using (var kitsroot = view32.OpenSubKey("Software\\Microsoft\\Windows Kits\\Installed Roots", false)) { sdkRootPath = (string)kitsroot.GetValue("WdkBinRootVersioned", string.Empty); } } if (string.IsNullOrEmpty(sdkRootPath)) { Program.PrintColorMessage("[Skipped] Windows SDK", ConsoleColor.Red); return; } string makeAppxExePath = Environment.ExpandEnvironmentVariables(sdkRootPath + "\\x64\\MakeAppx.exe"); string signToolExePath = Environment.ExpandEnvironmentVariables(sdkRootPath + "\\x64\\SignTool.exe"); try { //Win32.ImageResizeFile(44, "ProcessHacker\\resources\\ProcessHacker.png", BuildOutputFolder + "\\ProcessHacker-44.png"); //Win32.ImageResizeFile(50, "ProcessHacker\\resources\\ProcessHacker.png", BuildOutputFolder + "\\ProcessHacker-50.png"); //Win32.ImageResizeFile(150, "ProcessHacker\\resources\\ProcessHacker.png", BuildOutputFolder + "\\ProcessHacker-150.png"); if ((Flags & BuildFlags.Build32bit) == BuildFlags.Build32bit) { // create the package manifest string appxManifestString = Properties.Resources.AppxManifest; appxManifestString = appxManifestString.Replace("PH_APPX_ARCH", "x86"); appxManifestString = appxManifestString.Replace("PH_APPX_VERSION", BuildLongVersion); File.WriteAllText(BuildOutputFolder + "\\AppxManifest32.xml", appxManifestString); // create the package mapping file StringBuilder packageMap32 = new StringBuilder(0x100); packageMap32.AppendLine("[Files]"); packageMap32.AppendLine("\"" + BuildOutputFolder + "\\AppxManifest32.xml\" \"AppxManifest.xml\""); packageMap32.AppendLine("\"" + BuildOutputFolder + "\\ProcessHacker-44.png\" \"Assets\\ProcessHacker-44.png\""); packageMap32.AppendLine("\"" + BuildOutputFolder + "\\ProcessHacker-50.png\" \"Assets\\ProcessHacker-50.png\""); packageMap32.AppendLine("\"" + BuildOutputFolder + "\\ProcessHacker-150.png\" \"Assets\\ProcessHacker-150.png\""); var filesToAdd = Directory.GetFiles("bin\\Release32", "*", SearchOption.AllDirectories); foreach (string filePath in filesToAdd) { // Ignore junk files if (filePath.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".iobj", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".ipdb", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".exp", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".lib", StringComparison.OrdinalIgnoreCase)) { continue; } packageMap32.AppendLine("\"" + filePath + "\" \"" + filePath.Substring("bin\\Release32\\".Length) + "\""); } File.WriteAllText(BuildOutputFolder + "\\package32.map", packageMap32.ToString()); // create the package var error = Win32.ShellExecute( makeAppxExePath, "pack /o /f " + BuildOutputFolder + "\\package32.map /p " + BuildOutputFolder + "\\processhacker-build-package-x32.appx" ); Program.PrintColorMessage(Environment.NewLine + error, ConsoleColor.Gray, true, Flags); // sign the package error = Win32.ShellExecute( signToolExePath, "sign /v /fd SHA256 /a /f " + BuildOutputFolder + "\\processhacker-appx.pfx /td SHA256 " + BuildOutputFolder + "\\processhacker-build-package-x32.appx" ); Program.PrintColorMessage(Environment.NewLine + error, ConsoleColor.Gray, true, Flags); } if ((Flags & BuildFlags.Build64bit) == BuildFlags.Build64bit) { // create the package manifest string appxManifestString = Properties.Resources.AppxManifest; appxManifestString = appxManifestString.Replace("PH_APPX_ARCH", "x64"); appxManifestString = appxManifestString.Replace("PH_APPX_VERSION", BuildLongVersion); File.WriteAllText(BuildOutputFolder + "\\AppxManifest64.xml", appxManifestString); StringBuilder packageMap64 = new StringBuilder(0x100); packageMap64.AppendLine("[Files]"); packageMap64.AppendLine("\"" + BuildOutputFolder + "\\AppxManifest64.xml\" \"AppxManifest.xml\""); packageMap64.AppendLine("\"" + BuildOutputFolder + "\\ProcessHacker-44.png\" \"Assets\\ProcessHacker-44.png\""); packageMap64.AppendLine("\"" + BuildOutputFolder + "\\ProcessHacker-50.png\" \"Assets\\ProcessHacker-50.png\""); packageMap64.AppendLine("\"" + BuildOutputFolder + "\\ProcessHacker-150.png\" \"Assets\\ProcessHacker-150.png\""); var filesToAdd = Directory.GetFiles("bin\\Release64", "*", SearchOption.AllDirectories); foreach (string filePath in filesToAdd) { // Ignore junk files if (filePath.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".iobj", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".ipdb", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".exp", StringComparison.OrdinalIgnoreCase) || filePath.EndsWith(".lib", StringComparison.OrdinalIgnoreCase)) { continue; } packageMap64.AppendLine("\"" + filePath + "\" \"" + filePath.Substring("bin\\Release64\\".Length) + "\""); } File.WriteAllText(BuildOutputFolder + "\\package64.map", packageMap64.ToString()); // create the package var error = Win32.ShellExecute( makeAppxExePath, "pack /o /f " + BuildOutputFolder + "\\package64.map /p " + BuildOutputFolder + "\\processhacker-build-package-x64.appx" ); Program.PrintColorMessage(Environment.NewLine + error, ConsoleColor.Gray, true, Flags); // sign the package error = Win32.ShellExecute( signToolExePath, "sign /v /fd SHA256 /a /f " + BuildOutputFolder + "\\processhacker-appx.pfx /td SHA256 " + BuildOutputFolder + "\\processhacker-build-package-x64.appx" ); Program.PrintColorMessage(Environment.NewLine + error, ConsoleColor.Gray, true, Flags); } { // create the appx bundle map StringBuilder bundleMap = new StringBuilder(0x100); bundleMap.AppendLine("[Files]"); bundleMap.AppendLine("\"" + BuildOutputFolder + "\\processhacker-build-package-x32.appx\" \"processhacker-build-package-x32.appx\""); bundleMap.AppendLine("\"" + BuildOutputFolder + "\\processhacker-build-package-x64.appx\" \"processhacker-build-package-x64.appx\""); File.WriteAllText(BuildOutputFolder + "\\bundle.map", bundleMap.ToString()); if (File.Exists(BuildOutputFolder + "\\processhacker-build-package.appxbundle")) { File.Delete(BuildOutputFolder + "\\processhacker-build-package.appxbundle"); } // create the appx bundle package var error = Win32.ShellExecute( makeAppxExePath, "bundle /f " + BuildOutputFolder + "\\bundle.map /p " + BuildOutputFolder + "\\processhacker-build-package.appxbundle" ); Program.PrintColorMessage(Environment.NewLine + error, ConsoleColor.Gray, true, Flags); // sign the appx bundle package error = Win32.ShellExecute( signToolExePath, "sign /v /fd SHA256 /a /f " + BuildOutputFolder + "\\processhacker-appx.pfx /td SHA256 " + BuildOutputFolder + "\\processhacker-build-package.appxbundle" ); Program.PrintColorMessage(Environment.NewLine + error, ConsoleColor.Gray, true, Flags); } foreach (string file in cleanupAppxArray) { if (File.Exists(file)) { File.Delete(file); } } } catch (Exception ex) { Program.PrintColorMessage("[ERROR] " + ex, ConsoleColor.Red); } }
public static bool BuildAppxSignature(string BuildOutputFolder) { string sdkRootPath = string.Empty; string[] cleanupAppxArray = { BuildOutputFolder + "\\processhacker-appx.pvk", BuildOutputFolder + "\\processhacker-appx.cer", BuildOutputFolder + "\\processhacker-appx.pfx" }; Program.PrintColorMessage("Building Appx Signature...", ConsoleColor.Cyan); using (var view32 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)) { using (var kitsroot = view32.OpenSubKey("Software\\Microsoft\\Windows Kits\\Installed Roots", false)) { sdkRootPath = (string)kitsroot.GetValue("WdkBinRootVersioned", string.Empty); } } if (string.IsNullOrEmpty(sdkRootPath)) { Program.PrintColorMessage("[Skipped] Windows SDK", ConsoleColor.Red); return(false); } string makeCertExePath = Environment.ExpandEnvironmentVariables(sdkRootPath + "\\x64\\MakeCert.exe"); string pvk2PfxExePath = Environment.ExpandEnvironmentVariables(sdkRootPath + "\\x64\\Pvk2Pfx.exe"); string certUtilExePath = Win32.SearchFile("certutil.exe"); try { foreach (string file in cleanupAppxArray) { if (File.Exists(file)) { File.Delete(file); } } string output = Win32.ShellExecute(makeCertExePath, "/n " + "\"CN=ProcessHacker, O=ProcessHacker, C=AU\" " + "/r /h 0 " + "/eku \"1.3.6.1.5.5.7.3.3,1.3.6.1.4.1.311.10.3.13\" " + "/sv " + BuildOutputFolder + "\\processhacker-appx.pvk " + BuildOutputFolder + "\\processhacker-appx.cer " ); if (!string.IsNullOrEmpty(output) && !output.Equals("Succeeded", StringComparison.OrdinalIgnoreCase)) { Program.PrintColorMessage("[MakeCert] " + output, ConsoleColor.Red); return(false); } output = Win32.ShellExecute(pvk2PfxExePath, "/pvk " + BuildOutputFolder + "\\processhacker-appx.pvk " + "/spc " + BuildOutputFolder + "\\processhacker-appx.cer " + "/pfx " + BuildOutputFolder + "\\processhacker-appx.pfx " ); if (!string.IsNullOrEmpty(output)) { Program.PrintColorMessage("[Pvk2Pfx] " + output, ConsoleColor.Red); return(false); } output = Win32.ShellExecute(certUtilExePath, "-addStore TrustedPeople " + BuildOutputFolder + "\\processhacker-appx.cer" ); if (!string.IsNullOrEmpty(output) && !output.Contains("command completed successfully")) { Program.PrintColorMessage("[Certutil] " + output, ConsoleColor.Red); return(false); } Program.PrintColorMessage("[Pvk2Pfx] " + output, ConsoleColor.Green); } catch (Exception ex) { Program.PrintColorMessage("[ERROR] " + ex, ConsoleColor.Red); return(false); } return(true); }
public static string GetMsbuildFilePath() { string[] MsBuildPathArray = { "\\MSBuild\\Current\\Bin\\MSBuild.exe", "\\MSBuild\\15.0\\Bin\\MSBuild.exe" }; string vswhere = Environment.ExpandEnvironmentVariables("%ProgramFiles%\\Microsoft Visual Studio\\Installer\\vswhere.exe"); if (!File.Exists(vswhere)) { vswhere = Environment.ExpandEnvironmentVariables("%ProgramFiles(x86)%\\Microsoft Visual Studio\\Installer\\vswhere.exe"); } if (!File.Exists(vswhere)) { vswhere = Environment.ExpandEnvironmentVariables("%ProgramW6432%\\Microsoft Visual Studio\\Installer\\vswhere.exe"); } if (File.Exists(vswhere)) { string vswhereResult = Win32.ShellExecute(vswhere, "-latest " + "-prerelease " + "-products * " + "-requires Microsoft.Component.MSBuild " + "-property installationPath " ); if (string.IsNullOrEmpty(vswhereResult)) { return(null); } foreach (string path in MsBuildPathArray) { if (File.Exists(vswhereResult + path)) { return(vswhereResult + path); } } return(null); } else { try { VisualStudioInstance instance = FindVisualStudioInstance(); if (instance != null) { foreach (string path in MsBuildPathArray) { if (File.Exists(instance.Path + path)) { return(instance.Path + path); } } } } catch (Exception ex) { Program.PrintColorMessage("[VisualStudioInstance] " + ex, ConsoleColor.Red, true); } return(null); } }