Repository navigation
Expand file tree
/
Copy pathNuGetAwareProjectPackageRepository.cs
More file actions
114 lines (100 loc) · 3.16 KB
/
Copy pathNuGetAwareProjectPackageRepository.cs
File metadata and controls
114 lines (100 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.ProjectSystem.Interop;
namespace NuGet.VisualStudio
{
class NuGetAwareProjectPackageRepository : IPackageRepository, IPackageReferenceRepository2
{
INuGetPackageManager _project;
ISharedPackageRepository _repo;
public NuGetAwareProjectPackageRepository(INuGetPackageManager project, ISharedPackageRepository sourceRepository)
{
_project = project;
_repo = sourceRepository;
}
public string Source
{
get { return "ICanSupportNuGet"; }
}
public PackageSaveModes PackageSaveMode
{
get
{
throw new NotSupportedException();
}
set
{
throw new NotSupportedException();
}
}
public bool SupportsPrereleasePackages
{
get { return true; }
}
public IQueryable<IPackage> GetPackages()
{
CancellationTokenSource cts = new CancellationTokenSource();
var task = _project.GetInstalledPackagesAsync(cts.Token);
task.Wait();
List<IPackage> packages = new List<IPackage>();
foreach (object item in task.Result)
{
var moniker = item as INuGetPackageMoniker;
if (moniker != null)
{
packages.Add(new DataServicePackage()
{
Id = moniker.Id,
Version = moniker.Version
});
continue;
}
var fileName = item as string;
if (item != null)
{
packages.Add(new OptimizedZipPackage(fileName));
}
}
return packages.AsQueryable();
}
public void AddPackage(IPackage package)
{
// no-op
}
public void RemovePackage(IPackage package)
{
// no-op
}
public PackageReference GetPackageReference(string packageId)
{
var package = GetPackages().Where(p => string.Equals(p.Id, packageId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (package == null)
{
return null;
}
var packageReference = new PackageReference(
package.Id,
package.Version,
versionConstraint: null,
targetFramework: null,
isDevelopmentDependency: false);
return packageReference;
}
public IEnumerable<PackageReference> GetPackageReferences(string packageId)
{
var packageReference = GetPackageReference(packageId);
if (packageReference == null)
{
return Enumerable.Empty<PackageReference>();
}
else
{
return new[] { packageReference };
}
}
}
}