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