33using Clide ;
44using System . Windows ;
55using Microsoft . VisualStudio . Shell ;
6+ using NuGet . VisualStudio ;
67
78namespace NuGet . Packaging . VisualStudio
89{
@@ -12,17 +13,23 @@ class AddPlatformImplementationCommand : DynamicCommand
1213 readonly ISolutionExplorer solutionExplorer ;
1314 readonly IDialogService dialogService ;
1415 readonly IPlatformProvider platformProvider ;
16+ readonly IVsPackageInstaller packageInstaller ;
17+ readonly IVsPackageInstallerServices packageInstallerServices ;
1518
1619 [ ImportingConstructor ]
1720 public AddPlatformImplementationCommand (
1821 ISolutionExplorer solutionExplorer ,
1922 IPlatformProvider platformProvider ,
20- IDialogService dialogService )
23+ IDialogService dialogService ,
24+ IVsPackageInstaller packageInstaller ,
25+ IVsPackageInstallerServices packageInstallerServices )
2126 : base ( Commands . AddPlatformImplementationCommandId )
2227 {
2328 this . solutionExplorer = solutionExplorer ;
2429 this . platformProvider = platformProvider ;
2530 this . dialogService = dialogService ;
31+ this . packageInstaller = packageInstaller ;
32+ this . packageInstallerServices = packageInstallerServices ;
2633 }
2734
2835 protected override void Execute ( )
@@ -65,11 +72,13 @@ protected override void Execute()
6572 if ( context . NuGetProject == null )
6673 {
6774 context . NuGetProject = solutionExplorer . Solution . UnfoldTemplate (
68- Constants . Templates . NuGetPackage , context . NuGetProjectName , Constants . Language ) ;
75+ Constants . Templates . NuGetPackage , context . NuGetProjectName ) ;
6976 }
7077
7178 context . NuGetProject . AddReference ( context . SelectedProject ) ;
7279
80+ EnsureBuildPackagingNugetInstalled ( context . SelectedProject ) ;
81+
7382 foreach ( var selectedPlatform in viewModel . Platforms . Where ( x => x . IsEnabled && x . IsSelected ) )
7483 {
7584 var projectName = context . GetTargetProjectName ( selectedPlatform ) ;
@@ -80,6 +89,8 @@ protected override void Execute()
8089 Constants . Templates . GetPlatformTemplate ( selectedPlatform . Id ) ,
8190 projectName ) ;
8291
92+ EnsureBuildPackagingNugetInstalled ( project ) ;
93+
8394 if ( context . SharedProject != null && viewModel . UseSharedProject )
8495 project . AddReference ( context . SharedProject ) ;
8596
@@ -88,6 +99,14 @@ protected override void Execute()
8899 }
89100 }
90101
102+ void EnsureBuildPackagingNugetInstalled ( IProjectNode project )
103+ {
104+ var dteProject = project . As < EnvDTE . Project > ( ) ;
105+
106+ if ( ! packageInstallerServices . IsBuildPackagingNuGetInstalled ( dteProject ) )
107+ packageInstaller . InstallBuildPackagingNuget ( dteProject ) ;
108+ }
109+
91110 IProjectNode ActiveProject => solutionExplorer . Solution . ActiveProject ;
92111
93112 protected override void CanExecute ( OleMenuCommand command ) =>
0 commit comments