using System.Diagnostics; namespace Facepunch; /// /// Windows platform implementation /// internal class WindowsPlatform : Platform { protected override string PlatformBaseName => "win"; public override bool CompileSolution( string solutionName, bool forceRebuild = false ) { string vsDevCmdPath = FindVsDevCmdPath(); if ( string.IsNullOrEmpty( vsDevCmdPath ) ) { Log.Error( "Could not find Visual Studio Developer Command Prompt. Ensure Visual Studio is installed and accessible." ); return false; } string buildTarget = forceRebuild ? "/t:Rebuild" : "/t:Build"; return RunCommandWithVsEnv( vsDevCmdPath, $"msbuild {solutionName}.slnx {buildTarget} /p:Configuration=Release /p:Platform=x64 /m /v:minimal /clp:Summary" ); } /// /// Finds the Visual Studio Developer Command Prompt path /// /// Path to VsDevCmd.bat, or empty string if not found private string FindVsDevCmdPath() { // Find Visual Studio installation path string vsPath = string.Empty; using ( Process vsWhere = new Process() ) { vsWhere.StartInfo.FileName = "src\\devtools\\bin\\win64\\vswhere"; vsWhere.StartInfo.Arguments = "-latest -prerelease -property installationPath"; vsWhere.StartInfo.UseShellExecute = false; vsWhere.StartInfo.RedirectStandardOutput = true; vsWhere.StartInfo.CreateNoWindow = true; vsWhere.Start(); vsPath = vsWhere.StandardOutput.ReadToEnd().Trim(); vsWhere.WaitForExit(); } string vsDevCmdPath = Path.Combine( vsPath, "Common7\\Tools\\VsDevCmd.bat" ); if ( !File.Exists( vsDevCmdPath ) ) { Log.Error( $"Could not find VsDevCmd.bat at {vsDevCmdPath}" ); return string.Empty; } return vsDevCmdPath; } /// /// Runs a command with Visual Studio environment variables set /// /// Path to VsDevCmd.bat /// Command to execute /// True if command succeeded, false otherwise private bool RunCommandWithVsEnv( string vsDevCmdPath, string command ) { var arguments = $"/c \"call \"{vsDevCmdPath}\" -no_logo && cd src && {command}\""; return Utility.RunProcess( "cmd.exe", arguments, null ); } }