private void HandlePackage(GlobTask globTask) { var assembliesInPackage = new List <string>(); var packageDefPath = Path.Combine(PackageInstallDir, "Packages", globTask.PackageName, "package.xml"); // Silently ignore the package if its package.xml does not exist if (!File.Exists(packageDefPath)) { Log.LogWarning($"No package named {globTask.PackageName}. Does a glob expression contain a semicolon?"); return; } var dllsInPackage = dllRx.Matches(File.ReadAllText(packageDefPath)).Cast <Match>() .Where(match => match.Groups["name"].Success) .Select(match => match.Groups["name"].Value); var matchedDlls = dllsInPackage.Where(x => globTask.Includes(x, Log)); foreach (var dllPath in matchedDlls.Distinct()) { var absolutedllPath = Path.Combine(PackageInstallDir, dllPath); // Ensure we don't add references twice if they are matched by multiple patterns if (_added.Contains(absolutedllPath)) { Log.LogMessage($"{absolutedllPath} already added. Not adding again."); continue; } _added.Add(absolutedllPath); if (IsDotNetAssembly(absolutedllPath)) { assembliesInPackage.Add(dllPath); } else { Log.LogWarning($"{absolutedllPath} not recognized as a DotNet assembly. Reference not added."); } } Log.LogMessage(MessageImportance.Normal, "Found these assemblies in OpenTAP references: " + string.Join(", ", assembliesInPackage)); if (!assembliesInPackage.Any()) { Log.LogWarning($"No references added from package '{globTask.PackageName}'."); } else { WriteItemGroup(assembliesInPackage); Assemblies = Assemblies.Concat(assembliesInPackage).ToArray(); } }
public override bool Execute() { if (File.Exists(TargetMsBuildFile)) { File.Delete(TargetMsBuildFile); } if (OpenTapPackagesToReference == null || OpenTapPackagesToReference.Length == 0) { // This happens when a .csproj file does not specify any OpenTapPackageReferences -- simply ignore it Log.LogMessage("Got 0 OpenTapPackageReference targets."); return(true); } if (TargetMsBuildFile == null) { throw new Exception("TargetMsBuildFile is null"); } Assemblies = new string[] { }; try { // Distincting the tasks is not necessary, but it is a much more helpful warning than // 'No references added from package' which would be given in 'HandlePackage'. var distinctTasks = new List <ITaskItem>(OpenTapPackagesToReference.Length); foreach (var task in OpenTapPackagesToReference) { if (distinctTasks.Contains(task)) { Log.LogWarning($"Duplicate entry '{ITaskItemString(task)}' detected."); } else { distinctTasks.Add(task); } } if (distinctTasks.Count != OpenTapPackagesToReference.Length) { Log.LogWarning("Skipped duplicate entries."); } var globTasks = GlobTask.Parse(distinctTasks.ToArray()); Log.LogMessage($"Got {globTasks.Count} OpenTapPackageReference targets."); foreach (var task in globTasks) { var includeGlobs = task.Globs.Where(x => x.Include).Select(x => x.Globber.ToString()); var excludeGlobs = task.Globs.Where(x => x.Include == false).Select(x => x.Globber.ToString()); var includeGlobString = string.Join(",", includeGlobs); var excludeGlobString = string.Join(",", excludeGlobs); Log.LogMessage($"{task.PackageName} Include=\"{includeGlobString}\" Exclude=\"{excludeGlobString}\""); } foreach (var globTask in globTasks) { HandlePackage(globTask); } if (Written) { Write(); } } catch (Exception e) { Log.LogWarning($"Unexpected error while parsing patterns in '<OpenTapPackageReference>'. If the problem persists, please open an issue and include the build log."); Log.LogErrorFromException(e); throw; } return(true); }