public void TestEngineShutdownWhileActive() { BuildRequestData data = new BuildRequestData("TestFile", new Dictionary <string, string>(), "TestToolsVersion", new string[0], null); BuildRequestConfiguration config = new BuildRequestConfiguration(1, data, "2.0"); _cache.AddConfiguration(config); string[] targets = new string[3] { "target1", "target2", "target3" }; BuildRequest request = CreateNewBuildRequest(1, targets); VerifyEngineStatus(BuildRequestEngineStatus.Uninitialized); _engine.InitializeForBuild(new NodeLoggingContext(_host.LoggingService, 0, false)); _engine.SubmitBuildRequest(request); Thread.Sleep(250); VerifyEngineStatus(BuildRequestEngineStatus.Active); _engine.CleanupForBuild(); WaitForEvent(_requestCompleteEvent, "RequestComplete"); Assert.Equal(request, _requestComplete_Request); Assert.Equal(BuildResultCode.Failure, _requestComplete_Result.OverallResult); VerifyEngineStatus(BuildRequestEngineStatus.Uninitialized); }
/// <summary> /// Handles the NodeConfiguration packet. /// </summary> private void HandleNodeConfiguration(NodeConfiguration configuration) { // Set the culture. #if FEATURE_CULTUREINFO_SETTERS CultureInfo.CurrentCulture = configuration.BuildParameters.Culture; CultureInfo.CurrentUICulture = configuration.BuildParameters.UICulture; #else Thread.CurrentThread.CurrentCulture = configuration.BuildParameters.Culture; Thread.CurrentThread.CurrentUICulture = configuration.BuildParameters.UICulture; #endif // Snapshot the initial environment. _savedEnvironment = CommunicationsUtilities.GetEnvironmentVariables(); // Save the current directory. _savedCurrentDirectory = NativeMethodsShared.GetCurrentDirectory(); // Set the node id. _componentHost.BuildParameters.NodeId = configuration.NodeId; _shutdownException = null; #if FEATURE_APPDOMAIN // And the AppDomainSetup _componentHost.BuildParameters.AppDomainSetup = configuration.AppDomainSetup; #endif // Declare in-proc _componentHost.BuildParameters.IsOutOfProc = false; // Set the logging exception handler ILoggingService loggingService = _componentHost.LoggingService; loggingService.OnLoggingThreadException += new LoggingExceptionDelegate(OnLoggingThreadException); // Now prep the buildRequestEngine for the build. _loggingContext = new NodeLoggingContext(loggingService, configuration.NodeId, true /* inProcNode */); _buildRequestEngine.OnEngineException += _engineExceptionEventHandler; _buildRequestEngine.OnNewConfigurationRequest += _newConfigurationRequestEventHandler; _buildRequestEngine.OnRequestBlocked += _requestBlockedEventHandler; _buildRequestEngine.OnRequestComplete += _requestCompleteEventHandler; if (_shutdownException != null) { Exception exception; HandleShutdown(out exception); throw exception; } _buildRequestEngine.InitializeForBuild(_loggingContext); // Finally store off this configuration packet. _currentConfiguration = configuration; }
private void HandleNodeConfiguration(NodeConfiguration configuration) { // Grab the system parameters. _buildParameters = configuration.BuildParameters; _buildParameters.ProjectRootElementCache = s_projectRootElementCacheBase; // Snapshot the current environment _savedEnvironment = CommunicationsUtilities.GetEnvironmentVariables(); // Change to the startup directory try { NativeMethodsShared.SetCurrentDirectory(BuildParameters.StartupDirectory); } catch (DirectoryNotFoundException) { // Somehow the startup directory vanished. This can happen if build was started from a USB Key and it was removed. NativeMethodsShared.SetCurrentDirectory(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory); } // Replicate the environment. First, unset any environment variables set by the previous configuration. if (_currentConfiguration != null) { foreach (string key in _currentConfiguration.BuildParameters.BuildProcessEnvironment.Keys) { Environment.SetEnvironmentVariable(key, null); } } // Now set the new environment foreach (KeyValuePair <string, string> environmentPair in _buildParameters.BuildProcessEnvironment) { Environment.SetEnvironmentVariable(environmentPair.Key, environmentPair.Value); } // We want to make sure the global project collection has the toolsets which were defined on the parent // so that any custom toolsets defined can be picked up by tasks who may use the global project collection but are // executed on the child node. ICollection <Toolset> parentToolSets = _buildParameters.ToolsetProvider.Toolsets; if (parentToolSets != null) { ProjectCollection.GlobalProjectCollection.RemoveAllToolsets(); foreach (Toolset toolSet in parentToolSets) { ProjectCollection.GlobalProjectCollection.AddToolset(toolSet); } } // Set the culture. CultureInfo.CurrentCulture = _buildParameters.Culture; CultureInfo.CurrentUICulture = _buildParameters.UICulture; // Get the node ID. _buildParameters.NodeId = configuration.NodeId; _buildParameters.IsOutOfProc = true; #if FEATURE_APPDOMAIN // And the AppDomainSetup _buildParameters.AppDomainSetup = configuration.AppDomainSetup; #endif // Set up the logging service. LoggingServiceFactory loggingServiceFactory = new LoggingServiceFactory(LoggerMode.Asynchronous, configuration.NodeId); _componentFactories.ReplaceFactory(BuildComponentType.LoggingService, loggingServiceFactory.CreateInstance); _loggingService = _componentFactories.GetComponent(BuildComponentType.LoggingService) as ILoggingService; BuildEventArgTransportSink sink = new BuildEventArgTransportSink(SendPacket); _shutdownException = null; if (configuration.LoggingNodeConfiguration.IncludeEvaluationMetaprojects) { _loggingService.IncludeEvaluationMetaprojects = true; } if (configuration.LoggingNodeConfiguration.IncludeEvaluationProfiles) { _loggingService.IncludeEvaluationProfile = true; } if (configuration.LoggingNodeConfiguration.IncludeTaskInputs) { _loggingService.IncludeTaskInputs = true; } if (configuration.LoggingNodeConfiguration.IncludeEvaluationPropertiesAndItems) { _loggingService.IncludeEvaluationPropertiesAndItems = true; } try { // If there are no node loggers to initialize dont do anything if (configuration.LoggerDescriptions?.Length > 0) { _loggingService.InitializeNodeLoggers(configuration.LoggerDescriptions, sink, configuration.NodeId); } } catch (Exception ex) when(!ExceptionHandling.IsCriticalException(ex)) { OnEngineException(ex); } _loggingService.OnLoggingThreadException += OnLoggingThreadException; string forwardPropertiesFromChild = Environment.GetEnvironmentVariable("MSBUILDFORWARDPROPERTIESFROMCHILD"); string[] propertyListToSerialize = null; // Get a list of properties which should be serialized if (!String.IsNullOrEmpty(forwardPropertiesFromChild)) { propertyListToSerialize = forwardPropertiesFromChild.Split(MSBuildConstants.SemicolonChar, StringSplitOptions.RemoveEmptyEntries); } _loggingService.PropertiesToSerialize = propertyListToSerialize; _loggingService.RunningOnRemoteNode = true; string forwardAllProperties = Environment.GetEnvironmentVariable("MSBUILDFORWARDALLPROPERTIESFROMCHILD"); if (String.Equals(forwardAllProperties, "1", StringComparison.OrdinalIgnoreCase) || _buildParameters.LogInitialPropertiesAndItems) { _loggingService.SerializeAllProperties = true; } else { _loggingService.SerializeAllProperties = false; } // Now prep the buildRequestEngine for the build. _loggingContext = new NodeLoggingContext(_loggingService, configuration.NodeId, false /* inProcNode */); if (_shutdownException != null) { HandleShutdown(out Exception exception); throw exception; } _buildRequestEngine.InitializeForBuild(_loggingContext); // Finally store off this configuration packet. _currentConfiguration = configuration; }