$(PipelineCollectFilesPhaseDependsOn); CollectNugetPackageFiles; bin\%(RecursiveDir)%(Filename)%(Extension) (); // packaged used by the project try { foreach (var packageConfig in PackageConfigs) { var path = packageConfig.GetMetadata("FullPath"); var xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(path)); var deps = xml.GetElementsByTagName("package"); foreach (XmlNode dep in deps) { if (dep.Attributes == null) { continue; } var id = dep.Attributes.GetNamedItem("id").Value; if ("Baseclass.Contrib.Nuget.Output".Equals(id)) { continue; } var version = dep.Attributes.GetNamedItem("version").Value; var s = string.Format("{0}.{1}", id, version); usedPackages.Add(s); } } } catch (Exception e) { Log.LogError("Failed to load package files: {0}", e.Message); return false; } var usedNugetPackages = new List(); // list of nuget packages used by the project try { foreach (var nugetPackage in NugetPackages) { var path = nugetPackage.GetMetadata("FullPath"); var parts = path.Split(Path.DirectorySeparatorChar); usedNugetPackages.AddRange(from part in parts where usedPackages.Contains(part) select nugetPackage); } } catch (Exception e) { Log.LogError("Failed to filter nuget specs: {0}", e.Message); return false; } var result = new List(); // list of nuget packages used by the project that depends on Baseclass.Contrib.Nuget.Output foreach (var nugetPackage in usedNugetPackages) { var path = nugetPackage.GetMetadata("FullPath"); var nupkgpath = Path.GetDirectoryName(path); using (var archive = Package.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read)) { var nuspec = archive.GetParts().Single(part => part.Uri.ToString().EndsWith(".nuspec")); var nugetSpec = Path.Combine(nupkgpath, Path.GetFileName(nuspec.Uri.ToString())); // use a mutex to ensure that only one process unzip the nuspec // and that one process do not start reading it due to its existence while another one is still writing it. Mutex mut = new Mutex(false, "UnzipNuSpec"); try { mut.WaitOne(); if (!File.Exists(nugetSpec)) { // unpack the nuget spec file from the package try { using (var outputstream = new FileStream(nugetSpec, FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { using (var nspecstream = nuspec.GetStream()) { nspecstream.CopyTo(outputstream); } } } catch (IOException) { if (!File.Exists(nugetSpec)) { throw; } } } } finally { mut.ReleaseMutex(); } var xml = new XmlDocument(); xml.LoadXml(File.ReadAllText(nugetSpec)); var deps = xml.GetElementsByTagName("dependency"); foreach (XmlNode dep in deps) { if (dep.Attributes == null) { continue; } var id = dep.Attributes.GetNamedItem("id").Value; if ("Baseclass.Contrib.Nuget.Output".Equals(id)) { result.Add(new TaskItem(nugetPackage)); break; } } } } Result = result.ToArray(); return true; ]]>