2 // ProjectCollection.cs
5 // Leszek Ciesielski (skolima@gmail.com)
6 // Rolf Bjarne Kvinge (rolf@xamarin.com)
7 // Atsushi Enomoto (atsushi@xamarin.com)
9 // (C) 2011 Leszek Ciesielski
10 // Copyright (C) 2011,2013 Xamarin Inc.
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using Microsoft.Build.Construction;
33 using Microsoft.Build.Execution;
34 using Microsoft.Build.Framework;
35 using Microsoft.Build.Logging;
36 using Microsoft.Build.Utilities;
38 using System.Collections.Generic;
39 using System.Collections.ObjectModel;
43 namespace Microsoft.Build.Evaluation
45 public class ProjectCollection : IDisposable
47 public delegate void ProjectAddedEventHandler (object target, ProjectAddedToProjectCollectionEventArgs args);
49 public class ProjectAddedToProjectCollectionEventArgs : EventArgs
51 public ProjectAddedToProjectCollectionEventArgs (ProjectRootElement project)
54 throw new ArgumentNullException ("project");
55 ProjectRootElement = project;
58 public ProjectRootElement ProjectRootElement { get; private set; }
63 static readonly ProjectCollection global_project_collection;
65 static ProjectCollection ()
68 global_project_collection = new ProjectCollection (new ReadOnlyDictionary<string, string> (new Dictionary<string, string> ()));
70 global_project_collection = new ProjectCollection (new Dictionary<string, string> ());
74 public static string Escape (string unescapedString)
76 return Mono.XBuild.Utilities.MSBuildUtils.Escape (unescapedString);
79 public static string Unescape (string scapedString)
81 throw new NotImplementedException ();
84 public static ProjectCollection GlobalProjectCollection {
85 get { return global_project_collection; }
88 // semantic model part
90 public ProjectCollection ()
95 public ProjectCollection (IDictionary<string, string> globalProperties)
96 : this (globalProperties, null, ToolsetDefinitionLocations.Registry | ToolsetDefinitionLocations.ConfigurationFile)
100 public ProjectCollection (ToolsetDefinitionLocations toolsetDefinitionLocations)
101 : this (null, null, toolsetDefinitionLocations)
105 public ProjectCollection (IDictionary<string, string> globalProperties, IEnumerable<ILogger> loggers,
106 ToolsetDefinitionLocations toolsetDefinitionLocations)
107 : this (globalProperties, loggers, null, toolsetDefinitionLocations, int.MaxValue, false)
111 public ProjectCollection (IDictionary<string, string> globalProperties,
112 IEnumerable<ILogger> loggers, IEnumerable<ForwardingLoggerRecord> remoteLoggers,
113 ToolsetDefinitionLocations toolsetDefinitionLocations,
114 int maxNodeCount, bool onlyLogCriticalEvents)
116 global_properties = globalProperties ?? new Dictionary<string, string> ();
117 this.loggers = loggers != null ? loggers.ToList () : new List<ILogger> ();
118 toolset_locations = toolsetDefinitionLocations;
119 max_node_count = maxNodeCount;
120 OnlyLogCriticalEvents = onlyLogCriticalEvents;
122 LoadDefaultToolsets ();
125 [MonoTODO ("not fired yet")]
126 public event ProjectAddedEventHandler ProjectAdded;
127 [MonoTODO ("not fired yet")]
128 public event EventHandler<ProjectChangedEventArgs> ProjectChanged;
129 [MonoTODO ("not fired yet")]
130 public event EventHandler<ProjectCollectionChangedEventArgs> ProjectCollectionChanged;
131 [MonoTODO ("not fired yet")]
132 public event EventHandler<ProjectXmlChangedEventArgs> ProjectXmlChanged;
134 readonly int max_node_count;
138 get { return loaded_projects.Count; }
142 public string DefaultToolsVersion {
143 get { return Toolsets.Any () ? Toolsets.First ().ToolsVersion : null; }
146 public void Dispose ()
149 GC.SuppressFinalize (this);
152 protected virtual void Dispose (bool disposing)
158 public ICollection<Project> GetLoadedProjects (string fullPath)
160 return LoadedProjects.Where (p => Path.GetFullPath (p.FullPath) == Path.GetFullPath (fullPath)).ToList ();
163 readonly IDictionary<string, string> global_properties;
165 public IDictionary<string, string> GlobalProperties {
166 get { return global_properties; }
169 readonly List<Project> loaded_projects = new List<Project> ();
172 public ICollection<Project> LoadedProjects {
173 get { return loaded_projects; }
176 readonly List<ILogger> loggers = new List<ILogger> ();
178 public ICollection<ILogger> Loggers {
179 get { return loggers; }
183 public bool OnlyLogCriticalEvents { get; set; }
186 public bool SkipEvaluation { get; set; }
188 readonly ToolsetDefinitionLocations toolset_locations;
189 public ToolsetDefinitionLocations ToolsetLocations {
190 get { return toolset_locations; }
193 readonly List<Toolset> toolsets = new List<Toolset> ();
194 [MonoTODO ("unused")]
195 // so what should we do without ToolLocationHelper in Microsoft.Build.Utilities.dll? There is no reference to it in this dll.
196 public ICollection<Toolset> Toolsets {
197 // For ConfigurationFile and None, they cannot be added externally.
198 get { return (ToolsetLocations & ToolsetDefinitionLocations.Registry) != 0 ? toolsets : toolsets.ToList (); }
201 //FIXME: should also support config file, depending on ToolsetLocations
202 void LoadDefaultToolsets ()
204 AddToolset (new Toolset ("2.0",
205 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version20), this, null));
206 AddToolset (new Toolset ("3.0",
207 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version30), this, null));
208 AddToolset (new Toolset ("3.5",
209 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version35), this, null));
211 AddToolset (new Toolset ("4.0",
212 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version40), this, null));
215 AddToolset (new Toolset ("4.5",
216 ToolLocationHelper.GetPathToDotNetFramework (TargetDotNetFrameworkVersion.Version45), this, null));
220 [MonoTODO ("not verified at all")]
221 public void AddToolset (Toolset toolset)
223 toolsets.Add (toolset);
226 [MonoTODO ("not verified at all")]
227 public void RemoveAllToolsets ()
232 [MonoTODO ("not verified at all")]
233 public void RegisterLogger (ILogger logger)
235 loggers.Add (logger);
238 [MonoTODO ("not verified at all")]
239 public void RegisterLoggers (IEnumerable<ILogger> loggers)
241 foreach (var logger in loggers)
242 this.loggers.Add (logger);
245 public void UnloadAllProjects ()
247 throw new NotImplementedException ();
250 public void UnloadProject (Project project)
252 throw new NotImplementedException ();
255 public void UnloadProject (ProjectRootElement projectRootElement)
257 throw new NotImplementedException ();
260 public static Version Version {
261 get { throw new NotImplementedException (); }
267 public bool DisableMarkDirty { get; set; }
270 public HostServices HostServices { get; set; }
273 public bool IsBuildEnabled { get; set; }