/// <summary> /// Adds a reference to binary file. /// <param name="sourceFile">Path to source file. May contain environment variables.</param> /// </summary> public void AddSourceReference(string sourceFile) { if (SourceReferences == null) { SourceReferences = new List <string>(); } SourceReferences.Add(sourceFile); }
public override bool Execute() { if (SourceReferences == null) { throw new ArgumentNullException(nameof(SourceReferences)); } var assemblyNames = new HashSet <string>( (AssemblyNames ?? string.Empty).Split(Semicolon, StringSplitOptions.RemoveEmptyEntries), StringComparer.OrdinalIgnoreCase); if (assemblyNames.Count == 0) { return(true); } var targetPath = Path.Combine(_sourceDir, "obj", "GeneratedPublicizedAssemblies"); Directory.CreateDirectory(targetPath); GenerateAttributes(targetPath, assemblyNames); foreach (var assemblyPath in SourceReferences .Select(a => Path.GetDirectoryName(GetFullFilePath(a.ItemSpec)))) { _resolver.AddSearchDirectory(assemblyPath); } var targetReferences = new List <ITaskItem>(); var removedReferences = new List <ITaskItem>(); foreach (var assembly in SourceReferences) { var assemblyPath = GetFullFilePath(assembly.ItemSpec); var assemblyName = Path.GetFileNameWithoutExtension(assemblyPath); if (assemblyNames.Contains(assemblyName)) { // ReSharper disable once AssignNullToNotNullAttribute var targetAssemblyPath = Path.Combine(targetPath, Path.GetFileName(assemblyPath)); var targetAsemblyFileInfo = new FileInfo(targetAssemblyPath); if (!targetAsemblyFileInfo.Exists || targetAsemblyFileInfo.Length == 0) { CreatePublicAssembly(assemblyPath, targetAssemblyPath); Log.LogMessageFromText("Created publicized assembly at " + targetAssemblyPath, MessageImportance.Normal); } else { Log.LogMessageFromText("Publicized assembly already exists at " + targetAssemblyPath, MessageImportance.Low); } targetReferences.Add(new TaskItem(targetAssemblyPath)); removedReferences.Add(assembly); } } TargetReferences = targetReferences.ToArray(); RemovedReferences = removedReferences.ToArray(); return(true); }