public static void Fatal(object message) { var text = message != null?message.ToString() : "Null"; fatalActivated = true; lock ( lockObject ) { bool handled = false; DumpToFile("Fatal: " + text + "\r\n" + GetStackTrace()); string copyLogFileName = FatalErrorCopyLogFile(); if (copyLogFileName != null) { text = "Fatal log file created: " + copyLogFileName + ".\t\n\t\n" + text; } Handlers.Fatal(text, copyLogFileName, ref handled); if (!handled) { string messageBoxText = text + "\r\n\r\n\r\n" + GetStackTrace(); LogPlatformFunctionality.Get().ShowMessageBox(messageBoxText, "Fatal"); //: Exception" ); if (AfterFatal != null) { AfterFatal(); } Process process = Process.GetCurrentProcess(); process.Kill(); } } }
static void HandlersError(string text, ref bool dumpToLogFile) { bool handled = false; Handlers.Error(text, ref handled, ref dumpToLogFile); if (!handled) { LogPlatformFunctionality.Get().ShowMessageBox(text, "Error"); } }
public static void FatalAsException(object message) { var text = message != null?message.ToString() : "Null"; lock ( lockObject ) { bool handled = false; DumpToFile("Exception: " + text); string copyLogFileName = FatalErrorCopyLogFile(); if (copyLogFileName != null) { text = "Fatal log file created: " + copyLogFileName + ".\t\n\t\n" + text; } Handlers.Fatal(text, copyLogFileName, ref handled); if (!handled) { //if( PlatformInfo.Platform == PlatformInfo.Platforms.Android ) //{ // ( (AndroidPlatformFunctionality)PlatformFunctionality.Get() ).Fatal( text ); // return; //} //else //{ LogPlatformFunctionality.Get().ShowMessageBox(text, "Fatal: Exception"); AfterFatal?.Invoke(); Process process = Process.GetCurrentProcess(); process.Kill(); //} } } }
//static string GetTargetFrameworkRootPath() //{ // return Path.Combine( VirtualFileSystem.Directories.EngineInternal, @"Tools\Framework" ); //} //static bool ExecuteMSBuild( string args, out string result ) //{ // var msBuildExePath = Path.Combine( GetMSBuildPath(), "msbuild.exe" ); // return ProcessUtils.RunAndWait( msBuildExePath, args, out result ) == 0; // //if( ProcessUtils.RunAndWait( msBuildExePath, args, out string result ) != 0 ) // //{ // // xx xx; // // throw new Exception( string.Format( "Failed to build Visual Studio project using arguments '{0} {1}'.\nOutput:{2}\n", msBuildExePath, args, result ) ); // // //throw new BuildException( string.Format( "Failed to build Visual Studio project using arguments '{0} {1}'.\nOutput:{2}\n", msBuildExePath, args, result ) ); // //} // //return result; //} //public static bool RestoreNuGetPackets( string solutionDir, string productName, BuildConfig config ) //{ // var fileName = $"{productName}.sln"; // //TODO: Kill Running App before build? // // restore changes in msbuild 15.5 https://stackoverflow.com/questions/46773698/msbuild-15-nuget-restore-and-build // string arguments; // { // var builder = new StringBuilder(); // builder.Append( $"\"{solutionDir}\\{fileName}\" /nologo /maxcpucount /t:Restore" ); // builder.Append( $" /p:SolutionDir=\"{solutionDir}\"" ); // builder.Append( $" /p:Configuration={config.BuildConfiguration}" ); // builder.Append( $" /p:Platform=\"{config.BuildPlatform}\"" ); // //const bool InternalNuGet = true; // //if( InternalNuGet ) // //{ // // string nuGetRestoreTargets = Path.Combine( ToolsetHelper.GetNuGetBuildPath(), "NuGet.targets" ); // // args.Append( $" /p:NuGetRestoreTargets=\"{nuGetRestoreTargets}\"" ); // //} // builder.Append( $" /Verbosity:{config.Verbosity}" ); // arguments = builder.ToString(); // } // //!!!! // Log.Fatal( "VisualStudioSolutionUtility: RestoreNuGetPackets: impl." ); // var msBuildExePath = Path.Combine( GetMSBuildFolderPath(), "msbuild.exe" ); // var success = ProcessUtility.RunAndWait( msBuildExePath, arguments, out var result ) == 0; // result = result.Trim( new char[] { '\r', '\n' } ); // if( success ) // { // // result ignored ? // Log.Info( $"NuGet packages for \'{fileName}\' was restored successfully." ); // } // else // { // var error = $"Unable to restore NuGet packages for \'{fileName}\'.\r\n\r\n" + result; // Log.Error( result ); // } // return success; //} public static bool BuildSolution(string solutionDir, string productName, BuildConfig config, bool rebuild) { var fileName = $"{productName}.sln"; string arguments; { //!!!!юзает последнюю версию фрейморка. например Preview //[-r | --runtime<RUNTIME_IDENTIFIER>] var builder = new StringBuilder(); builder.Append("build"); builder.Append($" \"{solutionDir}\\{productName}.sln\""); builder.Append($" --configuration {config.BuildConfiguration}"); builder.Append($" --framework netcoreapp3.1"); if (!string.IsNullOrEmpty(config.OutDir)) { builder.Append($" --output \"{config.OutDir}\""); } builder.Append($" --verbosity {config.Verbosity}"); //!!!!optional? //builder.Append( " --no-restore" ); if (rebuild) { builder.Append(" --no-incremental"); } //builder.Append( $" /p:Platform=\"{config.BuildPlatform}\"" ); //if( !string.IsNullOrEmpty( config.OutputAssemblyName ) ) // builder.Append( $" /p:AssemblyName=\"{config.OutputAssemblyName}\"" ); //builder.Append( $" /p:AppxPackage={config.CreateAppxPackage}" ); //builder.Append( $" /p:AppxBundlePlatforms=\"{config.AppxBundlePlatforms}\"" ); //builder.Append( $" /p:AppxBundle={config.CreateAppxBundle}" ); //builder.Append( $" /p:AppxPackageSigningEnabled={config.AppxPackageSigningEnabled}" ); //// instead of TargetFrameworkRootPath we can also use FrameworkPathOverride prop but only for .net 4.x building. //// FrameworkPathOverride will not work for UWP app building. //string frameworkRootPath = GetTargetFrameworkRootPath(); //if( Directory.Exists( frameworkRootPath ) ) // builder.Append( $" /p:TargetFrameworkRootPath=\"{frameworkRootPath}\"" ); //else // Log.Info( $"Framework Root Path '{frameworkRootPath}' not found. will be used Targeting Pack installed in system." ); arguments = builder.ToString(); } var msBuildExePath = GetDotNetExecutablePath(); var success = ProcessUtility.RunAndWait(msBuildExePath, arguments, out var result) == 0; //var msBuildExePath = Path.Combine( GetDotNetExecutablePath(), Path.Combine( GetMSBuildFolderPath(), "MSBuild.dll" ) ); //var msBuildExePath = Path.Combine( GetMSBuildFolderPath(), "msbuild.exe" ); //var success = ProcessUtility.RunAndWait( msBuildExePath, arguments, out var result ) == 0; result = result.Trim(new char[] { '\r', '\n' }); if (success) { //!!!!result ignored? Log.Info($"\'{fileName}\' was built successfully."); return(true); } else { if (EngineApp.ApplicationType == EngineApp.ApplicationTypeEnum.Simulation) { var error = $"Unable to compile solution \'{fileName}\'. Continue?\r\n\r\n{result}\r\n\r\nCommand line:\r\n{msBuildExePath} {arguments}\r\n\r\nSee details in log."; if (LogPlatformFunctionality.Get().ShowMessageBox(error, "Error", EMessageBoxButtons.OKCancel) == EDialogResult.Cancel) { Process.GetCurrentProcess().Kill(); Environment.Exit(0); } } else { var error = $"Unable to compile solution \'{fileName}\'.\r\n\r\n{result}\r\n\r\nCommand line:\r\n{msBuildExePath} {arguments}\r\n\r\nSee details in log."; Log.Error(error); } return(false); } //var fileName = $"{productName}.sln"; //string arguments; //{ // var builder = new StringBuilder(); // builder.Append( $"\"{solutionDir}\\{productName}.sln\" /nologo /maxcpucount /t:Build" ); // builder.Append( $" /p:SolutionDir=\"{solutionDir}\"" ); // if( !string.IsNullOrEmpty( config.OutDir ) ) // builder.Append( $" /p:OutDir=\"{config.OutDir}\"" ); // builder.Append( $" /p:Configuration={config.BuildConfiguration}" ); // builder.Append( $" /p:Platform=\"{config.BuildPlatform}\"" ); // if( !string.IsNullOrEmpty( config.OutputAssemblyName ) ) // builder.Append( $" /p:AssemblyName=\"{config.OutputAssemblyName}\"" ); // builder.Append( $" /p:AppxPackage={config.CreateAppxPackage}" ); // builder.Append( $" /p:AppxBundlePlatforms=\"{config.AppxBundlePlatforms}\"" ); // builder.Append( $" /p:AppxBundle={config.CreateAppxBundle}" ); // builder.Append( $" /p:AppxPackageSigningEnabled={config.AppxPackageSigningEnabled}" ); // // instead of TargetFrameworkRootPath we can also use FrameworkPathOverride prop but only for .net 4.x building. // // FrameworkPathOverride will not work for UWP app building. // string frameworkRootPath = GetTargetFrameworkRootPath(); // if( Directory.Exists( frameworkRootPath ) ) // builder.Append( $" /p:TargetFrameworkRootPath=\"{frameworkRootPath}\"" ); // else // Log.Info( $"Framework Root Path '{frameworkRootPath}' not found. will be used Targeting Pack installed in system." ); // builder.Append( $" /Verbosity:{config.Verbosity}" ); // if( rebuild ) // builder.Append( " /t:Rebuild" ); // //const bool PerformanceSummary = false; // //if( PerformanceSummary ) // // builder.Append( $" /clp:performancesummary" ); // arguments = builder.ToString(); //} //var msBuildExePath = Path.Combine( GetDotNetExecutablePath(), Path.Combine( GetMSBuildFolderPath(), "MSBuild.dll" ) ); //var success = ProcessUtility.RunAndWait( msBuildExePath, arguments, out var result ) == 0; ////var msBuildExePath = Path.Combine( GetMSBuildFolderPath(), "msbuild.exe" ); ////var success = ProcessUtility.RunAndWait( msBuildExePath, arguments, out var result ) == 0; //result = result.Trim( new char[] { '\r', '\n' } ); //if( success ) //{ // //!!!!result ignored? // Log.Info( $"\'{fileName}\' was built successfully." ); // return true; //} //else //{ // var error = $"Unable to compile solution \'{fileName}\'.\r\n\r\n{result}\r\n\r\nCommand line:\r\n{msBuildExePath} {arguments}\r\n\r\nSee details in log."; // Log.Error( error ); // return false; //} }