Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ProjectReference.cs « MonoDevelop.Projects « MonoDevelop.Core « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a30115c441a4a50e57a1ac6fb725105011e06326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
// 
// ProjectReference.cs
//  
// Author:
//       Lluis Sanchez Gual <lluis@novell.com>
// 
// Copyright (c) 2009 Novell, Inc (http://www.novell.com)
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.



using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Diagnostics;
using System.Xml;
using MonoDevelop.Core;
using System.ComponentModel;
using MonoDevelop.Projects;
using MonoDevelop.Core.Serialization;
using MonoDevelop.Core.Assemblies;
using MonoDevelop.Projects.Formats.MSBuild;

namespace MonoDevelop.Projects
{
	public enum ReferenceType {
		Assembly,
		Project,
		Package,
		Custom,
		[Obsolete ("Use Package")]
		Gac = Package
	}
	
	/// <summary>
	/// This class represent a reference information in an Project object.
	/// </summary>
	[DataItem (FallbackType=typeof(UnknownProjectReference))]
	public class ProjectReference : ProjectItem, ICloneable
	{
		ReferenceType referenceType = ReferenceType.Custom;
		DotNetProject ownerProject;
		string reference = String.Empty;
		bool? localCopy;
		
		// A project may reference assemblies which are not available
		// in the system where it is opened. For example, opening
		// a project that references gtk# 2.4 in a system with gtk# 2.6.
		// In this case the reference will be upgraded to 2.6, but for
		// consistency reasons the reference will still be saved as 2.4.
		// The loadedReference stores the reference initially loaded,
		// so it can be saved again.
		string loadedReference;
		bool specificVersion = true;
		bool notFound;
		string package;
		SystemPackage cachedPackage;
		string customError;
		FilePath hintPath;

		string originalMSBuildReferenceInclude;
		string originalMSBuildReferenceHintPath;

		public event EventHandler StatusChanged;
		
		[ItemProperty ("Package", DefaultValue="")]
		internal string packageName {
			get {
				SystemPackage sp = Package;
				if (sp != null && !sp.IsGacPackage)
					return sp.Name;
				else
					return string.Empty;
			}
			set {
				package = value;
			}
		}
		
		public ProjectReference ()
		{
		}
		
		internal void SetOwnerProject (DotNetProject project)
		{
			ownerProject = project;
			UpdatePackageReference ();
		}

		public sealed override string Include {
			get {
				if (referenceType == ReferenceType.Project && base.Include == null) {
					Project refProj = OwnerProject != null && OwnerProject.ParentSolution != null ? OwnerProject.ParentSolution.FindProjectByName (Reference) : null;
					if (refProj != null)
						base.Include = MSBuildProjectService.ToMSBuildPath (OwnerProject.ItemDirectory, refProj.FileName);
					else
						base.Include = Reference;
				}
				return base.Include;
			}
		}
		
		public ProjectReference (ReferenceType referenceType, string reference): this (referenceType, reference, null)
		{
		}

		public ProjectReference (ReferenceType referenceType, string reference, string hintPath)
		{
			Init (referenceType, reference, hintPath);
		}
		
		void Init (ReferenceType referenceType, string reference, string hintPath)
		{
			if (referenceType == ReferenceType.Assembly) {
				specificVersion = false;
				if (hintPath == null) {
					hintPath = reference;
					reference = Path.GetFileNameWithoutExtension (reference);
				}

				if (Include == null) {
					if (File.Exists (HintPath)) {
						try {
							var aname = System.Reflection.AssemblyName.GetAssemblyName (HintPath);
							if (SpecificVersion) {
								Include = aname.FullName;
							} else {
								Include = aname.Name;
							}
						} catch (Exception ex) {
							string msg = string.Format ("Could not get full name for assembly '{0}'.", Reference);
							LoggingService.LogError (msg, ex);
						}
					}
					if (Include == null)
						Include = Path.GetFileNameWithoutExtension (hintPath);
				}
			}

			switch (referenceType) {
			case ReferenceType.Package: 
			case ReferenceType.Assembly: 
				ItemName = "Reference";
				break;
			case ReferenceType.Project:
				ItemName = "ProjectReference";
				break;
			}

			this.referenceType = referenceType;
			this.reference = reference;
			this.hintPath = hintPath;
			UpdatePackageReference ();

			if (referenceType == ReferenceType.Package && Include == null) {
				Include = StoredReference;
				SystemPackage pkg = Package;
				if (pkg != null && pkg.IsFrameworkPackage) {
					int i = Include.IndexOf (',');
					if (i != -1)
						Include = Include.Substring (0, i).Trim ();
				}
			}

			if (Include == null)
				Include = reference;
		}

