提交 347fff9c 编写于 作者: T Tom Meschter

Go through the unconfigured project to get the configured project

We're trying to go from an `IVsBrowseObjectContext` to an `IPackageReferencesService`.
We were doing this through `IVsBrowseObjectContext.ConfiguredProject`, but it turns out
that this property always returns null on the particular implementation of
`IVsBrowseObjectContext` we're working with.

Instead, we need to go through the `UnconfiguredProject` and ask it for the "suggested"
`ConfiguredProject`.

I've also switched from `GetAwaiter().GetResult()` to properly async/await code inside
an `ExecuteSynchronously` call, mostly for the purposes of readability.
上级 f1af5ae3
......@@ -221,9 +221,13 @@ public void AddPackageReference(string projectName, string packageName, string v
if (project is IVsBrowseObjectContext browseObjectContext)
{
var packageService = browseObjectContext.ConfiguredProject.Services.PackageReferences;
var threadingService = browseObjectContext.UnconfiguredProject.ProjectService.Services.ThreadingPolicy;
var result = packageService.AddAsync(packageName, version).GetAwaiter().GetResult();
var result = threadingService.ExecuteSynchronously(async () =>
{
var configuredProject = await browseObjectContext.UnconfiguredProject.GetSuggestedConfiguredProjectAsync();
return await configuredProject.Services.PackageReferences.AddAsync(packageName, version);
});
}
else
{
......@@ -237,9 +241,13 @@ public void RemovePackageReference(string projectName, string packageName)
if (project is IVsBrowseObjectContext browseObjectContext)
{
var packageService = browseObjectContext.ConfiguredProject.Services.PackageReferences;
var threadingService = browseObjectContext.UnconfiguredProject.ProjectService.Services.ThreadingPolicy;
packageService.RemoveAsync(packageName).GetAwaiter().GetResult();
threadingService.ExecuteSynchronously(async () =>
{
var configuredProject = await browseObjectContext.UnconfiguredProject.GetSuggestedConfiguredProjectAsync();
await configuredProject.Services.PackageReferences.RemoveAsync(packageName);
});
}
else
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册