2 // ProjectTaskElement.cs
5 // Leszek Ciesielski (skolima@gmail.com)
7 // (C) 2011 Leszek Ciesielski
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections.Generic;
33 using Microsoft.Build.Exceptions;
34 using Microsoft.Build.Internal;
36 namespace Microsoft.Build.Construction
38 [System.Diagnostics.DebuggerDisplayAttribute ("{Name} Condition={Condition} ContinueOnError={ContinueOnError} "
39 + "#Outputs={Count}")]
40 public class ProjectTaskElement : ProjectElementContainer
42 internal ProjectTaskElement (string taskName, ProjectRootElement containingProject)
43 : this(containingProject)
47 internal ProjectTaskElement (ProjectRootElement containingProject)
49 ContainingProject = containingProject;
51 string continueOnError;
52 public string ContinueOnError {
53 get { return continueOnError ?? String.Empty; }
54 set { continueOnError = value; }
57 public string Name { get { return name ?? String.Empty; } private set { name = value; } }
58 public ICollection<ProjectOutputElement> Outputs {
59 get { return new CollectionFromEnumerable<ProjectOutputElement> (
60 new FilteredEnumerable<ProjectOutputElement> (AllChildren)); }
62 public IDictionary<string, string> Parameters {
63 get { return parameters; }
65 public ProjectOutputElement AddOutputItem (string taskParameter, string itemType)
67 return AddOutputItem (taskParameter, itemType, null);
69 public ProjectOutputElement AddOutputItem (string taskParameter, string itemType, string condition)
71 var output = new ProjectOutputElement (taskParameter, itemType, null, ContainingProject);
72 if( condition != null)
73 output.Condition = condition;
77 public ProjectOutputElement AddOutputProperty (string taskParameter, string propertyName)
79 return AddOutputProperty (taskParameter, propertyName, null);
81 public ProjectOutputElement AddOutputProperty (string taskParameter, string propertyName,
84 var output = new ProjectOutputElement (taskParameter, null, propertyName, ContainingProject);
85 if( condition != null)
86 output.Condition = condition;
90 public string GetParameter (string name)
93 if (parameters.TryGetValue (name, out value))
97 public void RemoveAllParameters ()
101 public void RemoveParameter (string name)
103 parameters.Remove (name);
105 public void SetParameter (string name, string unevaluatedValue)
107 parameters[name] = unevaluatedValue;
109 internal override string XmlName {
112 internal override ProjectElement LoadChildElement (XmlReader reader)
114 switch (reader.LocalName) {
116 var output = ContainingProject.CreateOutputElement (null, null, null);
117 AppendChild (output);
120 throw new InvalidProjectFileException (string.Format (
121 "Child \"{0}\" is not a known node type.", reader.LocalName));
124 internal override void LoadAttribute (string name, string value)
127 case "ContinueOnError":
128 ContinueOnError = value;
131 case "ExecuteTargets":
132 ExecuteTargets = value;
134 case "MSBuildArchitecture":
135 MSBuildArchitecture = value;
137 case "MSBuildRuntime":
138 MSBuildRuntime = value;
150 SetParameter (name, value);
154 internal override void SaveValue (XmlWriter writer)
156 SaveAttribute (writer, "ContinueOnError", ContinueOnError);
157 foreach (var parameter in parameters) {
158 SaveAttribute (writer, parameter.Key, parameter.Value);
160 base.SaveValue (writer);
162 private Dictionary<string, string> parameters = new Dictionary<string, string> ();
164 public string ExecuteTargets { get; set; }
166 public ElementLocation ExecuteTargetsLocation { get; set; }
167 public ElementLocation ContinueOnErrorLocation { get; set; }
168 public string MSBuildArchitecture { get; set; }
169 public ElementLocation MSBuildArchitectureLocation { get; set; }
170 public string MSBuildRuntime { get; set; }
171 public ElementLocation MSBuildRuntimeLocation { get; set; }