		public ProjectReference (Project referencedProject)
		{
			referenceType = ReferenceType.Project;
			reference = referencedProject.Name;
			specificVersion = true;
		}
		
		public ProjectReference (SystemAssembly asm)
		{
			referenceType = ReferenceType.Package;
			reference = asm.FullName;
			if (asm.Package.IsFrameworkPackage)
				specificVersion = false;
			if (!asm.Package.IsGacPackage)
				package = asm.Package.Name;
			UpdatePackageReference ();
		}

		internal protected override void Read (Project project, IMSBuildItemEvaluated buildItem)
		{
			base.Read (project, buildItem);

			if (buildItem.Name == "Reference")
				ReadReference (project, buildItem);
			else if (buildItem.Name == "ProjectReference")
				ReadProjectReference (project, buildItem);

			LocalCopy = buildItem.Metadata.GetValue ("Private", DefaultLocalCopy);
		}

		void ReadReference (Project project, IMSBuildItemEvaluated buildItem)
		{
			if (buildItem.Metadata.HasProperty ("HintPath")) {
				FilePath path;
				var p = buildItem.Metadata.GetProperty ("HintPath");
				if (p != null)
					originalMSBuildReferenceHintPath = p.UnevaluatedValue;
				if (!buildItem.Metadata.TryGetPathValue ("HintPath", out path)) {
					var hp = buildItem.Metadata.GetValue ("HintPath");
					Init (ReferenceType.Assembly, hp, null);
					SetInvalid (GettextCatalog.GetString ("Invalid file path"));
					originalMSBuildReferenceInclude = buildItem.Include;
				} else {
					var type = File.Exists (path) ? ReferenceType.Assembly : ReferenceType.Package;
					Init (type, buildItem.Include, path);
				}
			} else {
				string asm = buildItem.Include;
				// This is a workaround for a VS bug. Looks like it is writing this assembly incorrectly
				if (asm == "System.configuration")
					asm = "System.Configuration";
				else if (asm == "System.XML")
					asm = "System.Xml";
				else if (asm == "system")
					asm = "System";
				Init (ReferenceType.Package, asm, null);
			}

			string specificVersion = buildItem.Metadata.GetValue ("SpecificVersion");
			if (string.IsNullOrWhiteSpace (specificVersion)) {
				// If the SpecificVersion element isn't present, check if the Assembly Reference specifies a Version
				SpecificVersion = ReferenceStringHasVersion (buildItem.Include);
			}
			else {
				bool value;
				// if we can't parse the value, default to false which is more permissive
				SpecificVersion = bool.TryParse (specificVersion, out value) && value;
			}
		}

		void ReadProjectReference (Project project, IMSBuildItemEvaluated buildItem)
		{
			// Get the project name from the path, since the Name attribute may other stuff other than the name
			string path = MSBuildProjectService.FromMSBuildPath (project.ItemDirectory, buildItem.Include);
			string name = Path.GetFileNameWithoutExtension (path);
			Init (ReferenceType.Project, name, null);
		}

		internal protected override void Write (MSBuildFileFormat fmt, MSBuildItem buildItem)
		{
			// If the project is not supported, don't try to update any metadata of the property,
			// just leave what was read
			if (OwnerProject.IsUnsupportedProject)
				return;

			base.Write (fmt, buildItem);

			if (ReferenceType == ReferenceType.Assembly) {
				if (originalMSBuildReferenceHintPath != null)
					buildItem.Metadata.SetValue ("HintPath", originalMSBuildReferenceHintPath, "");
				else
					buildItem.Metadata.SetValue ("HintPath", HintPath);

				buildItem.Metadata.SetValue ("SpecificVersion", SpecificVersion || !ReferenceStringHasVersion (Include), true);
			}
			else if (ReferenceType == ReferenceType.Package) {
				buildItem.Metadata.SetValue ("SpecificVersion", SpecificVersion || !ReferenceStringHasVersion (Include), true);

				//RequiredTargetFramework is undocumented, maybe only a hint for VS. Only seems to be used for .NETFramework
				var dnp = OwnerProject as DotNetProject;
				IList supportedFrameworks = fmt.SupportedFrameworks;
				if (supportedFrameworks != null && dnp != null && Package != null
					&& dnp.TargetFramework.Id.Identifier == TargetFrameworkMoniker.ID_NET_FRAMEWORK
					&& Package.IsFrameworkPackage && supportedFrameworks.Contains (Package.TargetFramework)
					&& Package.TargetFramework.Version != "2.0" && supportedFrameworks.Count > 1)
				{
					TargetFramework fx = Runtime.SystemAssemblyService.GetTargetFramework (Package.TargetFramework);
					buildItem.Metadata.SetValue ("RequiredTargetFramework", fx.Id.Version);
				} else {
					buildItem.Metadata.RemoveProperty ("RequiredTargetFramework");
				}

				buildItem.Metadata.SetValue ("HintPath", originalMSBuildReferenceHintPath, "");
			}
			else if (ReferenceType == ReferenceType.Project) {
				Project refProj = OwnerProject.ParentSolution.FindProjectByName (Reference);
				if (refProj != null) {
					buildItem.Metadata.SetValue ("Project", refProj.ItemId);
					buildItem.Metadata.SetValue ("Name", refProj.Name);
				}
			}

			buildItem.Metadata.SetValue ("Private", LocalCopy, DefaultLocalCopy);
		}

