internal static (string processFilePath, string commandLineArguments, string toolFilePath) GetServerProcessInfo(string clientDir, string pipeName) { var serverPathWithoutExtension = Path.Combine(clientDir, "VBCSCompiler"); var commandLineArgs = $@"""-pipename:{pipeName}"""; return(RuntimeHostInfo.GetProcessInfo(serverPathWithoutExtension, commandLineArgs)); }
/// <summary> /// This generates the path to the executable that is directly ran. /// This could be the managed assembly itself (on desktop .NET on Windows), /// or a runtime such as dotnet. /// </summary> protected sealed override string GenerateFullPathToTool() { return(IsManagedTool ? RuntimeHostInfo.GetProcessInfo( PathToManagedToolWithoutExtension, string.Empty ).processFilePath : PathToNativeTool); }
/// <summary> /// GenerateCommandLineCommands generates the actual OS-level arguments: /// if dotnet needs to be executed and the managed assembly is the first argument, /// then this will contain the managed assembly followed by ToolArguments /// </summary> protected sealed override string GenerateCommandLineCommands() { var commandLineArguments = ToolArguments; if (IsManagedTool) { (_, commandLineArguments, _) = RuntimeHostInfo.GetProcessInfo(PathToManagedToolWithoutExtension, commandLineArguments); } return(commandLineArguments); }
internal static bool TryCreateServerCore(string clientDir, string pipeName) { var serverPathWithoutExtension = Path.Combine(clientDir, "VBCSCompiler"); var serverInfo = RuntimeHostInfo.GetProcessInfo(serverPathWithoutExtension, $"-pipename:{pipeName}"); if (!File.Exists(serverInfo.toolFilePath)) { return(false); } if (PlatformInformation.IsWindows) { // As far as I can tell, there isn't a way to use the Process class to // create a process with no stdin/stdout/stderr, so we use P/Invoke. // This code was taken from MSBuild task starting code. STARTUPINFO startInfo = new STARTUPINFO(); startInfo.cb = Marshal.SizeOf(startInfo); startInfo.hStdError = InvalidIntPtr; startInfo.hStdInput = InvalidIntPtr; startInfo.hStdOutput = InvalidIntPtr; startInfo.dwFlags = STARTF_USESTDHANDLES; uint dwCreationFlags = NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW; PROCESS_INFORMATION processInfo; Log("Attempting to create process '{0}'", serverInfo.processFilePath); var builder = new StringBuilder($@"""{serverInfo.processFilePath}"" {serverInfo.commandLineArguments}"); bool success = CreateProcess( lpApplicationName: null, lpCommandLine: builder, lpProcessAttributes: NullPtr, lpThreadAttributes: NullPtr, bInheritHandles: false, dwCreationFlags: dwCreationFlags, lpEnvironment: NullPtr, // Inherit environment lpCurrentDirectory: clientDir, lpStartupInfo: ref startInfo, lpProcessInformation: out processInfo); if (success) { Log("Successfully created process with process id {0}", processInfo.dwProcessId); CloseHandle(processInfo.hProcess); CloseHandle(processInfo.hThread); } else { Log("Failed to create process. GetLastError={0}", Marshal.GetLastWin32Error()); } return(success); } else { try { var startInfo = new ProcessStartInfo() { FileName = serverInfo.processFilePath, Arguments = serverInfo.commandLineArguments, UseShellExecute = false, WorkingDirectory = clientDir, RedirectStandardInput = true, RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true }; Process.Start(startInfo); return(true); } catch { return(false); } } }