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