		bool ReferenceStringHasVersion (string asmName)
		{
			int commaPos = asmName.IndexOf (',');
			return commaPos >= 0 && asmName.IndexOf ("Version", commaPos) >= 0;
		}

		protected void InitCustomReference (string reference)
		{
			Reference = reference;
			referenceType = ReferenceType.Custom;
		}
		
		public static ProjectReference RenameReference (ProjectReference pref, string newReference)
		{
			ProjectReference newRef = (ProjectReference) pref.MemberwiseClone ();
			newRef.reference = newReference;
			return newRef;
		}
		
		public Project OwnerProject {
			get { return ownerProject; }
		}

		// This property is used by the serializer. It ensures that the obsolete Gac value is not serialized
		internal ReferenceType internalReferenceType {
			get { return referenceType; }
			set { referenceType = value; }
		}

		public ReferenceType ReferenceType {
			get {
				return referenceType;
			}
		}
		
		public string Reference {
			get {
				return reference;
			}
			internal set {
				reference = value;
				UpdatePackageReference ();
			}
		}
		
		public string StoredReference {
			get {
				if (!string.IsNullOrEmpty (loadedReference))
					return loadedReference;
				else
					return reference;
			}
		}
		
		public bool LocalCopy {
			get {
				// When not explicitly set, the default value of LocalCopy depends on the type of reference.
				// For project and file references the default is true. For framework and package assemblies
				// (including GAC) the default is false

				if (localCopy.HasValue)
					return localCopy.Value;
				return DefaultLocalCopy;
			}
			set {
				localCopy = value;
				if (ownerProject != null)
					ownerProject.NotifyModified (null);
			}
		}
		
		internal bool DefaultLocalCopy {
			get {
				return referenceType != ReferenceType.Package;
			}
		}

		public bool CanSetLocalCopy {
			get {
				return true;
			}
		}

		public bool SpecificVersion {
			get {
				return specificVersion;
			}
			set {
				if (specificVersion != value) {
					specificVersion = value;
					OnStatusChanged ();
				}
			}
		}
		
		public bool CanSetSpecificVersion {
			get {
				if (ReferenceType == ReferenceType.Project || ReferenceType == ReferenceType.Custom)
					return false;
				if (ReferenceType == ReferenceType.Package && Package != null && Package.IsFrameworkPackage)
					return false;
				return true;
			}
		}

		[ItemProperty ("Aliases", DefaultValue="")]
		public string Aliases { get; set; }

		public bool IsValid {
			get { return string.IsNullOrEmpty (ValidationErrorMessage); }
		}
		
