Merge pull request #1033 from godFather89/master
[mono.git] / mcs / class / Microsoft.Build.Tasks / Microsoft.Build.Tasks / ResolveAssemblyReference.cs
1 //
2 // ResolveAssemblyReference.cs: Searches for assembly files.
3 //
4 // Author:
5 //   Marek Sieradzki (marek.sieradzki@gmail.com)
6 //   Ankit Jain (jankit@novell.com)
7 // 
8 // (C) 2006 Marek Sieradzki
9 // Copyright 2009 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 using System;
31 using System.Collections.Generic;
32 using System.Globalization;
33 using System.IO;
34 using System.Linq;
35 using System.Reflection;
36 using System.Security;
37 using Microsoft.Build.Framework;
38 using Microsoft.Build.Utilities;
39
40 namespace Microsoft.Build.Tasks {
41         public class ResolveAssemblyReference : TaskExtension {
42         
43                 bool            autoUnify;
44                 ITaskItem[]     assemblyFiles;
45                 ITaskItem[]     assemblies;
46                 string          appConfigFile;
47                 string[]        allowedAssemblyExtensions;
48                 string[]        allowedRelatedFileExtensions;
49                 string[]        candidateAssemblyFiles;
50                 ITaskItem[]     copyLocalFiles;
51                 ITaskItem[]     filesWritten;
52                 bool            findDependencies;
53                 bool            findRelatedFiles;
54                 bool            findSatellites;
55                 bool            findSerializationAssemblies;
56                 string[]        installedAssemblyTables;
57                 ITaskItem[]     relatedFiles;
58                 ITaskItem[]     resolvedDependencyFiles;
59                 ITaskItem[]     resolvedFiles;
60                 ITaskItem[]     satelliteFiles;
61                 ITaskItem[]     scatterFiles;
62                 string[]        searchPaths;
63                 ITaskItem[]     serializationAssemblyFiles;
64                 bool            silent;
65                 string          stateFile;
66                 ITaskItem[]     suggestedRedirects;
67                 string[]        targetFrameworkDirectories;
68                 string          targetProcessorArchitecture;
69                 static string []        default_assembly_extensions;
70
71                 AssemblyResolver        assembly_resolver;
72                 List<string> dependency_search_paths;
73                 Dictionary<string, ResolvedReference> assemblyNameToResolvedRef;
74                 Dictionary<string, ITaskItem>   tempSatelliteFiles, tempRelatedFiles,
75                         tempResolvedDepFiles, tempCopyLocalFiles;
76                 List<ITaskItem> tempResolvedFiles;
77                 List<PrimaryReference> primaryReferences;
78                 Dictionary<string, string> alreadyScannedAssemblyNames;
79                 Dictionary<string, string> conflictWarningsCache;
80
81                 //FIXME: construct and use a graph of the dependencies, useful across projects
82
83                 static ResolveAssemblyReference ()
84                 {
85                         default_assembly_extensions = new string [] { ".dll", ".exe" };
86                 }
87
88                 public ResolveAssemblyReference ()
89                 {
90                         assembly_resolver = new AssemblyResolver ();
91                 }
92
93                 //FIXME: make this reusable
94                 public override bool Execute ()
95                 {
96                         if (assemblies == null && assemblyFiles == null)
97                                 // nothing to resolve
98                                 return true;
99
100                         LogTaskParameters ();
101
102                         assembly_resolver.Log = Log;
103                         tempResolvedFiles = new List<ITaskItem> ();
104                         tempCopyLocalFiles = new Dictionary<string, ITaskItem> ();
105                         tempSatelliteFiles = new Dictionary<string, ITaskItem> ();
106                         tempRelatedFiles = new Dictionary<string, ITaskItem> ();
107                         tempResolvedDepFiles = new Dictionary<string, ITaskItem> ();
108
109                         primaryReferences = new List<PrimaryReference> ();
110                         assemblyNameToResolvedRef = new Dictionary<string, ResolvedReference> ();
111                         conflictWarningsCache = new Dictionary<string, string> ();
112
113                         ResolveAssemblies ();
114                         ResolveAssemblyFiles ();
115                         resolvedFiles = tempResolvedFiles.ToArray ();
116
117                         alreadyScannedAssemblyNames = new Dictionary<string, string> ();
118
119                         // the first element is place holder for parent assembly's dir
120                         dependency_search_paths = new List<string> () { String.Empty };
121                         dependency_search_paths.AddRange (searchPaths);
122
123                         // resolve dependencies
124                         foreach (PrimaryReference pref in primaryReferences)
125                                 ResolveAssemblyFileDependencies (pref.TaskItem, pref.ParentCopyLocal);
126
127                         copyLocalFiles = tempCopyLocalFiles.Values.ToArray ();
128                         satelliteFiles = tempSatelliteFiles.Values.ToArray ();
129                         relatedFiles = tempRelatedFiles.Values.ToArray ();
130                         resolvedDependencyFiles = tempResolvedDepFiles.Values.ToArray ();
131
132                         tempResolvedFiles.Clear ();
133                         tempCopyLocalFiles.Clear ();
134                         tempSatelliteFiles.Clear ();
135                         tempRelatedFiles.Clear ();
136                         tempResolvedDepFiles.Clear ();
137                         alreadyScannedAssemblyNames.Clear ();
138                         primaryReferences.Clear ();
139                         assemblyNameToResolvedRef.Clear ();
140                         conflictWarningsCache.Clear ();
141                         dependency_search_paths = null;
142
143                         return true;
144                 }
145
146                 void ResolveAssemblies ()
147                 {
148                         if (assemblies == null || assemblies.Length == 0)
149                                 return;
150
151                         foreach (ITaskItem item in assemblies) {
152                                 if (!String.IsNullOrEmpty (item.GetMetadata ("SubType"))) {
153                                         Log.LogWarning ("Reference '{0}' has non-empty SubType. Ignoring.", item.ItemSpec);
154                                         continue;
155                                 }
156
157                                 LogWithPrecedingNewLine (MessageImportance.Low, "Primary Reference {0}", item.ItemSpec);
158                                 ResolvedReference resolved_ref = ResolveReference (item, searchPaths, true);
159                                 if (resolved_ref == null) {
160                                         Log.LogWarning ("Reference '{0}' not resolved", item.ItemSpec);
161                                         assembly_resolver.LogSearchLoggerMessages (MessageImportance.Normal);
162                                 } else {
163                                         Log.LogMessage (MessageImportance.Low,
164                                                         "\tReference {0} resolved to {1}. CopyLocal = {2}",
165                                                         item.ItemSpec, resolved_ref.TaskItem,
166                                                         resolved_ref.TaskItem.GetMetadata ("CopyLocal"));
167
168                                         Log.LogMessage (MessageImportance.Low,
169                                                         "\tReference found at search path {0}",
170                                                         resolved_ref.FoundInSearchPathAsString);
171
172                                         assembly_resolver.LogSearchLoggerMessages (MessageImportance.Low);
173
174                                         if (TryAddNewReference (tempResolvedFiles, resolved_ref) &&
175                                                 !IsFromGacOrTargetFramework (resolved_ref) &&
176                                                 resolved_ref.FoundInSearchPath != SearchPath.PkgConfig) {
177                                                 primaryReferences.Add (new PrimaryReference (
178                                                                 resolved_ref.TaskItem,
179                                                                 resolved_ref.TaskItem.GetMetadata ("CopyLocal")));
180                                         }
181                                 }
182                         }
183                 }
184
185                 // Use @search_paths to resolve the reference
186                 ResolvedReference ResolveReference (ITaskItem item, IEnumerable<string> search_paths, bool set_copy_local)
187                 {
188                         ResolvedReference resolved = null;
189                         bool specific_version;
190
191                         assembly_resolver.ResetSearchLogger ();
192
193                         if (!TryGetSpecificVersionValue (item, out specific_version))
194                                 return null;
195
196                         foreach (string spath in search_paths) {
197                                 assembly_resolver.LogSearchMessage ("For searchpath {0}", spath);
198
199                                 if (String.Compare (spath, "{HintPathFromItem}") == 0) {
200                                         resolved = assembly_resolver.ResolveHintPathReference (item, specific_version);
201                                 } else if (String.Compare (spath, "{TargetFrameworkDirectory}") == 0) {
202                                         if (targetFrameworkDirectories == null)
203                                                 continue;
204                                         foreach (string fpath in targetFrameworkDirectories) {
205                                                 resolved = assembly_resolver.FindInTargetFramework (item,
206                                                                 fpath, specific_version);
207                                                 if (resolved != null)
208                                                         break;
209                                         }
210                                 } else if (String.Compare (spath, "{GAC}") == 0) {
211                                         resolved = assembly_resolver.ResolveGacReference (item, specific_version);
212                                 } else if (String.Compare (spath, "{RawFileName}") == 0) {
213                                         //FIXME: identify assembly names, as extract the name, and try with that?
214                                         AssemblyName aname;
215                                         if (assembly_resolver.TryGetAssemblyNameFromFile (item.ItemSpec, out aname))
216                                                 resolved = assembly_resolver.GetResolvedReference (item, item.ItemSpec, aname, true,
217                                                                 SearchPath.RawFileName);
218                                 } else if (String.Compare (spath, "{CandidateAssemblyFiles}") == 0) {
219                                         assembly_resolver.LogSearchMessage (
220                                                         "Warning: {{CandidateAssemblyFiles}} not supported currently");
221                                 } else if (String.Compare (spath, "{PkgConfig}") == 0) {
222                                         resolved = assembly_resolver.ResolvePkgConfigReference (item, specific_version);
223                                 } else {
224                                         resolved = assembly_resolver.FindInDirectory (
225                                                         item, spath,
226                                                         allowedAssemblyExtensions ?? default_assembly_extensions,
227                                                         specific_version);
228                                 }
229
230                                 if (resolved != null)
231                                         break;
232                         }
233
234                         if (resolved != null && set_copy_local)
235                                 SetCopyLocal (resolved.TaskItem, resolved.CopyLocal.ToString ());
236
237                         return resolved;
238                 }
239
240                 bool TryGetSpecificVersionValue (ITaskItem item, out bool specific_version)
241                 {
242                         specific_version = true;
243                         string value = item.GetMetadata ("SpecificVersion");
244                         if (String.IsNullOrEmpty (value)) {
245                                 //AssemblyName name = new AssemblyName (item.ItemSpec);
246                                 // If SpecificVersion is not specified, then
247                                 // it is true if the Include is a strong name else false
248                                 //specific_version = assembly_resolver.IsStrongNamed (name);
249
250                                 // msbuild seems to just look for a ',' in the name :/
251                                 specific_version = item.ItemSpec.IndexOf (',') >= 0;
252                                 return true;
253                         }
254
255                         if (Boolean.TryParse (value, out specific_version))
256                                 return true;
257
258                         Log.LogError ("Item '{0}' has attribute SpecificVersion with invalid value '{1}' " +
259                                         "which could not be converted to a boolean.", item.ItemSpec, value);
260                         return false;
261                 }
262
263                 //FIXME: Consider CandidateAssemblyFiles also here
264                 void ResolveAssemblyFiles ()
265                 {
266                         if (assemblyFiles == null)
267                                 return;
268
269                         foreach (ITaskItem item in assemblyFiles) {
270                                 assembly_resolver.ResetSearchLogger ();
271
272                                 if (!File.Exists (item.ItemSpec)) {
273                                         LogWithPrecedingNewLine (MessageImportance.Low,
274                                                         "Primary Reference from AssemblyFiles {0}, file not found. Ignoring",
275                                                         item.ItemSpec);
276                                         continue;
277                                 }
278
279                                 LogWithPrecedingNewLine (MessageImportance.Low, "Primary Reference from AssemblyFiles {0}", item.ItemSpec);
280                                 string copy_local;
281
282                                 AssemblyName aname;
283                                 if (!assembly_resolver.TryGetAssemblyNameFromFile (item.ItemSpec, out aname)) {
284                                         Log.LogWarning ("Reference '{0}' not resolved", item.ItemSpec);
285                                         assembly_resolver.LogSearchLoggerMessages (MessageImportance.Normal);
286                                         continue;
287                                 }
288
289                                 assembly_resolver.LogSearchLoggerMessages (MessageImportance.Low);
290
291                                 ResolvedReference rr = assembly_resolver.GetResolvedReference (item, item.ItemSpec, aname, true,
292                                                 SearchPath.RawFileName);
293                                 copy_local = rr.CopyLocal.ToString ();
294
295                                 if (!TryAddNewReference (tempResolvedFiles, rr))
296                                         // already resolved
297                                         continue;
298
299                                 SetCopyLocal (rr.TaskItem, copy_local);
300
301                                 FindAndAddRelatedFiles (item.ItemSpec, copy_local);
302                                 FindAndAddSatellites (item.ItemSpec, copy_local);
303
304                                 if (FindDependencies && !IsFromGacOrTargetFramework (rr) &&
305                                                 rr.FoundInSearchPath != SearchPath.PkgConfig)
306                                         primaryReferences.Add (new PrimaryReference (item, copy_local));
307                         }
308                 }
309
310                 // Tries to resolve assemblies referenced by @item
311                 // Skips gac references
312                 // @item : filename
313                 void ResolveAssemblyFileDependencies (ITaskItem item, string parent_copy_local)
314                 {
315                         Queue<string> dependencies = new Queue<string> ();
316                         dependencies.Enqueue (item.ItemSpec);
317
318                         while (dependencies.Count > 0) {
319                                 string filename = Path.GetFullPath (dependencies.Dequeue ());
320                                 Assembly asm = Assembly.ReflectionOnlyLoadFrom (filename);
321                                 if (alreadyScannedAssemblyNames.ContainsKey (asm.FullName))
322                                         continue;
323
324                                 // set the 1st search path to this ref's base path
325                                 // Will be used for resolving the dependencies
326                                 dependency_search_paths [0] = Path.GetDirectoryName (filename);
327
328                                 foreach (AssemblyName aname in asm.GetReferencedAssemblies ()) {
329                                         if (alreadyScannedAssemblyNames.ContainsKey (aname.FullName))
330                                                 continue;
331
332                                         ResolvedReference resolved_ref = ResolveDependencyByAssemblyName (
333                                                 aname, asm.FullName, parent_copy_local);
334
335                                         if (IncludeDependencies (resolved_ref, aname.FullName)) {
336                                                 tempResolvedDepFiles[resolved_ref.AssemblyName.FullName] = resolved_ref.TaskItem;
337                                                 dependencies.Enqueue (resolved_ref.TaskItem.ItemSpec);
338                                         }
339                                 }
340                                 alreadyScannedAssemblyNames.Add (asm.FullName, String.Empty);
341                         }
342                 }
343
344                 // Resolves by looking dependency_search_paths
345                 // which is dir of parent reference file, and
346                 // SearchPaths
347                 ResolvedReference ResolveDependencyByAssemblyName (AssemblyName aname, string parent_asm_name,
348                                 string parent_copy_local)
349                 {
350                         // This will check for compatible assembly name/version
351                         ResolvedReference resolved_ref;
352                         if (TryGetResolvedReferenceByAssemblyName (aname, false, out resolved_ref))
353                                 return resolved_ref;
354
355                         LogWithPrecedingNewLine (MessageImportance.Low, "Dependency {0}", aname);
356                         Log.LogMessage (MessageImportance.Low, "\tRequired by {0}", parent_asm_name);
357
358                         ITaskItem item = new TaskItem (aname.FullName);
359                         item.SetMetadata ("SpecificVersion", "false");
360                         resolved_ref = ResolveReference (item, dependency_search_paths, false);
361
362                         if (resolved_ref != null) {
363                                 Log.LogMessage (MessageImportance.Low, "\tReference {0} resolved to {1}.",
364                                         aname, resolved_ref.TaskItem.ItemSpec);
365
366                                 Log.LogMessage (MessageImportance.Low,
367                                                 "\tReference found at search path {0}",
368                                                 resolved_ref.FoundInSearchPathAsString);
369
370                                 assembly_resolver.LogSearchLoggerMessages (MessageImportance.Low);
371
372                                 if (resolved_ref.FoundInSearchPath == SearchPath.Directory) {
373                                         // override CopyLocal with parent's val
374                                         SetCopyLocal (resolved_ref.TaskItem, parent_copy_local);
375
376                                         Log.LogMessage (MessageImportance.Low,
377                                                         "\tThis is CopyLocal {0} as parent item has this value",
378                                                         parent_copy_local);
379
380                                         if (TryAddNewReference (tempResolvedFiles, resolved_ref)) {
381                                                 FindAndAddRelatedFiles (resolved_ref.TaskItem.ItemSpec, parent_copy_local);
382                                                 FindAndAddSatellites (resolved_ref.TaskItem.ItemSpec, parent_copy_local);
383                                         }
384                                 } else {
385                                         //gac or tgtfmwk
386                                         Log.LogMessage (MessageImportance.Low,
387                                                         "\tThis is CopyLocal false as it is in the GAC," +
388                                                         "target framework directory or provided by a package.");
389
390                                         TryAddNewReference (tempResolvedFiles, resolved_ref);
391                                 }
392                         } else {
393                                 Log.LogMessage (MessageImportance.Low, "Could not resolve the assembly \"{0}\".", aname);
394                                 assembly_resolver.LogSearchLoggerMessages (MessageImportance.Low);
395                         }
396
397                         return resolved_ref;
398                 }
399
400                 void FindAndAddRelatedFiles (string filename, string parent_copy_local)
401                 {
402                         if (!findRelatedFiles || allowedRelatedFileExtensions == null)
403                                 return;
404
405                         foreach (string ext in allowedRelatedFileExtensions) {
406                                 string rfile = Path.ChangeExtension (filename, ext);
407                                 if (File.Exists (rfile)) {
408                                         ITaskItem item = new TaskItem (rfile);
409                                         SetCopyLocal (item, parent_copy_local);
410
411                                         tempRelatedFiles.AddUniqueFile (item);
412                                 }
413                         }
414                 }
415
416                 void FindAndAddSatellites (string filename, string parent_copy_local)
417                 {
418                         if (!FindSatellites)
419                                 return;
420
421                         string basepath = Path.GetDirectoryName (filename);
422                         string resource = String.Format ("{0}{1}{2}",
423                                         Path.GetFileNameWithoutExtension (filename),
424                                         ".resources",
425                                         Path.GetExtension (filename));
426
427                         string dir_sep = Path.DirectorySeparatorChar.ToString ();
428                         foreach (string dir in Directory.GetDirectories (basepath)) {
429                                 string culture = Path.GetFileName (dir);
430                                 if (!CultureNamesTable.ContainsKey (culture))
431                                         continue;
432
433                                 string res_path = Path.Combine (dir, resource);
434                                 if (File.Exists (res_path)) {
435                                         ITaskItem item = new TaskItem (res_path);
436                                         SetCopyLocal (item, parent_copy_local);
437                                         item.SetMetadata ("DestinationSubdirectory", culture + dir_sep);
438                                         tempSatelliteFiles.AddUniqueFile (item);
439                                 }
440                         }
441                 }
442
443                 // returns true is it was new
444                 bool TryAddNewReference (List<ITaskItem> file_list, ResolvedReference key_ref)
445                 {
446                         ResolvedReference found_ref;
447                         if (!TryGetResolvedReferenceByAssemblyName (key_ref.AssemblyName, key_ref.IsPrimary, out found_ref)) {
448                                 assemblyNameToResolvedRef [key_ref.AssemblyName.Name] = key_ref;
449                                 file_list.Add (key_ref.TaskItem);
450
451                                 return true;
452                         }
453                         return false;
454                 }
455
456                 void SetCopyLocal (ITaskItem item, string copy_local)
457                 {
458                         item.SetMetadata ("CopyLocal", copy_local);
459
460                         // Assumed to be valid value
461                         if (Boolean.Parse (copy_local))
462                                 tempCopyLocalFiles.AddUniqueFile (item);
463                 }
464
465                 bool TryGetResolvedReferenceByAssemblyName (AssemblyName key_aname, bool is_primary, out ResolvedReference found_ref)
466                 {
467                         found_ref = null;
468                         // Match by just name
469                         if (!assemblyNameToResolvedRef.TryGetValue (key_aname.Name, out found_ref))
470                                 // not there
471                                 return false;
472
473                         // match for full name
474                         if (AssemblyResolver.AssemblyNamesCompatible (key_aname, found_ref.AssemblyName, true, false))
475                                 // exact match, so its already there, dont add anything
476                                 return true;
477
478                         // we have a name match, but version mismatch!
479                         assembly_resolver.LogSearchMessage ("A conflict was detected between '{0}' and '{1}'",
480                                         key_aname.FullName, found_ref.AssemblyName.FullName);
481
482                         if (is_primary == found_ref.IsPrimary) {
483                                 assembly_resolver.LogSearchMessage ("Unable to choose between the two. " +
484                                                 "Choosing '{0}' arbitrarily.", found_ref.AssemblyName.FullName);
485                                 return true;
486                         }
487
488                         // since all dependencies are processed after
489                         // all primary refererences, the one in the cache
490                         // has to be a primary
491                         // Prefer a primary reference over a dependency
492
493                         assembly_resolver.LogSearchMessage ("Choosing '{0}' as it is a primary reference.",
494                                         found_ref.AssemblyName.FullName);
495
496                         // If we can successfully use the primary reference, don't log a warning. It's too
497                         // verbose.
498                         //LogConflictWarning (found_ref.AssemblyName.FullName, key_aname.FullName);
499
500                         return true;
501                 }
502
503                 void LogWithPrecedingNewLine (MessageImportance importance, string format, params object [] args)
504                 {
505                         Log.LogMessage (importance, String.Empty);
506                         Log.LogMessage (importance, format, args);
507                 }
508
509                 // conflict b/w @main and @conflicting, picking @main
510                 void LogConflictWarning (string main, string conflicting)
511                 {
512                         string key = main + ":" + conflicting;
513                         if (!conflictWarningsCache.ContainsKey (key)) {
514                                 Log.LogWarning ("Found a conflict between : '{0}' and '{1}'. Using '{0}' reference.",
515                                                 main, conflicting);
516                                 conflictWarningsCache [key] = key;
517                         }
518                 }
519
520                 bool IsFromGacOrTargetFramework (ResolvedReference rr)
521                 {
522                         return rr.FoundInSearchPath == SearchPath.Gac ||
523                                 rr.FoundInSearchPath == SearchPath.TargetFrameworkDirectory;
524                 }
525
526                 bool IncludeDependencies (ResolvedReference rr, string aname)
527                 {
528                         if (rr == null)
529                                 return false;
530                         if (aname.Equals ("System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"))
531                                 return true;
532                         return !IsFromGacOrTargetFramework (rr) && rr.FoundInSearchPath != SearchPath.PkgConfig;
533                 }
534
535                 void LogTaskParameters ()
536                 {
537                         Log.LogMessage (MessageImportance.Low, "TargetFrameworkDirectories:");
538                         if (TargetFrameworkDirectories != null)
539                                 foreach (string dir in TargetFrameworkDirectories)
540                                         Log.LogMessage (MessageImportance.Low, "\t{0}", dir);
541
542                         Log.LogMessage (MessageImportance.Low, "SearchPaths:");
543                         if (SearchPaths != null)
544                                 foreach (string path in SearchPaths)
545                                         Log.LogMessage (MessageImportance.Low, "\t{0}", path);
546                 }
547
548                 public bool AutoUnify {
549                         get { return autoUnify; }
550                         set { autoUnify = value; }
551                 }
552                 
553                 public ITaskItem[] AssemblyFiles {
554                         get { return assemblyFiles; }
555                         set { assemblyFiles = value; }
556                 }
557                 
558                 public ITaskItem[] Assemblies {
559                         get { return assemblies; }
560                         set { assemblies = value; }
561                 }
562                 
563                 public string AppConfigFile {
564                         get { return appConfigFile; }
565                         set { appConfigFile = value; }
566                 }
567                 
568                 public string[] AllowedAssemblyExtensions {
569                         get { return allowedAssemblyExtensions; }
570                         set { allowedAssemblyExtensions = value; }
571                 }
572
573                 public string[] AllowedRelatedFileExtensions {
574                         get { return allowedRelatedFileExtensions; }
575                         set { allowedRelatedFileExtensions = value; }
576                 }
577                 
578                 public string[] CandidateAssemblyFiles {
579                         get { return candidateAssemblyFiles; }
580                         set { candidateAssemblyFiles = value; }
581                 }
582                 
583                 [Output]
584                 public ITaskItem[] CopyLocalFiles {
585                         get { return copyLocalFiles; }
586                 }
587                 
588                 [Output]
589                 public ITaskItem[] FilesWritten {
590                         get { return filesWritten; }
591                         set { filesWritten = value; }
592                 }
593                 
594                 public bool FindDependencies {
595                         get { return findDependencies; }
596                         set { findDependencies = value; }
597                 }
598                 
599                 public bool FindRelatedFiles {
600                         get { return findRelatedFiles; }
601                         set { findRelatedFiles = value; }
602                 }
603                 
604                 public bool FindSatellites {
605                         get { return findSatellites; }
606                         set { findSatellites = value; }
607                 }
608                 
609                 public bool FindSerializationAssemblies {
610                         get { return findSerializationAssemblies; }
611                         set { findSerializationAssemblies = value; }
612                 }
613                 
614                 public string[] InstalledAssemblyTables {
615                         get { return installedAssemblyTables; }
616                         set { installedAssemblyTables = value; }
617                 }
618                 
619                 [Output]
620                 public ITaskItem[] RelatedFiles {
621                         get { return relatedFiles; }
622                 }
623                 
624                 [Output]
625                 public ITaskItem[] ResolvedDependencyFiles {
626                         get { return resolvedDependencyFiles; }
627                 }
628                 
629                 [Output]
630                 public ITaskItem[] ResolvedFiles {
631                         get { return resolvedFiles; }
632                 }
633                 
634                 [Output]
635                 public ITaskItem[] SatelliteFiles {
636                         get { return satelliteFiles; }
637                 }
638                 
639                 [Output]
640                 public ITaskItem[] ScatterFiles {
641                         get { return scatterFiles; }
642                 }
643                 
644                 [Required]
645                 public string[] SearchPaths {
646                         get { return searchPaths; }
647                         set { searchPaths = value; }
648                 }
649                 
650                 [Output]
651                 public ITaskItem[] SerializationAssemblyFiles {
652                         get { return serializationAssemblyFiles; }
653                 }
654                 
655                 public bool Silent {
656                         get { return silent; }
657                         set { silent = value; }
658                 }
659                 
660                 public string StateFile {
661                         get { return stateFile; }
662                         set { stateFile = value; }
663                 }
664                 
665                 [Output]
666                 public ITaskItem[] SuggestedRedirects {
667                         get { return suggestedRedirects; }
668                 }
669
670 #if NET_4_0
671                 public string TargetFrameworkMoniker { get; set; }
672
673                 public string TargetFrameworkMonikerDisplayName { get; set; }
674 #endif
675
676                 public string TargetFrameworkVersion { get; set; }
677
678                 public string[] TargetFrameworkDirectories {
679                         get { return targetFrameworkDirectories; }
680                         set { targetFrameworkDirectories = value; }
681                 }
682                 
683                 public string TargetProcessorArchitecture {
684                         get { return targetProcessorArchitecture; }
685                         set { targetProcessorArchitecture = value; }
686                 }
687
688
689                 static Dictionary<string, string> cultureNamesTable;
690                 static Dictionary<string, string> CultureNamesTable {
691                         get {
692                                 if (cultureNamesTable == null) {
693                                         cultureNamesTable = new Dictionary<string, string> ();
694                                         foreach (CultureInfo ci in CultureInfo.GetCultures (CultureTypes.AllCultures))
695                                                 cultureNamesTable [ci.Name] = ci.Name;
696                                 }
697
698                                 return cultureNamesTable;
699                         }
700                 }
701         }
702
703         static class ResolveAssemblyReferenceHelper {
704                 public static void AddUniqueFile (this Dictionary<string, ITaskItem> dic, ITaskItem item)
705                 {
706                         if (dic == null)
707                                 throw new ArgumentNullException ("dic");
708                         if (item == null)
709                                 throw new ArgumentNullException ("item");
710
711                         string fullpath = Path.GetFullPath (item.ItemSpec);
712                         if (!dic.ContainsKey (fullpath))
713                                 dic [fullpath] = item;
714                 }
715         }
716
717         struct PrimaryReference {
718                 public ITaskItem TaskItem;
719                 public string ParentCopyLocal;
720
721                 public PrimaryReference (ITaskItem item, string parent_copy_local)
722                 {
723                         TaskItem = item;
724                         ParentCopyLocal = parent_copy_local;
725                 }
726         }
727
728 }