bool Run (BuildTask buildTask, out bool executeOnErrors) { executeOnErrors = false; // Run the task in batches bool retval = true; if (buckets.Count == 0) { // batched mode, but no values in the corresponding items! if (ConditionParser.ParseAndEvaluate (buildTask.Condition, project)) { retval = buildTask.Execute (); if (!retval && !buildTask.ContinueOnError) executeOnErrors = true; } return retval; } // batched foreach (Dictionary<string, BuildItemGroup> bucket in buckets) { project.PushBatch (bucket, commonItemsByName); try { if (ConditionParser.ParseAndEvaluate (buildTask.Condition, project)) { retval = buildTask.Execute (); if (!retval && !buildTask.ContinueOnError) { executeOnErrors = true; break; } } } finally { project.PopBatch (); } } return retval; }
public bool Build (BuildTask buildTask, out bool executeOnErrors) { executeOnErrors = false; try { Init (); // populate list of referenced items and metadata ParseTaskAttributes (buildTask); if (consumedMetadataReferences.Count == 0) { // No batching required if (ConditionParser.ParseAndEvaluate (buildTask.Condition, project)) return buildTask.Execute (); else // skipped, it should be logged return true; } BatchAndPrepareBuckets (); return Run (buildTask, out executeOnErrors); } finally { consumedItemsByName = null; consumedMetadataReferences = null; consumedQMetadataReferences = null; consumedUQMetadataReferences = null; batchedItemsByName = null; commonItemsByName = null; } }
public TaskDefinition(BuildTask task, PSWithReturnValueToken varToken) { this.task = task; scriptUseToken = asNodeWithOptions(varToken); task.SetParameterValue("Capture", scriptUseToken["Capture"]); var kvSerializer = (KeyValueSerializer)scriptUseToken.Where(kv => kv.Key != "Capture") .ToDictionary(kv => kv.Key, kv => kv.Value); if (!string.IsNullOrEmpty(kvSerializer.ToString())) task.SetParameterValue("CommandParameters", kvSerializer.ToString()); task.SetParameterValue("ReturnValueType", varToken.ValueType.ToString()); if (varToken.ValueType.Equals(PSScriptReturnValueType.ItemGroup)) task.AddOutputItem("ScriptItemOutput", varToken.VariableName); if (varToken.ValueType.Equals(PSScriptReturnValueType.Property)) task.AddOutputProperty("ScriptPropOutput", varToken.VariableName); }
/// <summary> /// Removes the specified BuildTask from the target. This method correctly updates /// the project's XML content, so the task will no longer show up when the project /// is saved out. /// </summary> /// <param name="taskElement"></param> public void RemoveTask ( BuildTask taskElement ) { // Confirm that it's not an imported target. error.VerifyThrowInvalidOperation(!this.IsImported, "CannotModifyImportedProjects"); error.VerifyThrow(this.taskElementList != null, "Arraylist not initialized!"); error.VerifyThrowArgumentNull(taskElement, "taskElement"); // Confirm that the BuildTask belongs to this Target. error.VerifyThrowInvalidOperation(taskElement.ParentTarget == this, "IncorrectObjectAssociation", "BuildTask", "Target"); // Remove the BuildTask from our list. this.taskElementList.Remove(taskElement); // Remove the task's XML from the project document. this.targetElement.RemoveChild(taskElement.TaskXmlElement); // Dissociate the BuildTask from this target. taskElement.ParentTarget = null; this.MarkTargetAsDirty(); }
/// <summary> /// Adds a task with the specified name to the end of this target. This method /// does all of the work to manipulate the project's XML content. /// </summary> /// <param name="taskName"></param> public BuildTask AddNewTask ( string taskName ) { error.VerifyThrow(this.taskElementList != null, "Arraylist not initialized!"); error.VerifyThrowArgumentLength(taskName, "taskName"); // Confirm that it's not an imported target. error.VerifyThrowInvalidOperation(!this.IsImported, "CannotModifyImportedProjects"); // Create the XML for the new task node and append it to the very end of the <Target> element. XmlElement newTaskElement = this.targetElement.OwnerDocument.CreateElement(taskName, XMakeAttributes.defaultXmlNamespace); this.targetElement.AppendChild(newTaskElement); // Create a new BuildTask object, and add it to our list. BuildTask newTask = new BuildTask(newTaskElement, this, false); this.taskElementList.Add(newTask); this.MarkTargetAsDirty(); return newTask; }
/// <summary> /// Adds a new VCBuild task element to the specified target /// </summary> /// <param name="target">The target to add the VCBuild task to</param> /// <param name="solutionPath">Path to the solution if any</param> /// <param name="projectPath">Path to the solution if any</param> /// <param name="vcbuildTargetName">The VCBuild target name</param> /// <param name="platformName">The platform parameter to VCBuild</param> /// <param name="fullConfigurationName">Configuration property value</param> /// <returns></returns> static internal BuildTask AddVCBuildTaskElement ( Project msbuildProject, Target target, string solutionPath, string projectPath, string vcbuildTargetName, string platformName, string fullConfigurationName ) { // The VCBuild task (which we already shipped) has a bug - it cannot // find vcbuild.exe when running in MSBuild 64 bit unless it's on the path. // So, pass it here, unless some explicit path was passed. // Note, we have to do this even if we're in a 32 bit MSBuild, because we save the .sln.cache // file, and the next build of the solution could be a 64 bit MSBuild. if (VCBuildLocationHint != null) // Should only be null if vcbuild truly isn't installed; in that case, let the task log its error { BuildTask createProperty = target.AddNewTask("CreateProperty"); createProperty.SetParameterValue("Value", VCBuildLocationHint); createProperty.Condition = "'$(VCBuildToolPath)' == ''"; createProperty.AddOutputProperty("Value", "VCBuildToolPath"); } BuildTask newTask = target.AddNewTask("VCBuild"); newTask.SetParameterValue("Projects", projectPath, true /* treat as literal */); // Add the toolpath so that the user can override if necessary newTask.SetParameterValue("ToolPath", "$(VCBuildToolPath)"); newTask.SetParameterValue("Configuration", fullConfigurationName); if (!string.IsNullOrEmpty(platformName)) { newTask.SetParameterValue("Platform", platformName); } newTask.SetParameterValue("SolutionFile", solutionPath); if ((vcbuildTargetName != null) && (vcbuildTargetName.Length > 0)) { newTask.SetParameterValue(vcbuildTargetName, "true"); } // Add the override switch so that the user can supply one if necessary newTask.SetParameterValue("Override", "$(VCBuildOverride)"); // Add any additional lib paths newTask.SetParameterValue("AdditionalLibPaths", "$(VCBuildAdditionalLibPaths)"); // Only use new properties if we're not emitting a 2.0 project if (!String.Equals(msbuildProject.ToolsVersion, "2.0", StringComparison.OrdinalIgnoreCase)) { // Add any additional link library paths newTask.SetParameterValue("AdditionalLinkLibraryPaths", "$(VCBuildAdditionalLinkLibraryPaths)"); // Add the useenv switch so that the user can supply one if necessary // Note: "VCBuildUserEnvironment" is included for backwards-compatibility; the correct // property name is "VCBuildUseEnvironment" to match the task parameter. When the old name is // used the task will emit a warning. newTask.SetParameterValue("UseEnvironment", "$(VCBuildUseEnvironment)"); } newTask.SetParameterValue("UserEnvironment", "$(VCBuildUserEnvironment)"); // Add the additional options switches newTask.SetParameterValue("AdditionalOptions", "$(VCBuildAdditionalOptions)"); return(newTask); }
// Parse task attributes to get list of referenced metadata and items // to determine batching // void ParseTaskAttributes (BuildTask buildTask) { foreach (XmlAttribute attrib in buildTask.TaskElement.Attributes) ParseAttribute (attrib.Value); foreach (XmlNode xn in buildTask.TaskElement.ChildNodes) { XmlElement xe = xn as XmlElement; if (xe == null) continue; //FIXME: error on any other child if (String.Compare (xe.LocalName, "Output", StringComparison.Ordinal) == 0) { foreach (XmlAttribute attrib in xe.Attributes) ParseAttribute (attrib.Value); } } }
public void AddNewTaskSeveralToDifferentTargets() { project.LoadXml(ProjectContentsSeveralTargets); BuildTask[] task = new BuildTask[3]; Target[] t = new Target[3]; t[0] = GetSpecificTargetFromProject(project, "t1"); task[0] = t[0].AddNewTask("Message"); task[0].SetParameterValue("Text", "t1.task1"); t[1] = GetSpecificTargetFromProject(project, "t2"); task[1] = t[1].AddNewTask("Message"); task[1].SetParameterValue("Text", "t2.task1"); t[2] = GetSpecificTargetFromProject(project, "t3"); task[2] = t[2].AddNewTask("Message"); task[2].SetParameterValue("Text", "t3.task1"); Assertion.AssertEquals(true, project.Build(new string[] { "t1", "t2", "t3" })); Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task1")); Assertion.AssertEquals(true, logger.FullLog.Contains("t2.task1")); Assertion.AssertEquals(true, logger.FullLog.Contains("t3.task1")); }
public TaskDefinition(BuildTask task, TokenWithOptions callToken) { this.task = task; scriptUseToken = callToken; task.SetParameterValue("Capture", callToken["Capture"]); task.SetParameterValue("ReturnValueType", PSScriptReturnValueType.Undefined.ToString()); }
public void AddScriptTask(BuildTask task, PSInlineScriptToken inlineScript) { tasks.Add(new TaskDefinition(task, inlineScript)); }
public void AddScriptTask(BuildTask task, PSScriptCallToken callToken) { tasks.Add(new TaskDefinition(task, callToken)); }
public void AddScriptTask(BuildTask task, PSWithReturnValueToken variableToken) { tasks.Add(new TaskDefinition(task,variableToken)); }
/*/// <summary> /// Gets or sets the default source parameter identifier. /// </summary> /// <value>The default source parameter identifier.</value> public string DefaultSourceParameterIdentifier { get { return this.defaultSourceParameterIdentifier; } set { this.defaultSourceParameterIdentifier = value; } }*/ /// <summary> /// Creates and Adds a new task on a build target. /// </summary> /// <param name="target">The build target.</param> /// <param name="sourceParameterIdentifier">The source parameter identifier used to name the /// ItemGroup with source files.</param> /// <param name="sourceParameter">The source parameter.</param> /// <returns> /// A new task ready to use. /// </returns> public BuildTask CreateNewTaskOnTarget( Target target, string sourceParameterIdentifier, string sourceParameter) { if (target == null) { throw new ArgumentNullException("target"); } // Compose the new task. var batask = target.AddNewTask(this.taskType.FullName); // Set the main source parameter on the build task. //batask.SetParameterValue(sourceParameter, this.DefaultSourceParameterIdentifier); var spi = @"@(" + sourceParameterIdentifier + ")"; batask.SetParameterValue(sourceParameter, spi); // Store for later use with SetParametersOnCreatedTask( ... ). this.composedTask = batask; return batask; }
// FIXME: shouldn't we remove it from XML? public void RemoveTask (BuildTask buildTask) { if (buildTask == null) throw new ArgumentNullException ("buildTask"); buildTasks.Remove (buildTask); }
public TaskDefinition(BuildTask task, PSScriptToken token) { this.task = task; task.SetParameterValue("Script", token.Script); task.SetParameterValue("ReturnValueType", PSScriptReturnValueType.Undefined.ToString()); ScriptIsSet = true; }
public BuildTask AddNewTask (string taskName) { if (taskName == null) throw new ArgumentNullException ("taskName"); XmlElement task = project.XmlDocument.CreateElement (taskName, Project.XmlNamespace); targetElement.AppendChild (task); BuildTask bt = new BuildTask (task, this); buildTasks.Add (bt); return bt; }
public void AddNewTaskSeveralToOneTarget() { project.LoadXml(ProjectContentsOneTarget); Target t = GetSpecificTargetFromProject(project, "t1"); BuildTask[] task = new BuildTask[3]; task[0] = t.AddNewTask("Message"); task[0].SetParameterValue("Text", "t1.task1"); task[1] = t.AddNewTask("Message"); task[1].SetParameterValue("Text", "t1.task2"); task[2] = t.AddNewTask("Message"); task[2].SetParameterValue("Text", "t1.task3"); Assertion.AssertEquals(true, project.Build("t1")); Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task1")); Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task2")); Assertion.AssertEquals(true, logger.FullLog.Contains("t1.task3")); }