		// Returns the validation error message, or an empty string if everything is ok
		public virtual string ValidationErrorMessage {
			get {
				if (customError != null)
					return customError;
				if (ReferenceType == ReferenceType.Package) {
					if (!IsExactVersion && SpecificVersion)
						return GettextCatalog.GetString ("Specified version not found: expected {0}, found {1}", GetVersionNum (StoredReference), GetVersionNum (Reference));
					if (notFound) {
						if (ownerProject != null) {
							bool isDefaultRuntime = Runtime.SystemAssemblyService.DefaultRuntime == TargetRuntime;
							bool probablyFrameworkAssembly = string.IsNullOrEmpty (originalMSBuildReferenceHintPath);

							if (TargetRuntime.IsInstalled (TargetFramework) || !probablyFrameworkAssembly) {
								if (isDefaultRuntime)
									return GettextCatalog.GetString ("Assembly not found for framework {0}", TargetFramework.Name);

								return GettextCatalog.GetString ("Assembly not found for framework {0} (in {1})", TargetFramework.Name, TargetRuntime.DisplayName);
							}

							if (isDefaultRuntime)
								return GettextCatalog.GetString ("Framework {0} is not installed", TargetFramework.Name);

							return GettextCatalog.GetString ("Framework {0} is not installed (in {1})", TargetFramework.Name, TargetRuntime.DisplayName);
						}

						return GettextCatalog.GetString ("Assembly not found");
					}
				} else if (ReferenceType == ReferenceType.Project) {
					if (ownerProject != null && ownerProject.ParentSolution != null) {
						DotNetProject p = ownerProject.ParentSolution.FindProjectByName (reference) as DotNetProject;
						if (p != null) {
							if (!ownerProject.TargetFramework.CanReferenceAssembliesTargetingFramework (p.TargetFramework))
								return GettextCatalog.GetString ("Incompatible target framework ({0})", p.TargetFramework.Name);
						}
					}
				} else if (ReferenceType == ReferenceType.Assembly) {
					if (!File.Exists (hintPath))
						return GettextCatalog.GetString ("File not found");
				}
				return string.Empty;
			}
		}
		
		public void SetInvalid (string message)
		{
			customError = message;
			OnStatusChanged ();
		}
		
		public bool IsExactVersion {
			get {
				if (ReferenceType == ReferenceType.Package) {
					string r1 = MonoDevelop.Core.Assemblies.AssemblyContext.NormalizeAsmName (StoredReference);
					string r2 = MonoDevelop.Core.Assemblies.AssemblyContext.NormalizeAsmName (Reference);
					return r1 == r2;
				}
				return true;
			}
		}

		public FilePath HintPath {
			get { return hintPath; }
		}
		
		string GetVersionNum (string asmName)
		{
			int i = asmName.IndexOf (',');
			if (i != -1) {
				i++;
				int j = asmName.IndexOf (',', i);
				if (j == -1)
					j = asmName.Length;
				string ver = asmName.Substring (i, j - i).Trim ();
				if (ver.Length > 0)
					return ver;
			}
			return "0.0.0.0";
		}

		internal ProjectReference GetRefreshedReference ()
		{
			if (customError != null)
				return null;
			if (ReferenceType == ReferenceType.Package) {
				if (!string.IsNullOrEmpty (hintPath) && File.Exists (hintPath)) {
					var res = (ProjectReference) MemberwiseClone ();
					res.referenceType = ReferenceType.Assembly;
					return res;
				}
			} else if (ReferenceType == ReferenceType.Assembly) {
				if (!string.IsNullOrEmpty (hintPath) && !File.Exists (hintPath)) {
					var res = (ProjectReference) MemberwiseClone ();
					res.referenceType = ReferenceType.Package;
					return res;
				}
			}
			return null;
		}
		
		/// <summary>
		/// Returns the file name to an assembly, regardless of what 
		/// type the assembly is.
		/// </summary>
		string GetReferencedFileName (ConfigurationSelector configuration)
		{
			switch (ReferenceType) {
				case ReferenceType.Assembly:
					return hintPath;
				
				case ReferenceType.Package:
					string file = AssemblyContext.GetAssemblyLocation (Reference, package, ownerProject != null? ownerProject.TargetFramework : null);
					return file == null ? reference : file;
				case ReferenceType.Project:
					if (ownerProject != null) {
						if (ownerProject.ParentSolution != null) {
							Project p = ownerProject.ParentSolution.FindProjectByName (reference);
							if (p != null) return p.GetOutputFileName (configuration);
						}
					}
					return null;
				
				default:
					return null;
			}
		}
		
		public virtual string[] GetReferencedFileNames (ConfigurationSelector configuration)
		{
			string s = GetReferencedFileName (configuration);
	/*		if (referenceType == ReferenceType.Package) {
				List<string> result = new List<string> ();
				result.Add (s);
				AddRequiredPackages (result, Package);
				return result.ToArray ();
			}*/
			
			if (s != null)
				return new string[] { s };
			return new string [0];
		}
		/*
		void AddRequiredPackages (List<string> result, SystemPackage fromPackage)
		{
			if (fromPackage == null || string.IsNullOrEmpty (fromPackage.Requires))
				return;
			foreach (string requiredPackageName in fromPackage.Requires.Split (' ')) {
				SystemPackage package = AssemblyContext.GetPackage (requiredPackageName);
				if (package == null)
					continue;
				foreach (SystemAssembly assembly in package.Assemblies) {
					if (assembly == null)
						continue;
					string location = AssemblyContext.GetAssemblyLocation (assembly.FullName, ownerProject != null ? ownerProject.TargetFramework : null);
					result.Add (location);
				}
				AddRequiredPackages (result, package);
			}
		}*/
		
