提交 7731b162 编写于 作者: T Tom Meschter

Support adding PackageReferences to CPS projects

Add APIs to allow integration tests to add PackageReferences to CPS projects.
上级 35afa309
......@@ -89,6 +89,7 @@
<MicrosoftVisualStudioProgressionCodeSchemaVersion>15.0.26507-alpha</MicrosoftVisualStudioProgressionCodeSchemaVersion>
<MicrosoftVisualStudioProgressionCommonVersion>15.0.26507-alpha</MicrosoftVisualStudioProgressionCommonVersion>
<MicrosoftVisualStudioProgressionInterfacesVersion>15.0.26507-alpha</MicrosoftVisualStudioProgressionInterfacesVersion>
<MicrosoftVisualStudioProjectSystemVersion>15.0.751</MicrosoftVisualStudioProjectSystemVersion>
<MicrosoftVisualStudioQualityToolsUnitTestFrameworkVersion>10.0.0.0-alpha</MicrosoftVisualStudioQualityToolsUnitTestFrameworkVersion>
<MicrosoftVisualStudioRemoteControlVersion>14.0.249-master2E2DC10C</MicrosoftVisualStudioRemoteControlVersion>
<MicrosoftVisualStudioSetupConfigurationInteropVersion>1.3.269-rc</MicrosoftVisualStudioSetupConfigurationInteropVersion>
......
......@@ -30,4 +30,15 @@ public AssemblyReference(string name)
Name = name;
}
}
public class PackageReference : Identity
{
public string Version { get; }
public PackageReference(string name, string version)
{
Name = name;
Version = version;
}
}
}
......@@ -9,6 +9,7 @@
using System.Xml.Linq;
using EnvDTE80;
using Microsoft.CodeAnalysis;
using Microsoft.VisualStudio.ProjectSystem.Properties;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.TextManager.Interop;
......@@ -214,6 +215,38 @@ public void AddReference(string projectName, string fullyQualifiedAssemblyName)
((VSProject)project.Object).References.Add(fullyQualifiedAssemblyName);
}
public void AddPackageReference(string projectName, string packageName, string version)
{
var project = GetProject(projectName);
if (project.Object is IVsBrowseObjectContext browseObjectContext)
{
var threadingService = browseObjectContext.UnconfiguredProject.ProjectService.Services.ThreadingPolicy;
var packageService = browseObjectContext.ConfiguredProject.Services.PackageReferences;
var result = threadingService.ExecuteSynchronously(async () =>
{
return await packageService.AddAsync(packageName, version);
});
}
}
public void RemovePackageReference(string projectName, string packageName)
{
var project = GetProject(projectName);
if (project.Object is IVsBrowseObjectContext browseObjectContext)
{
var threadingService = browseObjectContext.UnconfiguredProject.ProjectService.Services.ThreadingPolicy;
var packageService = browseObjectContext.ConfiguredProject.Services.PackageReferences;
var result = threadingService.ExecuteSynchronously(async () =>
{
return await packageService.RemoveAsync(packageName);
});
}
}
public void RemoveProjectReference(string projectName, string projectReferenceName)
{
var project = GetProject(projectName);
......
......@@ -69,6 +69,20 @@ public void RemoveMetadataReference(ProjectUtils.AssemblyReference assemblyName,
_instance.Workspace.WaitForAsyncOperations(FeatureAttribute.Workspace);
}
/// <summary>
/// Add a PackageReference to the specified project. Generally this should be followed up by
/// a call to <see cref="RestoreNuGetPackages"/>.
/// </summary>
public void AddPackageReference(ProjectUtils.Project project, ProjectUtils.PackageReference package)
=> _inProc.AddPackageReference(project.Name, package.Name, package.Version);
/// <summary>
/// Remove a PackageReference from the specified project. Generally this should be followed up by
/// a call to <see cref="RestoreNuGetPackages"/>.
/// </summary>
public void RemovePackageReference(ProjectUtils.Project project, ProjectUtils.PackageReference package)
=> _inProc.RemovePackageReference(project.Name, package.Name);
public void CleanUpOpenSolution()
=> _inProc.CleanUpOpenSolution();
......
......@@ -129,6 +129,9 @@
<PackageReference Include="Microsoft.VisualStudio.OLE.Interop">
<Version>$(MicrosoftVisualStudioOLEInteropVersion)</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem">
<Version>$(MicrosoftVisualStudioProjectSystemVersion)</Version>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop">
<Version>$(MicrosoftVisualStudioSetupConfigurationInteropVersion)</Version>
</PackageReference>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册