Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
9582c433
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9582c433
编写于
4月 30, 2019
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Lazily load NuGet package source information
上级
07471570
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
89 addition
and
65 deletion
+89
-65
src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests_NuGet.cs
...EditorFeatures/CSharpTest/AddUsing/AddUsingTests_NuGet.cs
+7
-7
src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb
...alBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb
+7
-7
src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs
...re/Portable/AddImport/AbstractAddImportCodeFixProvider.cs
+1
-1
src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs
.../Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs
+1
-1
src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs
...udio/Core/Def/Packaging/PackageInstallerServiceFactory.cs
+70
-48
src/Workspaces/Core/Portable/Packaging/IPackageInstallerService.cs
...paces/Core/Portable/Packaging/IPackageInstallerService.cs
+3
-1
未找到文件。
src/EditorFeatures/CSharpTest/AddUsing/AddUsingTests_NuGet.cs
浏览文件 @
9582c433
...
...
@@ -55,7 +55,7 @@ public async Task TestSearchPackageSingleName()
installerServiceMock
.
Setup
(
i
=>
i
.
IsEnabled
(
It
.
IsAny
<
ProjectId
>())).
Returns
(
true
);
installerServiceMock
.
Setup
(
i
=>
i
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
)).
Returns
(
false
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
<
string
>.
Empty
);
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
TryInstallPackage
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
DocumentId
>(),
It
.
IsAny
<
string
>(),
"NuGetPackage"
,
It
.
IsAny
<
string
>(),
It
.
IsAny
<
bool
>(),
It
.
IsAny
<
CancellationToken
>()))
.
Returns
(
true
);
...
...
@@ -86,7 +86,7 @@ public async Task TestSearchPackageMultipleNames()
installerServiceMock
.
Setup
(
i
=>
i
.
IsEnabled
(
It
.
IsAny
<
ProjectId
>())).
Returns
(
true
);
installerServiceMock
.
Setup
(
i
=>
i
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
)).
Returns
(
false
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
<
string
>.
Empty
);
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
TryInstallPackage
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
DocumentId
>(),
It
.
IsAny
<
string
>(),
"NuGetPackage"
,
It
.
IsAny
<
string
>(),
It
.
IsAny
<
bool
>(),
It
.
IsAny
<
CancellationToken
>()))
.
Returns
(
true
);
...
...
@@ -115,7 +115,7 @@ public async Task TestMissingIfPackageAlreadyInstalled()
{
var
installerServiceMock
=
new
Mock
<
IPackageInstallerService
>(
MockBehavior
.
Strict
);
installerServiceMock
.
Setup
(
i
=>
i
.
IsEnabled
(
It
.
IsAny
<
ProjectId
>())).
Returns
(
true
);
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
))
.
Returns
(
true
);
...
...
@@ -141,7 +141,7 @@ public async Task TestOptionsOffered()
installerServiceMock
.
Setup
(
i
=>
i
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
)).
Returns
(
false
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
<
Solution
>(),
"NuGetPackage"
,
"1.0"
)).
Returns
(
Enumerable
.
Empty
<
Project
>());
installerServiceMock
.
Setup
(
i
=>
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
<
Solution
>(),
"NuGetPackage"
,
"2.0"
)).
Returns
(
Enumerable
.
Empty
<
Project
>());
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
GetInstalledVersions
(
"NuGetPackage"
))
.
Returns
(
ImmutableArray
.
Create
(
"1.0"
,
"2.0"
));
...
...
@@ -185,7 +185,7 @@ public async Task TestInstallGetsCalledNoVersion()
installerServiceMock
.
Setup
(
i
=>
i
.
IsEnabled
(
It
.
IsAny
<
ProjectId
>())).
Returns
(
true
);
installerServiceMock
.
Setup
(
i
=>
i
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
)).
Returns
(
false
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
<
string
>.
Empty
);
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
TryInstallPackage
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
DocumentId
>(),
It
.
IsAny
<
string
>(),
"NuGetPackage"
,
/*versionOpt*/
null
,
It
.
IsAny
<
bool
>(),
It
.
IsAny
<
CancellationToken
>()))
.
Returns
(
true
);
...
...
@@ -217,7 +217,7 @@ public async Task TestInstallGetsCalledWithVersion()
installerServiceMock
.
Setup
(
i
=>
i
.
IsEnabled
(
It
.
IsAny
<
ProjectId
>())).
Returns
(
true
);
installerServiceMock
.
Setup
(
i
=>
i
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
)).
Returns
(
false
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
<
Solution
>(),
"NuGetPackage"
,
"1.0"
)).
Returns
(
Enumerable
.
Empty
<
Project
>());
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
GetInstalledVersions
(
"NuGetPackage"
))
.
Returns
(
ImmutableArray
.
Create
(
"1.0"
));
installerServiceMock
.
Setup
(
s
=>
s
.
TryInstallPackage
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
DocumentId
>(),
It
.
IsAny
<
string
>(),
"NuGetPackage"
,
"1.0"
,
It
.
IsAny
<
bool
>(),
It
.
IsAny
<
CancellationToken
>()))
...
...
@@ -251,7 +251,7 @@ public async Task TestFailedInstallRollsBackFile()
installerServiceMock
.
Setup
(
i
=>
i
.
IsEnabled
(
It
.
IsAny
<
ProjectId
>())).
Returns
(
true
);
installerServiceMock
.
Setup
(
i
=>
i
.
IsInstalled
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
ProjectId
>(),
"NuGetPackage"
)).
Returns
(
false
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
<
Solution
>(),
"NuGetPackage"
,
"1.0"
)).
Returns
(
Enumerable
.
Empty
<
Project
>());
installerServiceMock
.
Setup
Get
(
i
=>
i
.
PackageSources
).
Returns
(
NugetPackageSources
);
installerServiceMock
.
Setup
(
i
=>
i
.
GetPackageSourcesAsync
(
It
.
IsAny
<
CancellationToken
>())).
Returns
(
new
ValueTask
<
ImmutableArray
<
PackageSource
>>(
NugetPackageSources
)
);
installerServiceMock
.
Setup
(
s
=>
s
.
GetInstalledVersions
(
"NuGetPackage"
))
.
Returns
(
ImmutableArray
.
Create
(
"1.0"
));
installerServiceMock
.
Setup
(
s
=>
s
.
TryInstallPackage
(
It
.
IsAny
<
Workspace
>(),
It
.
IsAny
<
DocumentId
>(),
It
.
IsAny
<
string
>(),
"NuGetPackage"
,
"1.0"
,
It
.
IsAny
<
bool
>(),
It
.
IsAny
<
CancellationToken
>()))
...
...
src/EditorFeatures/VisualBasicTest/Diagnostics/AddImport/AddImportTests_NuGet.vb
浏览文件 @
9582c433
...
...
@@ -50,7 +50,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.CodeActions.AddImp
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsEnabled
(
It
.
IsAny
(
Of
ProjectId
))).
Returns
(
True
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
ProjectId
),
"NuGetPackage"
)).
Returns
(
False
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
(
Of
String
).
Empty
)
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
TryInstallPackage
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
DocumentId
),
It
.
IsAny
(
Of
String
),
"NuGetPackage"
,
It
.
IsAny
(
Of
String
),
It
.
IsAny
(
Of
Boolean
),
It
.
IsAny
(
Of
CancellationToken
))).
Returns
(
True
)
...
...
@@ -79,7 +79,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsEnabled
(
It
.
IsAny
(
Of
ProjectId
))).
Returns
(
True
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
ProjectId
),
"NuGetPackage"
)).
Returns
(
False
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
(
Of
String
).
Empty
)
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
TryInstallPackage
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
DocumentId
),
It
.
IsAny
(
Of
String
),
"NuGetPackage"
,
It
.
IsAny
(
Of
String
),
It
.
IsAny
(
Of
Boolean
),
It
.
IsAny
(
Of
CancellationToken
))).
Returns
(
True
)
...
...
@@ -108,7 +108,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsEnabled
(
It
.
IsAny
(
Of
ProjectId
))).
Returns
(
True
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
ProjectId
),
"NuGetPackage"
)).
Returns
(
False
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
(
Of
String
).
Empty
)
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
TryInstallPackage
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
DocumentId
),
It
.
IsAny
(
Of
String
),
"NuGetPackage"
,
It
.
IsAny
(
Of
String
),
It
.
IsAny
(
Of
Boolean
),
It
.
IsAny
(
Of
CancellationToken
))).
Returns
(
False
)
...
...
@@ -133,7 +133,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
Public
Async
Function
TestMissingIfPackageAlreadyInstalled
()
As
Task
Dim
installerServiceMock
=
New
Mock
(
Of
IPackageInstallerService
)(
MockBehavior
.
Strict
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsEnabled
(
It
.
IsAny
(
Of
ProjectId
))).
Returns
(
True
)
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
)(),
It
.
IsAny
(
Of
ProjectId
)(),
"NuGetPackage"
)).
Returns
(
True
)
...
...
@@ -158,7 +158,7 @@ New TestParameters(fixProviderData:=New ProviderData(installerServiceMock.Object
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
ProjectId
),
"NuGetPackage"
)).
Returns
(
False
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
(
Of
Solution
),
"NuGetPackage"
,
"1.0"
)).
Returns
(
Enumerable
.
Empty
(
Of
Project
))
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
(
Of
Solution
),
"NuGetPackage"
,
"2.0"
)).
Returns
(
Enumerable
.
Empty
(
Of
Project
))
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
.
Create
(
"1.0"
,
"2.0"
))
...
...
@@ -200,7 +200,7 @@ parameters:=New TestParameters(index:=2, fixProviderData:=data))
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsEnabled
(
It
.
IsAny
(
Of
ProjectId
))).
Returns
(
True
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
ProjectId
),
"NuGetPackage"
)).
Returns
(
False
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
(
Of
String
).
Empty
)
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
TryInstallPackage
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
DocumentId
),
It
.
IsAny
(
Of
String
),
"NuGetPackage"
,
Nothing
,
It
.
IsAny
(
Of
Boolean
),
It
.
IsAny
(
Of
CancellationToken
))).
Returns
(
True
)
...
...
@@ -230,7 +230,7 @@ End Class", fixProviderData:=New ProviderData(installerServiceMock.Object, packa
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsEnabled
(
It
.
IsAny
(
Of
ProjectId
))).
Returns
(
True
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
IsInstalled
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
ProjectId
),
"NuGetPackage"
)).
Returns
(
False
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetProjectsWithInstalledPackage
(
It
.
IsAny
(
Of
Solution
),
"NuGetPackage"
,
"1.0"
)).
Returns
(
Enumerable
.
Empty
(
Of
Project
))
installerServiceMock
.
Setup
Get
(
Function
(
i
)
i
.
PackageSources
).
Returns
(
NugetPackageSources
)
installerServiceMock
.
Setup
(
Function
(
i
)
i
.
GetPackageSourcesAsync
(
It
.
IsAny
(
Of
CancellationToken
)())).
Returns
(
New
ValueTask
(
Of
ImmutableArray
(
Of
PackageSource
))(
NugetPackageSources
)
)
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
GetInstalledVersions
(
"NuGetPackage"
)).
Returns
(
ImmutableArray
.
Create
(
"1.0"
))
installerServiceMock
.
Setup
(
Function
(
s
)
s
.
TryInstallPackage
(
It
.
IsAny
(
Of
Workspace
),
It
.
IsAny
(
Of
DocumentId
),
It
.
IsAny
(
Of
String
),
"NuGetPackage"
,
"1.0"
,
It
.
IsAny
(
Of
Boolean
),
It
.
IsAny
(
Of
CancellationToken
))).
...
...
src/Features/Core/Portable/AddImport/AbstractAddImportCodeFixProvider.cs
浏览文件 @
9582c433
...
...
@@ -55,7 +55,7 @@ public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
var
installerService
=
GetPackageInstallerService
(
document
);
var
packageSources
=
searchNuGetPackages
&&
symbolSearchService
!=
null
&&
installerService
!=
null
?
installerService
.
PackageSources
?
await
installerService
.
GetPackageSourcesAsync
(
cancellationToken
).
ConfigureAwait
(
false
)
:
ImmutableArray
<
PackageSource
>.
Empty
;
var
fixesForDiagnostic
=
await
addImportService
.
GetFixesForDiagnosticsAsync
(
...
...
src/Features/Core/Portable/AddPackage/AbstractAddPackageCodeFixProvider.cs
浏览文件 @
9582c433
...
...
@@ -56,7 +56,7 @@ internal abstract partial class AbstractAddPackageCodeFixProvider : CodeFixProvi
searchNugetPackages
&&
installerService
.
IsEnabled
(
document
.
Project
.
Id
))
{
foreach
(
var
packageSource
in
installerService
.
PackageSources
)
foreach
(
var
packageSource
in
await
installerService
.
GetPackageSourcesAsync
(
cancellationToken
).
ConfigureAwait
(
false
)
)
{
cancellationToken
.
ThrowIfCancellationRequested
();
...
...
src/VisualStudio/Core/Def/Packaging/PackageInstallerServiceFactory.cs
浏览文件 @
9582c433
...
...
@@ -48,10 +48,17 @@ internal partial class PackageInstallerService : AbstractDelayStartedService, IP
private
readonly
SVsServiceProvider
_serviceProvider
;
private
readonly
IVsEditorAdaptersFactoryService
_editorAdaptersFactoryService
;
private
readonly
Lazy
<
IVsPackageInstallerServices
>
_packageInstallerServices
;
private
readonly
Lazy
<
IVsPackageInstaller2
>
_packageInstaller
;
private
readonly
Lazy
<
IVsPackageUninstaller
>
_packageUninstaller
;
private
readonly
Lazy
<
IVsPackageSourceProvider
>
_packageSourceProvider
;
// We refer to the package services through proxy types so that we can
// delay loading their DLLs until we actually need them.
private
IPackageServicesProxy
_packageServices
;
private
ImmutableArray
<
PackageSource
>
_packageSources
;
private
CancellationTokenSource
_tokenSource
=
new
CancellationTokenSource
();
// We keep track of what types of changes we've seen so we can then determine what to
...
...
@@ -69,7 +76,11 @@ internal partial class PackageInstallerService : AbstractDelayStartedService, IP
IThreadingContext
threadingContext
,
VisualStudioWorkspaceImpl
workspace
,
SVsServiceProvider
serviceProvider
,
IVsEditorAdaptersFactoryService
editorAdaptersFactoryService
)
IVsEditorAdaptersFactoryService
editorAdaptersFactoryService
,
[
Import
(
AllowDefault
=
true
)]
Lazy
<
IVsPackageInstallerServices
>
packageInstallerServices
,
[
Import
(
AllowDefault
=
true
)]
Lazy
<
IVsPackageInstaller2
>
packageInstaller
,
[
Import
(
AllowDefault
=
true
)]
Lazy
<
IVsPackageUninstaller
>
packageUninstaller
,
[
Import
(
AllowDefault
=
true
)]
Lazy
<
IVsPackageSourceProvider
>
packageSourceProvider
)
:
base
(
threadingContext
,
workspace
,
SymbolSearchOptions
.
Enabled
,
SymbolSearchOptions
.
SuggestForTypesInReferenceAssemblies
,
SymbolSearchOptions
.
SuggestForTypesInNuGetPackages
)
...
...
@@ -77,9 +88,44 @@ internal partial class PackageInstallerService : AbstractDelayStartedService, IP
_workspace
=
workspace
;
_serviceProvider
=
serviceProvider
;
_editorAdaptersFactoryService
=
editorAdaptersFactoryService
;
_packageInstallerServices
=
packageInstallerServices
;
_packageInstaller
=
packageInstaller
;
_packageUninstaller
=
packageUninstaller
;
_packageSourceProvider
=
packageSourceProvider
;
}
public
ImmutableArray
<
PackageSource
>
PackageSources
{
get
;
private
set
;
}
=
ImmutableArray
<
PackageSource
>.
Empty
;
public
async
ValueTask
<
ImmutableArray
<
PackageSource
>>
GetPackageSourcesAsync
(
CancellationToken
cancellationToken
)
{
var
packageSources
=
_packageSources
;
if
(
packageSources
!=
null
)
{
return
packageSources
;
}
try
{
await
ThreadingContext
.
JoinableTaskFactory
.
SwitchToMainThreadAsync
(
cancellationToken
);
cancellationToken
.
ThrowIfCancellationRequested
();
packageSources
=
_packageServices
.
GetSources
(
includeUnOfficial
:
true
,
includeDisabled
:
false
)
.
Select
(
r
=>
new
PackageSource
(
r
.
Key
,
r
.
Value
))
.
ToImmutableArrayOrEmpty
();
}
catch
(
Exception
ex
)
when
(
ex
is
InvalidDataException
||
ex
is
InvalidOperationException
)
{
// These exceptions can happen when the nuget.config file is broken.
packageSources
=
ImmutableArray
<
PackageSource
>.
Empty
;
}
var
previousPackageSources
=
ImmutableInterlocked
.
InterlockedCompareExchange
(
ref
_packageSources
,
packageSources
,
default
);
if
(
previousPackageSources
!=
null
)
{
// Another thread already initialized _packageSources
packageSources
=
previousPackageSources
;
}
return
packageSources
;
}
public
event
EventHandler
PackageSourcesChanged
;
...
...
@@ -106,21 +152,16 @@ protected override void EnableService()
// Our service has been enabled. Now load the VS package dlls.
var
componentModel
=
(
IComponentModel
)
_serviceProvider
.
GetService
(
typeof
(
SComponentModel
));
var
packageInstallerServices
=
componentModel
.
GetExtensions
<
IVsPackageInstallerServices
>().
FirstOrDefault
();
var
packageInstaller
=
componentModel
.
GetExtensions
<
IVsPackageInstaller2
>().
FirstOrDefault
();
var
packageUninstaller
=
componentModel
.
GetExtensions
<
IVsPackageUninstaller
>().
FirstOrDefault
();
var
packageSourceProvider
=
componentModel
.
GetExtensions
<
IVsPackageSourceProvider
>().
FirstOrDefault
();
if
(
packageInstallerServices
==
null
||
packageInstaller
==
null
||
packageUninstaller
==
null
||
packageSourceProvider
==
null
)
if
(
_packageInstallerServices
==
null
||
_packageInstaller
==
null
||
_packageUninstaller
==
null
||
_packageSourceProvider
==
null
)
{
return
;
}
_packageServices
=
new
PackageServicesProxy
(
packageInstallerServices
,
packageInstaller
,
packageUninstaller
,
packageSourceProvider
);
_packageInstallerServices
,
_packageInstaller
,
_packageUninstaller
,
_
packageSourceProvider
);
// Start listening to additional events workspace changes.
_workspace
.
WorkspaceChanged
+=
OnWorkspaceChanged
;
...
...
@@ -143,26 +184,7 @@ protected override void StartWorking()
private
void
OnSourceProviderSourcesChanged
(
object
sender
,
EventArgs
e
)
{
if
(!
this
.
IsForeground
())
{
this
.
InvokeBelowInputPriorityAsync
(()
=>
OnSourceProviderSourcesChanged
(
sender
,
e
));
return
;
}
this
.
AssertIsForeground
();
try
{
PackageSources
=
_packageServices
.
GetSources
(
includeUnOfficial
:
true
,
includeDisabled
:
false
)
.
Select
(
r
=>
new
PackageSource
(
r
.
Key
,
r
.
Value
))
.
ToImmutableArrayOrEmpty
();
}
catch
(
Exception
ex
)
when
(
ex
is
InvalidDataException
||
ex
is
InvalidOperationException
)
{
// These exceptions can happen when the nuget.config file is broken.
PackageSources
=
ImmutableArray
<
PackageSource
>.
Empty
;
}
_packageSources
=
default
;
PackageSourcesChanged
?.
Invoke
(
this
,
EventArgs
.
Empty
);
}
...
...
@@ -659,16 +681,16 @@ public uint GetTokens(uint dwMaxTokens, IVsSearchToken[] rgpSearchTokens)
private
class
PackageServicesProxy
:
IPackageServicesProxy
{
private
readonly
IVsPackageInstaller2
_packageInstaller
;
private
readonly
IVsPackageInstallerServices
_packageInstallerServices
;
private
readonly
IVsPackageSourceProvider
_packageSourceProvider
;
private
readonly
IVsPackageUninstaller
_packageUninstaller
;
private
readonly
Lazy
<
IVsPackageInstaller2
>
_packageInstaller
;
private
readonly
Lazy
<
IVsPackageInstallerServices
>
_packageInstallerServices
;
private
readonly
Lazy
<
IVsPackageSourceProvider
>
_packageSourceProvider
;
private
readonly
Lazy
<
IVsPackageUninstaller
>
_packageUninstaller
;
public
PackageServicesProxy
(
IVsPackageInstallerServices
packageInstallerServices
,
IVsPackageInstaller2
packageInstaller
,
IVsPackageUninstaller
packageUninstaller
,
IVsPackageSourceProvider
packageSourceProvider
)
Lazy
<
IVsPackageInstallerServices
>
packageInstallerServices
,
Lazy
<
IVsPackageInstaller2
>
packageInstaller
,
Lazy
<
IVsPackageUninstaller
>
packageUninstaller
,
Lazy
<
IVsPackageSourceProvider
>
packageSourceProvider
)
{
_packageInstallerServices
=
packageInstallerServices
;
_packageInstaller
=
packageInstaller
;
...
...
@@ -680,36 +702,36 @@ private class PackageServicesProxy : IPackageServicesProxy
{
add
{
_packageSourceProvider
.
SourcesChanged
+=
value
;
_packageSourceProvider
.
Value
.
SourcesChanged
+=
value
;
}
remove
{
_packageSourceProvider
.
SourcesChanged
-=
value
;
_packageSourceProvider
.
Value
.
SourcesChanged
-=
value
;
}
}
public
IEnumerable
<
PackageMetadata
>
GetInstalledPackages
(
EnvDTE
.
Project
project
)
{
return
_packageInstallerServices
.
GetInstalledPackages
(
project
)
return
_packageInstallerServices
.
Value
.
GetInstalledPackages
(
project
)
.
Select
(
m
=>
new
PackageMetadata
(
m
.
Id
,
m
.
VersionString
))
.
ToList
();
}
public
bool
IsPackageInstalled
(
EnvDTE
.
Project
project
,
string
id
)
=>
_packageInstallerServices
.
IsPackageInstalled
(
project
,
id
);
=>
_packageInstallerServices
.
Value
.
IsPackageInstalled
(
project
,
id
);
public
void
InstallPackage
(
string
source
,
EnvDTE
.
Project
project
,
string
packageId
,
string
version
,
bool
ignoreDependencies
)
=>
_packageInstaller
.
InstallPackage
(
source
,
project
,
packageId
,
version
,
ignoreDependencies
);
=>
_packageInstaller
.
Value
.
InstallPackage
(
source
,
project
,
packageId
,
version
,
ignoreDependencies
);
public
void
InstallLatestPackage
(
string
source
,
EnvDTE
.
Project
project
,
string
packageId
,
bool
includePrerelease
,
bool
ignoreDependencies
)
=>
_packageInstaller
.
InstallLatestPackage
(
source
,
project
,
packageId
,
includePrerelease
,
ignoreDependencies
);
=>
_packageInstaller
.
Value
.
InstallLatestPackage
(
source
,
project
,
packageId
,
includePrerelease
,
ignoreDependencies
);
public
IEnumerable
<
KeyValuePair
<
string
,
string
>>
GetSources
(
bool
includeUnOfficial
,
bool
includeDisabled
)
=>
_packageSourceProvider
.
GetSources
(
includeUnOfficial
,
includeDisabled
);
=>
_packageSourceProvider
.
Value
.
GetSources
(
includeUnOfficial
,
includeDisabled
);
public
void
UninstallPackage
(
EnvDTE
.
Project
project
,
string
packageId
,
bool
removeDependencies
)
=>
_packageUninstaller
.
UninstallPackage
(
project
,
packageId
,
removeDependencies
);
=>
_packageUninstaller
.
Value
.
UninstallPackage
(
project
,
packageId
,
removeDependencies
);
}
}
}
src/Workspaces/Core/Portable/Packaging/IPackageInstallerService.cs
浏览文件 @
9582c433
...
...
@@ -4,6 +4,7 @@
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Host
;
using
Roslyn.Utilities
;
...
...
@@ -26,7 +27,8 @@ internal interface IPackageInstallerService : IWorkspaceService
void
ShowManagePackagesDialog
(
string
packageName
);
ImmutableArray
<
PackageSource
>
PackageSources
{
get
;
}
ValueTask
<
ImmutableArray
<
PackageSource
>>
GetPackageSourcesAsync
(
CancellationToken
cancellationToken
);
event
EventHandler
PackageSourcesChanged
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录