		void UpdatePackageReference ()
		{
			if (referenceType == ReferenceType.Package && ownerProject != null) {
				notFound = false;
				string cref = AssemblyContext.FindInstalledAssembly (reference, package, ownerProject.TargetFramework);
				if (cref == null)
					cref = reference;
				cref = AssemblyContext.GetAssemblyNameForVersion (cref, package, ownerProject.TargetFramework);
				notFound = (cref == null);
				if (cref != null && cref != reference) {
					SystemAssembly asm = AssemblyContext.GetAssemblyFromFullName (cref, package, ownerProject.TargetFramework);
					bool isFrameworkAssembly = asm != null && asm.Package.IsFrameworkPackage;
					if (loadedReference == null && !isFrameworkAssembly) {
						loadedReference = reference;
					}
					reference = cref;
				}
				cachedPackage = null;
				OnStatusChanged ();
			}
		}
		
		IAssemblyContext AssemblyContext {
			get {
				if (ownerProject != null)
					return ownerProject.AssemblyContext;
				else
					return Runtime.SystemAssemblyService.DefaultAssemblyContext;
			}
		}
		
		TargetRuntime TargetRuntime {
			get {
				if (ownerProject != null)
					return ownerProject.TargetRuntime;
				else
					return Runtime.SystemAssemblyService.DefaultRuntime;
			}
		}
		
		TargetFramework TargetFramework {
			get {
				if (ownerProject != null)
					return ownerProject.TargetFramework;
				else
					return null;
			}
		}
		
		public SystemPackage Package {
			get {
				if (referenceType == ReferenceType.Package) {
					if (cachedPackage != null)
						return cachedPackage;
					
					if (package != null)
						return AssemblyContext.GetPackage (package);

					// No package is specified, get any of the registered assemblies, giving priority to gaced assemblies
					// (because non-gac assemblies should have a package name set)
					TargetFramework fx = ownerProject == null? null : ownerProject.TargetFramework;
					var best = AssemblyContext.GetAssemblyFromFullName (reference, null, fx);
					if (best != null)
						return cachedPackage = best.Package;
				}
				return null;
			}
		}
		
		internal void ResetReference ()
		{
			cachedPackage = null;
			if (loadedReference != null) {
				reference = loadedReference;
				loadedReference = null;
				UpdatePackageReference ();
			} else
				UpdatePackageReference ();
		}
		
		public object Clone()
		{
			return MemberwiseClone();
		}
		
		public override bool Equals (object obj)
		{
			return Equals (obj as ProjectReference);
		}
		
		public bool Equals (ProjectReference other)
		{
			return other != null
				&& StoredReference == other.StoredReference
				&& referenceType == other.referenceType
				&& package == other.package;
		}
		
		public override int GetHashCode ()
		{
			int result = 0;
			if (StoredReference != null)
				result ^= StoredReference.GetHashCode ();
			if (package != null)
				result ^= package.GetHashCode ();
			return result;
		}
		
		internal void NotifyStatusChanged ()
		{
			OnStatusChanged ();
		}
		
		protected virtual void OnStatusChanged ()
		{
			if (StatusChanged != null)
				StatusChanged (this, EventArgs.Empty);
		}

		/// <summary>
		/// Resolves a project for a ReferenceType.Project reference type in a given solution.
		/// </summary>
		/// <returns>The project, or <c>null</c> if it couldn't be resolved.</returns>
		/// <param name="inSolution">The solution the project is in.</param>
		/// <exception cref="T:System.ArgumentNullException">Thrown if inSolution == null</exception>
		/// <exception cref="T:System.InvalidOperationException">Thrown if ReferenceType != ReferenceType.Project</exception>
		public Project ResolveProject (Solution inSolution)
		{
			if (inSolution == null)
				throw new ArgumentNullException ("inSolution");
			if (ReferenceType != ReferenceType.Project)
				throw new InvalidOperationException ("ResolveProject is only definied for Project reference type.");
			return inSolution.FindProjectByName (Reference);
		}
	}
	
	public class UnknownProjectReference: ProjectReference
	{
	}
}