protected async Task <BuildInfo> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = _loadedProject.CreateProjectInstance(); if (!executedProject.Targets.ContainsKey("Compile")) { return(new BuildInfo(executedProject, null)); } var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(_loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(_loadedProject.ProjectCollection); var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, new string[] { "Compile" }, hostServices); BuildResult result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (result.OverallResult == BuildResultCode.Failure) { return(new BuildInfo(executedProject, result.Exception?.Message ?? "")); } else { return(new BuildInfo(executedProject, null)); } }
protected async Task <BuildResult> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // prepare for building var buildTargets = new BuildTargets(loadedProject, "Compile"); // Don't execute this one. It will build referenced projects. // Even when DesignTimeBuild is defined above, it will still add the referenced project's output to the references list // which we don't want. buildTargets.Remove("ResolveProjectReferences"); // don't execute anything after CoreCompile target, since we've // already done everything we need to compute compiler inputs by then. buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: false); // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = loadedProject.CreateProjectInstance(); var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(this.loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(loadedProject.ProjectCollection); var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, buildTargets.Targets, hostServices); var result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); return(new BuildResult(result, executedProject)); }
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) { ProjectInstance = projectInstance; TargetNames = targetsToBuild; HostServices = hostServices; Flags = flags; }
public void TestInvalidHostObjectRegistration_NullTarget() { Assert.Throws<ArgumentNullException>(() => { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.RegisterHostObject("project", null, "task", hostObject); } ); }
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) { if (targetsToBuild == null) throw new ArgumentNullException ("targetsToBuild"); ProjectInstance = projectInstance; TargetNames = targetsToBuild; HostServices = hostServices; Flags = flags; }
public void TestValidHostObjectRegistration() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); TestHostObject hostObject2 = new TestHostObject(); TestHostObject hostObject3 = new TestHostObject(); hostServices.RegisterHostObject("foo.proj", "target", "task", hostObject); hostServices.RegisterHostObject("foo.proj", "target2", "task", hostObject2); hostServices.RegisterHostObject("foo.proj", "target", "task2", hostObject3); Assert.AreSame(hostObject, hostServices.GetHostObject("foo.proj", "target", "task")); Assert.AreSame(hostObject2, hostServices.GetHostObject("foo.proj", "target2", "task")); Assert.AreSame(hostObject3, hostServices.GetHostObject("foo.proj", "target", "task2")); }
/// <summary> /// Copy constructor /// </summary> private BuildParameters(BuildParameters other) { ErrorUtilities.VerifyThrowInternalNull(other, "other"); _buildId = other._buildId; _culture = other._culture; _defaultToolsVersion = other._defaultToolsVersion; _enableNodeReuse = other._enableNodeReuse; _buildProcessEnvironment = other._buildProcessEnvironment != null ? new Dictionary <string, string>(other._buildProcessEnvironment) : null; _environmentProperties = other._environmentProperties != null ? new PropertyDictionary <ProjectPropertyInstance>(other._environmentProperties) : null; _forwardingLoggers = other._forwardingLoggers != null ? new List <ForwardingLoggerRecord>(other._forwardingLoggers) : null; _globalProperties = other._globalProperties != null ? new PropertyDictionary <ProjectPropertyInstance>(other._globalProperties) : null; _hostServices = other._hostServices; _loggers = other._loggers != null ? new List <ILogger>(other._loggers) : null; _maxNodeCount = other._maxNodeCount; _memoryUseLimit = other._memoryUseLimit; _nodeExeLocation = other._nodeExeLocation; NodeId = other.NodeId; _onlyLogCriticalEvents = other._onlyLogCriticalEvents; #if FEATURE_THREAD_PRIORITY BuildThreadPriority = other.BuildThreadPriority; #endif _toolsetProvider = other._toolsetProvider; _toolsetDefinitionLocations = other._toolsetDefinitionLocations; _toolsetProvider = other._toolsetProvider; _uiCulture = other._uiCulture; _detailedSummary = other._detailedSummary; _shutdownInProcNodeOnBuildFinish = other._shutdownInProcNodeOnBuildFinish; ProjectRootElementCache = other.ProjectRootElementCache; ResetCaches = other.ResetCaches; LegacyThreadingSemantics = other.LegacyThreadingSemantics; _saveOperatingEnvironment = other._saveOperatingEnvironment; _useSynchronousLogging = other._useSynchronousLogging; _disableInProcNode = other._disableInProcNode; _logTaskInputs = other._logTaskInputs; _logInitialPropertiesAndItems = other._logInitialPropertiesAndItems; _warningsAsErrors = other._warningsAsErrors == null ? null : new HashSet <string>(other._warningsAsErrors, StringComparer.OrdinalIgnoreCase); _warningsAsMessages = other._warningsAsMessages == null ? null : new HashSet <string>(other._warningsAsMessages, StringComparer.OrdinalIgnoreCase); _projectLoadSettings = other._projectLoadSettings; }
private async Task <Compilation> BuildAsync(string inputProjectFile, ICompilationHost compilationHost, CancellationToken cancellationToken = default(CancellationToken)) { var hostServices = new HostServices(); hostServices.RegisterHostObject(inputProjectFile, "CoreCompile", compilationHost.TaskName, compilationHost); var properties = new Dictionary <string, string>(_properties ?? ImmutableDictionary <string, string> .Empty) { ["DesignTimeBuild"] = "true", // this will tell msbuild to not build the dependent projects ["BuildingInsideVisualStudio"] = "true" // this will force CoreCompile task to execute even if all inputs and outputs are up to date }; var errorLogger = new Logger() { Verbosity = LoggerVerbosity.Normal }; var buildParameters = new BuildParameters { GlobalProperties = properties, Loggers = new ILogger[] { errorLogger } }; var buildRequestData = new BuildRequestData(inputProjectFile, properties, null, new string[] { "Compile" }, hostServices); var sw = new Stopwatch(); sw.Start(); Log.Trace("Begin MSBuild"); var result = await BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); sw.Stop(); Log.Trace($"Finish MSBuild {sw.Elapsed.TotalMilliseconds}ms"); if (result.OverallResult == BuildResultCode.Failure) { throw result.Exception ?? new InvalidOperationException("Error during project compilation"); } return(compilationHost.Compile(cancellationToken)); }
protected async Task <ProjectInstance> BuildAsync(string taskName, MSB.Framework.ITaskHost taskHost, CancellationToken cancellationToken) { // prepare for building var buildTargets = new BuildTargets(_loadedProject, "Compile"); // don't execute anything after CoreCompile target, since we've // already done everything we need to compute compiler inputs by then. buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: false); // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. var executedProject = _loadedProject.CreateProjectInstance(); if (!executedProject.Targets.ContainsKey("Compile")) { return(executedProject); } var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(_loadedProject.FullPath, "CoreCompile", taskName, taskHost); var buildParameters = new MSB.Execution.BuildParameters(_loadedProject.ProjectCollection); var buildRequestData = new MSB.Execution.BuildRequestData(executedProject, buildTargets.Targets, hostServices); var result = await this.BuildAsync(buildParameters, buildRequestData, cancellationToken).ConfigureAwait(continueOnCapturedContext: false); if (result.Exception != null) { throw result.Exception; } return(executedProject); }
public void TestInvalidHostObjectRegistration_NullTask() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.RegisterHostObject("project", "target", null, hostObject); }
public void CloneTargets() { var hostServices = new HostServices(); ProjectInstance first = GetSampleProjectInstance(hostServices); ProjectInstance second = first.DeepCopy(); // Targets, tasks are immutable so we can expect the same objects Assert.True(Object.ReferenceEquals(first.Targets, second.Targets)); Assert.True(Object.ReferenceEquals(first.Targets["t"], second.Targets["t"])); var firstTasks = first.Targets["t"]; var secondTasks = second.Targets["t"]; Assert.True(Object.ReferenceEquals(firstTasks.Children[0], secondTasks.Children[0])); }
public void TestUnregisteringNonConflictingHostObjectRestoresOriginalAffinity() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.SetNodeAffinity(String.Empty, NodeAffinity.OutOfProc); hostServices.SetNodeAffinity("project", NodeAffinity.Any); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project2")); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); hostServices.RegisterHostObject("project", "target", "task", hostObject); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project")); hostServices.RegisterHostObject("project", "target", "task", null); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project2")); }
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) { throw new NotImplementedException(); }
public void TestDefaultAffinityWhenProjectNotRegistered() { HostServices hostServices = new HostServices(); hostServices.SetNodeAffinity("project1", NodeAffinity.InProc); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project2")); }
/// <summary> /// Constructs a GraphBuildRequestData for build requests based on a project graph entry points. /// </summary> /// <param name="projectGraphEntryPoints">The entry points to use in the build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> /// <param name="flags">Flags controlling this build request.</param> public GraphBuildRequestData(IEnumerable <ProjectGraphEntryPoint> projectGraphEntryPoints, ICollection <string> targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(targetsToBuild, hostServices, flags) { ErrorUtilities.VerifyThrowArgumentNull(projectGraphEntryPoints, nameof(projectGraphEntryPoints)); ProjectGraphEntryPoints = projectGraphEntryPoints; }
public static ProjectDetails LoadProjectDetails(BuildEnvironment environment) { var key = Tuple.Create(environment.ProjectFile, environment.Configuration); ProjectDetails details; if (_allProjects.TryGetValue(key, out details)) { if (!details.HasChanged()) { if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { _log.LogDebug($"Using cached project file details for [{environment.ProjectFile}]"); } return(details); } else { if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { _log.LogDebug($"Reloading project file details [{environment.ProjectFile}] as one of its imports has been modified."); } } } if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { _log.LogDebug($"Loading project file [{environment.ProjectFile}]"); } details = new ProjectDetails(); var properties = new Dictionary <string, string>(ImmutableDictionary <string, string> .Empty) { ["DesignTimeBuild"] = "true", // this will tell msbuild to not build the dependent projects ["BuildingInsideVisualStudio"] = "true", // this will force CoreCompile task to execute even if all inputs and outputs are up to date ["BuildingInsideUnoSourceGenerator"] = "true", // this will force prevent the task to run recursively ["Configuration"] = environment.Configuration, ["UseHostCompilerIfAvailable"] = "true", ["UseSharedCompilation"] = "true", ["VisualStudioVersion"] = environment.VisualStudioVersion, // Force the intermediate path to be different from the VS default path // so that the generated files don't mess up the file count for incremental builds. ["IntermediateOutputPath"] = Path.Combine(environment.OutputPath, "obj") + Path.DirectorySeparatorChar }; // Target framework is required for the MSBuild 15.0 Cross Compilation. // Loading a project without the target framework results in an empty project, which interatively // sets the TargetFramework property. if (environment.TargetFramework.HasValue()) { properties["TargetFramework"] = environment.TargetFramework; } // TargetFrameworkRootPath is used by VS4Mac to determine the // location of frameworks like Xamarin.iOS. if (environment.TargetFrameworkRootPath.HasValue()) { properties["TargetFrameworkRootPath"] = environment.TargetFrameworkRootPath; } // Platform is intentionally kept as not defined, to avoid having // dependent projects being loaded with a platform they don't support. // properties["Platform"] = _platform; var xmlReader = XmlReader.Create(environment.ProjectFile); var collection = new Microsoft.Build.Evaluation.ProjectCollection(); // Change this logger details to troubleshoot project loading details. collection.RegisterLogger(new Microsoft.Build.Logging.ConsoleLogger() { Verbosity = LoggerVerbosity.Minimal }); // Uncomment this to enable file logging for debugging purposes. // collection.RegisterLogger(new Microsoft.Build.BuildEngine.FileLogger() { Verbosity = LoggerVerbosity.Diagnostic, Parameters = $@"logfile=c:\temp\build\MSBuild.{Guid.NewGuid()}.log" }); collection.OnlyLogCriticalEvents = false; var xml = Microsoft.Build.Construction.ProjectRootElement.Create(xmlReader, collection); // When constructing a project from an XmlReader, MSBuild cannot determine the project file path. Setting the // path explicitly is necessary so that the reserved properties like $(MSBuildProjectDirectory) will work. xml.FullPath = Path.GetFullPath(environment.ProjectFile); var loadedProject = new Microsoft.Build.Evaluation.Project( xml, properties, toolsVersion: null, projectCollection: collection ); var buildTargets = new BuildTargets(loadedProject, "Compile"); // don't execute anything after CoreCompile target, since we've // already done everything we need to compute compiler inputs by then. buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: true); details.Configuration = environment.Configuration; details.LoadedProject = loadedProject; // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. details.ExecutedProject = loadedProject.CreateProjectInstance(); var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(loadedProject.FullPath, "CoreCompile", "Csc", null); var buildParameters = new Microsoft.Build.Execution.BuildParameters(loadedProject.ProjectCollection); // This allows for the loggers to buildParameters.Loggers = collection.Loggers; var buildRequestData = new Microsoft.Build.Execution.BuildRequestData(details.ExecutedProject, buildTargets.Targets, hostServices); var result = BuildAsync(buildParameters, buildRequestData); if (result.Exception == null) { ValidateOutputPath(details.ExecutedProject); var projectFilePath = Path.GetFullPath(Path.GetDirectoryName(environment.ProjectFile)); details.References = details.ExecutedProject.GetItems("ReferencePath").Select(r => r.EvaluatedInclude).ToArray(); if (!details.References.Any()) { if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) { _log.LogError($"Project has no references."); } LogFailedTargets(environment.ProjectFile, result); details.Generators = new (Type, Func <SourceGenerator>)[0];
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices) : this (projectInstance, targetsToBuild, hostServices, BuildRequestDataFlags.None) { }
/// <summary> /// Constructs a GraphBuildRequestData for build requests based on a project graph entry points. /// </summary> /// <param name="projectGraphEntryPoint">The entry point to use in the build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> public GraphBuildRequestData(ProjectGraphEntryPoint projectGraphEntryPoint, ICollection <string> targetsToBuild, HostServices hostServices) : this(projectGraphEntryPoint.AsEnumerable(), targetsToBuild, hostServices, BuildRequestDataFlags.None) { }
public static ProjectDetails LoadProjectDetails(string projectFile, string configuration) { var key = Tuple.Create(projectFile, configuration); ProjectDetails details; if (_allProjects.TryGetValue(key, out details)) { if (!details.HasChanged()) { if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { _log.Debug($"Using cached project file details for [{projectFile}]"); } return(details); } else { if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { _log.Debug($"Reloading project file details [{projectFile}] as one of its imports has been modified."); } } } if (_log.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { _log.Debug($"Loading project file [{projectFile}]"); } details = new ProjectDetails(); var properties = new Dictionary <string, string>(ImmutableDictionary <string, string> .Empty); properties["DesignTimeBuild"] = "true"; // this will tell msbuild to not build the dependent projects properties["BuildingInsideVisualStudio"] = "true"; // this will force CoreCompile task to execute even if all inputs and outputs are up to date properties["BuildingInsideUnoSourceGenerator"] = "true"; // this will force prevent the task to run recursively properties["Configuration"] = configuration; properties["UseHostCompilerIfAvailable"] = "true"; properties["UseSharedCompilation"] = "true"; // Platform is intentionally kept as not defined, to avoid having // dependent projects being loaded with a platform they don't support. // properties["Platform"] = _platform; var xmlReader = XmlReader.Create(projectFile); var collection = new Microsoft.Build.Evaluation.ProjectCollection(); collection.RegisterLogger(new Microsoft.Build.Logging.ConsoleLogger() { Verbosity = LoggerVerbosity.Normal }); collection.OnlyLogCriticalEvents = false; var xml = Microsoft.Build.Construction.ProjectRootElement.Create(xmlReader, collection); // When constructing a project from an XmlReader, MSBuild cannot determine the project file path. Setting the // path explicitly is necessary so that the reserved properties like $(MSBuildProjectDirectory) will work. xml.FullPath = Path.GetFullPath(projectFile); var loadedProject = new Microsoft.Build.Evaluation.Project( xml, properties, toolsVersion: null, projectCollection: collection ); var buildTargets = new BuildTargets(loadedProject, "Compile"); // don't execute anything after CoreCompile target, since we've // already done everything we need to compute compiler inputs by then. buildTargets.RemoveAfter("CoreCompile", includeTargetInRemoval: false); details.Configuration = configuration; details.LoadedProject = loadedProject; // create a project instance to be executed by build engine. // The executed project will hold the final model of the project after execution via msbuild. details.ExecutedProject = loadedProject.CreateProjectInstance(); var hostServices = new Microsoft.Build.Execution.HostServices(); // connect the host "callback" object with the host services, so we get called back with the exact inputs to the compiler task. hostServices.RegisterHostObject(loadedProject.FullPath, "CoreCompile", "Csc", null); var buildParameters = new Microsoft.Build.Execution.BuildParameters(loadedProject.ProjectCollection); // This allows for the loggers to buildParameters.Loggers = collection.Loggers; var buildRequestData = new Microsoft.Build.Execution.BuildRequestData(details.ExecutedProject, buildTargets.Targets, hostServices); var result = BuildAsync(buildParameters, buildRequestData); if (result.Exception == null) { ValidateOutputPath(details.ExecutedProject); var projectFilePath = Path.GetFullPath(Path.GetDirectoryName(projectFile)); details.References = details.ExecutedProject.GetItems("ReferencePath").Select(r => r.EvaluatedInclude).ToArray(); if (details.References.None()) { LogFailedTargets(projectFile, result); return(details); } } else { LogFailedTargets(projectFile, result); } _allProjects.TryAdd(key, details); details.BuildImportsMap(); return(details); }
/// <summary> /// Constructs a GraphBuildRequestData for build requests based on project files. /// </summary> /// <param name="projectFullPath">The full path to the project file.</param> /// <param name="globalProperties">The global properties which should be used during evaluation of the project. Cannot be null.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use. May be null.</param> /// <param name="flags">The <see cref="BuildRequestDataFlags"/> to use.</param> public GraphBuildRequestData(string projectFullPath, IDictionary <string, string> globalProperties, ICollection <string> targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(new ProjectGraphEntryPoint(projectFullPath, globalProperties).AsEnumerable(), targetsToBuild, hostServices, flags) { }
/// <summary> /// Constructs a GraphBuildRequestData for build requests based on a project graph. /// </summary> /// <param name="projectGraph">The graph to build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> /// <param name="flags">Flags controlling this build request.</param> public GraphBuildRequestData(ProjectGraph projectGraph, ICollection <string> targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(targetsToBuild, hostServices, flags) { ErrorUtilities.VerifyThrowArgumentNull(projectGraph, nameof(projectGraph)); ProjectGraph = projectGraph; }
/// <summary> /// Constructs a GraphBuildRequestData for build requests based on a project graph. /// </summary> /// <param name="projectGraph">The graph to build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> public GraphBuildRequestData(ProjectGraph projectGraph, ICollection <string> targetsToBuild, HostServices hostServices) : this(projectGraph, targetsToBuild, hostServices, BuildRequestDataFlags.None) { }
/// <summary> /// Create a ProjectInstance from provided project content and host services object /// </summary> private static ProjectInstance GetProjectInstance(string content, HostServices hostServices, IDictionary<string, string> globalProperties, ProjectCollection projectCollection, string toolsVersion = null) { XmlReader reader = XmlReader.Create(new StringReader(content)); if (globalProperties == null) { // choose some interesting defaults if we weren't explicitly asked to use a set. globalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); globalProperties.Add("g1", "v1"); globalProperties.Add("g2", "v2"); } Project project = new Project(reader, globalProperties, toolsVersion ?? "4.0", projectCollection ?? ProjectCollection.GlobalProjectCollection); ProjectInstance instance = project.CreateProjectInstance(); return instance; }
public void TestClearingAffinities() { HostServices hostServices = new HostServices(); hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity(null, NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity(String.Empty, NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity(null, NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); }
/// <summary> /// Create a ProjectInstance with some items and properties and targets /// </summary> private static ProjectInstance GetSampleProjectInstance(HostServices hostServices, IDictionary<string, string> globalProperties, ProjectCollection projectCollection, string toolsVersion = null) { string toolsVersionSubstring = toolsVersion != null ? "ToolsVersion=\"" + toolsVersion + "\" " : String.Empty; string content = @" <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' InitialTargets='it' DefaultTargets='dt' " + toolsVersionSubstring + @"> <PropertyGroup> <p1>v1</p1> <p2>v2</p2> <p2>$(p2)X$(p)</p2> </PropertyGroup> <ItemGroup> <i Include='i0'/> <i Include='i1'> <m>m1</m> </i> <i Include='$(p1)'/> </ItemGroup> <Target Name='t'> <t1 a='a1' b='b1' ContinueOnError='coe' Condition='c'/> <t2/> </Target> <Target Name='tt'/> </Project> "; ProjectInstance p = GetProjectInstance(content, hostServices, globalProperties, projectCollection, toolsVersion); return p; }
public void TestContraditcoryHostObjectCausesException_OutOfProc() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc); hostServices.RegisterHostObject("project", "target", "task", hostObject); }
public BuildRequestData(string projectFullPath, IDictionary <string, string> globalProperties, string toolsVersion, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(new ProjectInstance(projectFullPath, globalProperties, toolsVersion), targetsToBuild, hostServices, flags) { ExplicitlySpecifiedToolsVersion = toolsVersion; }
public void TestNonContraditcoryHostObjectAllowed_InProc() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.SetNodeAffinity("project", NodeAffinity.InProc); hostServices.RegisterHostObject("project", "target", "task", hostObject); }
public void TestOverrideGeneralAffinityRegistration() { HostServices hostServices = new HostServices(); hostServices.SetNodeAffinity(String.Empty, NodeAffinity.InProc); hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project")); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project2")); }
public BuildRequestData(string projectFullPath, IDictionary <string, string> globalProperties, string toolsVersion, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) { throw new NotImplementedException(); }
public void TestContradictoryAffinityCausesException_Any() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.RegisterHostObject("project", "target", "task", hostObject); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity("project", NodeAffinity.Any); }
/// <summary> /// Constructs a BuildRequestData for build requests based on project instances. /// </summary> /// <param name="projectInstance">The instance to build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> /// <param name="flags">Flags controlling this build request.</param> public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(projectInstance, targetsToBuild, hostServices, flags, null) { }
public void TestNonContraditcoryHostObjectAllowed_Any() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.SetNodeAffinity("project", NodeAffinity.Any); hostServices.RegisterHostObject("project", "target", "task", hostObject); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project")); }
/// <summary> /// Constructs a BuildRequestData for build requests based on project instances. /// </summary> /// <param name="projectInstance">The instance to build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> /// <param name="flags">Flags controlling this build request.</param> /// <param name="propertiesToTransfer">The list of properties whose values should be transferred from the project to any out-of-proc node.</param> public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags, IEnumerable <string> propertiesToTransfer) : this(targetsToBuild, hostServices, flags) { ErrorUtilities.VerifyThrowArgumentNull(projectInstance, nameof(projectInstance)); foreach (string targetName in targetsToBuild) { ErrorUtilities.VerifyThrowArgumentNull(targetName, "target"); } ProjectInstance = projectInstance; ProjectFullPath = projectInstance.FullPath; GlobalPropertiesDictionary = projectInstance.GlobalPropertiesDictionary; ExplicitlySpecifiedToolsVersion = projectInstance.ExplicitToolsVersion; if (propertiesToTransfer != null) { PropertiesToTransfer = new List <string>(propertiesToTransfer); } }
public void TestAffinityChangeAfterClearingHostObject() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.RegisterHostObject("project", "target", "task", hostObject); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project")); hostServices.RegisterHostObject("project", "target", "task", null); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project")); }
/// <summary> /// Constructs a BuildRequestData for build requests based on project instances. /// </summary> /// <param name="projectInstance">The instance to build.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use, if any. May be null.</param> /// <param name="flags">Flags controlling this build request.</param> /// <param name="propertiesToTransfer">The list of properties whose values should be transferred from the project to any out-of-proc node.</param> /// <param name="requestedProjectState">A <see cref="Execution.RequestedProjectState"/> describing properties, items, and metadata that should be returned. Requires setting <see cref="BuildRequestDataFlags.ProvideSubsetOfStateAfterBuild"/>.</param> public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags, IEnumerable <string> propertiesToTransfer, RequestedProjectState requestedProjectState) : this(projectInstance, targetsToBuild, hostServices, flags, propertiesToTransfer) { ErrorUtilities.VerifyThrowArgumentNull(requestedProjectState, nameof(requestedProjectState)); RequestedProjectState = requestedProjectState; }
public void TestProjectInstanceWithNonConflictingHostServices() { HostServices hostServices = new HostServices(); ProjectInstance project = CreateDummyProject("foo.proj"); BuildRequestData data = new BuildRequestData(project, new string[] { }, hostServices); hostServices.SetNodeAffinity(project.FullPath, NodeAffinity.InProc); BuildRequestData data2 = new BuildRequestData(project, new string[] { }, hostServices); }
/// <summary> /// Constructs a BuildRequestData for build requests based on project files. /// </summary> /// <param name="projectFullPath">The full path to the project file.</param> /// <param name="globalProperties">The global properties which should be used during evaluation of the project. Cannot be null.</param> /// <param name="toolsVersion">The tools version to use for the build. May be null.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use. May be null.</param> public BuildRequestData(string projectFullPath, IDictionary <string, string> globalProperties, string toolsVersion, string[] targetsToBuild, HostServices hostServices) : this(projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, BuildRequestDataFlags.None) { }
public void UnloadedProjectDiscardsHostServices() { HostServices hostServices = new HostServices(); TestHostObject th = new TestHostObject(); ProjectCollection.GlobalProjectCollection.HostServices = hostServices; Project project1 = LoadDummyProject("foo.proj"); Project project2 = LoadDummyProject("foo.proj"); hostServices.RegisterHostObject(project1.FullPath, "test", "Message", th); ProjectCollection.GlobalProjectCollection.UnloadProject(project1); Assert.IsTrue(hostServices.HasHostObject(project2.FullPath)); ProjectCollection.GlobalProjectCollection.UnloadProject(project2); Assert.IsFalse(hostServices.HasHostObject(project2.FullPath)); }
/// <summary> /// Constructs a BuildRequestData for build requests based on project files. /// </summary> /// <param name="projectFullPath">The full path to the project file.</param> /// <param name="globalProperties">The global properties which should be used during evaluation of the project. Cannot be null.</param> /// <param name="toolsVersion">The tools version to use for the build. May be null.</param> /// <param name="targetsToBuild">The targets to build.</param> /// <param name="hostServices">The host services to use. May be null.</param> /// <param name="flags">The <see cref="BuildRequestDataFlags"/> to use.</param> public BuildRequestData(string projectFullPath, IDictionary <string, string> globalProperties, string toolsVersion, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this(targetsToBuild, hostServices, flags) { ErrorUtilities.VerifyThrowArgumentLength(projectFullPath, nameof(projectFullPath)); ErrorUtilities.VerifyThrowArgumentNull(globalProperties, nameof(globalProperties)); ProjectFullPath = FileUtilities.NormalizePath(projectFullPath); TargetNames = (ICollection <string>)targetsToBuild.Clone(); GlobalPropertiesDictionary = new PropertyDictionary <ProjectPropertyInstance>(globalProperties.Count); foreach (KeyValuePair <string, string> propertyPair in globalProperties) { GlobalPropertiesDictionary.Set(ProjectPropertyInstance.Create(propertyPair.Key, propertyPair.Value)); } ExplicitlySpecifiedToolsVersion = toolsVersion; }
public void TestUnregisterHostObject() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.RegisterHostObject("project", "target", "task", hostObject); Assert.AreSame(hostObject, hostServices.GetHostObject("project", "target", "task")); hostServices.RegisterHostObject("project", "target", "task", null); Assert.IsNull(hostServices.GetHostObject("project", "target", "task")); }
/// <summary> /// Copy constructor /// </summary> private BuildParameters(BuildParameters other) { ErrorUtilities.VerifyThrowInternalNull(other, "other"); _buildId = other._buildId; _culture = other._culture; _defaultToolsVersion = other._defaultToolsVersion; _enableNodeReuse = other._enableNodeReuse; _buildProcessEnvironment = other._buildProcessEnvironment != null ? new Dictionary<string, string>(other._buildProcessEnvironment) : null; _environmentProperties = other._environmentProperties != null ? new PropertyDictionary<ProjectPropertyInstance>(other._environmentProperties) : null; _forwardingLoggers = other._forwardingLoggers != null ? new List<ForwardingLoggerRecord>(other._forwardingLoggers) : null; _globalProperties = other._globalProperties != null ? new PropertyDictionary<ProjectPropertyInstance>(other._globalProperties) : null; _hostServices = other._hostServices; _loggers = other._loggers != null ? new List<ILogger>(other._loggers) : null; _maxNodeCount = other._maxNodeCount; _memoryUseLimit = other._memoryUseLimit; _nodeExeLocation = other._nodeExeLocation; _nodeId = other._nodeId; _onlyLogCriticalEvents = other._onlyLogCriticalEvents; _buildThreadPriority = other._buildThreadPriority; _toolsetProvider = other._toolsetProvider; _toolsetDefinitionLocations = other._toolsetDefinitionLocations; _toolsetProvider = other._toolsetProvider; _uiCulture = other._uiCulture; _detailedSummary = other._detailedSummary; _shutdownInProcNodeOnBuildFinish = other._shutdownInProcNodeOnBuildFinish; this.ProjectRootElementCache = other.ProjectRootElementCache; this.ResetCaches = other.ResetCaches; this.LegacyThreadingSemantics = other.LegacyThreadingSemantics; _saveOperatingEnvironment = other._saveOperatingEnvironment; _useSynchronousLogging = other._useSynchronousLogging; _disableInProcNode = other._disableInProcNode; _logTaskInputs = other._logTaskInputs; _logInitialPropertiesAndItems = other._logInitialPropertiesAndItems; }
/// <summary> /// Create a ProjectInstance from provided project content and host services object /// </summary> private static ProjectInstance GetProjectInstance(string content, HostServices hostServices) { return GetProjectInstance(content, hostServices, null, null); }
public BuildRequestData (string projectFullPath, IDictionary<string, string> globalProperties, string toolsVersion, string[] targetsToBuild, HostServices hostServices) : this (projectFullPath, globalProperties, toolsVersion, targetsToBuild, hostServices, BuildRequestDataFlags.None) { }
/// <summary> /// Create a ProjectInstance with some items and properties and targets /// </summary> private static ProjectInstance GetSampleProjectInstance(HostServices hostServices) { return GetSampleProjectInstance(hostServices, null, null); }
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) { if (targetsToBuild == null) { throw new ArgumentNullException("targetsToBuild"); } ProjectInstance = projectInstance; TargetNames = targetsToBuild; HostServices = hostServices; Flags = flags; }
/// <summary> /// Creates a build request. /// </summary> private BuildRequest CreateBuildRequest(int nodeRequestId, int configId, string[] targets, NodeAffinity nodeAffinity, BuildRequest parentRequest) { HostServices hostServices = null; if (nodeAffinity != NodeAffinity.Any) { hostServices = new HostServices(); hostServices.SetNodeAffinity(String.Empty, nodeAffinity); } BuildRequest request = new BuildRequest(1 /* submissionId */, nodeRequestId, configId, targets, hostServices, BuildEventContext.Invalid, parentRequest); return request; }
public void TestSpecificAffinityRegistration() { HostServices hostServices = new HostServices(); hostServices.SetNodeAffinity("project", NodeAffinity.InProc); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity("project", NodeAffinity.OutOfProc); Assert.AreEqual(NodeAffinity.OutOfProc, hostServices.GetNodeAffinity("project")); hostServices.SetNodeAffinity("project", NodeAffinity.Any); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); }
public void TestAffinityDefaultsToAny() { HostServices hostServices = new HostServices(); Assert.AreEqual(NodeAffinity.Any, hostServices.GetNodeAffinity("project")); }
public BuildRequestData(ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) { ProjectInstance = projectInstance; TargetNames = targetsToBuild; HostServices = hostServices; Flags = flags; }
public BuildRequestData (string projectFullPath, IDictionary<string, string> globalProperties, string toolsVersion, string[] targetsToBuild, HostServices hostServices, BuildRequestDataFlags flags) : this (new ProjectInstance (projectFullPath, globalProperties, toolsVersion), targetsToBuild, hostServices, flags) { ExplicitlySpecifiedToolsVersion = toolsVersion; }
public void TestHostObjectCausesInProcAffinity() { HostServices hostServices = new HostServices(); TestHostObject hostObject = new TestHostObject(); hostServices.RegisterHostObject("project", "target", "task", hostObject); Assert.AreEqual(NodeAffinity.InProc, hostServices.GetNodeAffinity("project")); }