Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix1444 #3

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
570 changes: 569 additions & 1 deletion NuGet.Clients.sln

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@
<Project>{306cddfa-ff0b-4299-930c-9ec6c9308160}</Project>
<Name>PackageManagement.VisualStudio</Name>
</ProjectReference>
<ProjectReference Include="..\VisualStudioAPI\VisualStudioAPI.csproj">
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudioAPI</Name>
<Name>VisualStudio</Name>
</ProjectReference>
<ProjectReference Include="..\VsConsole\Console.Types\Console.Types.csproj">
<Project>{6fd11460-39a3-4a10-ba63-7541b0a7d053}</Project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<RestoreNuGetPackages>true</RestoreNuGetPackages>
<PackagesDir>$(UserProfile)\.nuget\packages</PackagesDir>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<AssemblyOriginatorKeyFile>$(MS_PFX_PATH)</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>$(MS_PFX_PATH)</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '14.0'">
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
Expand Down Expand Up @@ -42,6 +42,7 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
Expand Down Expand Up @@ -147,6 +148,7 @@
<Compile Include="UserInterfaceService\NuGetUIProjectContext.cs" />
<Compile Include="UserSettings.cs" />
<Compile Include="Utility\NuGetUIThreadHelper.cs" />
<Compile Include="Utility\PackageManagerProviderUtility.cs" />
<Compile Include="Utility\RegistrySettingUtility.cs" />
<Compile Include="Utility\UIUtility.cs" />
<Compile Include="VersionForDisplay.cs" />
Expand Down Expand Up @@ -281,6 +283,12 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\build\common.targets" />
<Import Project="..\..\..\build\sign.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGet.PackageManagement.UI
{
Expand Down Expand Up @@ -37,5 +38,7 @@ public interface INuGetUIContext
/// </summary>
/// <param name="show">The value of the setting.</param>
void ApplyShowPreviewSetting(bool show);

IEnumerable<IVsPackageManagerProvider> PackageManagerProviders { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGet.PackageManagement.UI
{
Expand All @@ -14,6 +15,7 @@ namespace NuGet.PackageManagement.UI
public abstract class NuGetUIContextBase : INuGetUIContext
{
private readonly NuGetProject[] _projects;
private readonly IEnumerable<IVsPackageManagerProvider> _packageManagerProviders;

protected NuGetUIContextBase(
ISourceRepositoryProvider sourceProvider,
Expand All @@ -22,7 +24,8 @@ protected NuGetUIContextBase(
UIActionEngine uiActionEngine,
IPackageRestoreManager packageRestoreManager,
IOptionsPageActivator optionsPageActivator,
IEnumerable<NuGetProject> projects)
IEnumerable<NuGetProject> projects,
IEnumerable<IVsPackageManagerProvider> packageManagerProviders)
{
SourceProvider = sourceProvider;
SolutionManager = solutionManager;
Expand All @@ -32,6 +35,7 @@ protected NuGetUIContextBase(
PackageRestoreManager = packageRestoreManager;
OptionsPageActivator = optionsPageActivator;
_projects = projects.ToArray();
_packageManagerProviders = packageManagerProviders;
}

public ISourceRepositoryProvider SourceProvider { get; }
Expand All @@ -58,5 +62,10 @@ public IEnumerable<NuGetProject> Projects
public abstract void PersistSettings();

public abstract void ApplyShowPreviewSetting(bool show);

public IEnumerable<IVsPackageManagerProvider> PackageManagerProviders
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change this to be a read-only getter like SourceProvider

{
get { return _packageManagerProviders; }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Utilities;
using NuGet.VisualStudio;

namespace NuGet.PackageManagement.UI
{
public static class PackageManagerProviderUtility
{
public static List<IVsPackageManagerProvider> Sort(IEnumerable<Lazy<IVsPackageManagerProvider, IOrderable>> packageManagerProviders, int max)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Break long lines. Should be <= 120 chars

{
var sortedProviders = new List<IVsPackageManagerProvider>();
var uniqueId = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

foreach (var provider in Orderer.Order(packageManagerProviders))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
if (sortedProviders.Count < max && !uniqueId.Contains(provider.Value.PackageManagerId))
{
uniqueId.Add(provider.Value.PackageManagerId);
sortedProviders.Add(provider.Value);
}
}

return sortedProviders;
}
}
}
4 changes: 4 additions & 0 deletions src/NuGet.Clients/StandaloneUI/StandaloneUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
<Project>{538adefd-2170-40a9-a2c5-ec8369cfe490}</Project>
<Name>PackageManagement.UI</Name>
</ProjectReference>
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\build\common.targets" />
Expand Down
2 changes: 1 addition & 1 deletion src/NuGet.Clients/StandaloneUI/StandaloneUIContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public StandaloneUIContext(
IOptionsPageActivator optionsPageActivator,
IEnumerable<NuGetProject> projects)
:
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects)
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects, null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use parameter name when parameter value is null, true or false.
  2. Break long line

{
_settingsFile = settingsFile;
LoadSettings();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VisualStudioAPI\VisualStudioAPI.csproj">
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudioAPI</Name>
<Name>VisualStudio</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
47 changes: 47 additions & 0 deletions src/NuGet.Clients/VisualStudio/IVsPackageManagerProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;

namespace NuGet.VisualStudio
{
/// <summary>
/// Interface allowing integration of alternate package manager suggestion for a NuGet package.
/// For example jQuery may appear on Bower and it might be more appropriate to install a package from Bower for certain projects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please break long line here and in other places in your change as applicable

/// </summary>
[ComImport]
[Guid("BCED5BF2-40FC-4D9F-BF0A-43CD4E9FF65F")]
public interface IVsPackageManagerProvider
{
/// <summary>
/// Localized display package manager name.
/// </summary>
string PackageManagerName { get; }

/// <summary>
/// Package manager unique id.
/// </summary>
string PackageManagerId { get; }

/// <summary>
/// The tool tip description for the package
/// </summary>
string Description { get; }

/// <summary>
/// Check if a recommendation should be surfaced for an alternate package manager.
/// This code should not rely on slow network calls, and should return rapidly.
/// </summary>
/// <param name="packageId">Current package id</param>
/// <param name="projectName">Unique project name for finding the project through VS dte</param>
/// <param name="token">Cancellation Token</param>
/// <returns>return true if need to direct to integrated package manager for this package</returns>
Task<bool> CheckForPackage(string packageId, string projectName, CancellationToken token);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a convention to have a suffix 'async' when the return type is Task or Task. Consider changing this to 'CheckForPackageAsync' if possible.


/// <summary>
/// This Action should take the user to the other package manager.
/// </summary>
/// <param name="packageId">Current package id</param>
/// <param name="projectName">Unique project name for finding the project through VS dte</param>
void GoToPackage(string packageId, string projectName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
<Compile Include="Extensibility\IVsPackageRestorer.cs" />
<Compile Include="Extensibility\IVsPackageUninstaller.cs" />
<Compile Include="Extensibility\VsPackageEventHandler.cs" />
<Compile Include="IVsPackageManagerProvider.cs" />
<Compile Include="IRegistryKey.cs" />
<Compile Include="IVsTemplateWizard.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
6 changes: 4 additions & 2 deletions src/NuGet.Clients/VsExtension/VisualStudioUIContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using NuGet.PackageManagement.VisualStudio;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGetVSExtension
{
Expand All @@ -24,9 +25,10 @@ public VisualStudioUIContext(
UIActionEngine uiActionEngine,
IPackageRestoreManager packageRestoreManager,
IOptionsPageActivator optionsPageActivator,
IEnumerable<NuGetProject> projects)
IEnumerable<NuGetProject> projects,
IEnumerable<IVsPackageManagerProvider> packageManagerProviders)
:
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects)
base(sourceProvider, solutionManager, packageManager, uiActionEngine, packageRestoreManager, optionsPageActivator, projects, packageManagerProviders)
{
_package = package;
}
Expand Down
12 changes: 10 additions & 2 deletions src/NuGet.Clients/VsExtension/VisualStudioUIContextFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.VisualStudio.Utilities;
using NuGet.Configuration;
using NuGet.PackageManagement;
using NuGet.PackageManagement.UI;
using NuGet.ProjectManagement;
using NuGet.Protocol.Core.Types;
using NuGet.VisualStudio;

namespace NuGetVSExtension
{
Expand All @@ -22,21 +24,26 @@ internal class VisualStudioUIContextFactory : INuGetUIContextFactory
private readonly IOptionsPageActivator _optionsPage;
private readonly ISettings _settings;
private readonly IDeleteOnRestartManager _deleteOnRestartManager;
private readonly List<IVsPackageManagerProvider> _packageManagerProviders;
// only pick up at most three integrated package managers
private const int MaxPackageManager = 3;

[ImportingConstructor]
public VisualStudioUIContextFactory([Import] ISourceRepositoryProvider repositoryProvider,
[Import] ISolutionManager solutionManager,
[Import] ISettings settings,
[Import] IPackageRestoreManager packageRestoreManager,
[Import] IOptionsPageActivator optionsPage,
[Import] IDeleteOnRestartManager deleteOnRestartManager)
[Import] IDeleteOnRestartManager deleteOnRestartManager,
[ImportMany] IEnumerable<Lazy<IVsPackageManagerProvider, IOrderable>> packageManagerProviders)
{
_repositoryProvider = repositoryProvider;
_solutionManager = solutionManager;
_restoreManager = packageRestoreManager;
_optionsPage = optionsPage;
_settings = settings;
_deleteOnRestartManager = deleteOnRestartManager;
_packageManagerProviders = PackageManagerProviderUtility.Sort(packageManagerProviders, MaxPackageManager);
}

public INuGetUIContext Create(NuGetPackage package, IEnumerable<NuGetProject> projects)
Expand All @@ -62,7 +69,8 @@ public INuGetUIContext Create(NuGetPackage package, IEnumerable<NuGetProject> pr
actionEngine,
_restoreManager,
_optionsPage,
projects);
projects,
_packageManagerProviders);
}
}
}
7 changes: 4 additions & 3 deletions src/NuGet.Clients/VsExtension/VsExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@
<Project>{eea49a74-6efc-410e-9745-bad367ac151d}</Project>
<Name>VisualStudio14</Name>
</ProjectReference>
<ProjectReference Include="..\VisualStudioAPI\VisualStudioAPI.csproj">
<Project>{E5556BC6-A7FD-4D8E-8A7D-7648DF1D7471}</Project>
<Name>VisualStudioAPI</Name>
<ProjectReference Include="..\VisualStudio\VisualStudio.csproj">
<Project>{e5556bc6-a7fd-4d8e-8a7d-7648df1d7471}</Project>
<Name>VisualStudio</Name>
<IncludeOutputGroupsInVSIX>BuiltProjectOutputGroup%3bBuiltProjectOutputGroupDependencies%3bGetCopyToOutputDirectoryItems%3bSatelliteDllsProjectOutputGroup%3b</IncludeOutputGroupsInVSIX>
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup%3b</IncludeOutputGroupsInVSIXLocalOnly>
</ProjectReference>
Expand Down Expand Up @@ -206,6 +206,7 @@
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.VisualStudio.CoreUtility, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="Console" Path="|Console|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="PowerShellHostProvider" Path="|PowerShellHostProvider|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="File" Path="NuGet.Configuration.dll" />
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="VisualStudioAPI" Path="|VisualStudioAPI|" AssemblyName="|VisualStudioAPI;AssemblyName|" />
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="VisualStudio.Interop" Path="|VisualStudio.Interop|" AssemblyName="|VisualStudio.Interop;AssemblyName|" />
<Asset Type="Microsoft.VisualStudio.MefComponent" d:Source="Project" d:ProjectName="NuGet.VisualStudioImplement" Path="|NuGet.VisualStudio.Implementation|" />
<Asset Type="Microsoft.VisualStudio.Assembly" d:Source="Project" d:ProjectName="VisualStudio" Path="|VisualStudio|" AssemblyName="|VisualStudio;AssemblyName|" />
</Assets>
</PackageManifest>
Loading