Exemple #1
0
        private async void AddPackage(object sender, RoutedEventArgs e)
        {
            Init();
            try
            {
                var nuGetProject = SolutionManager.DefaultNuGetProject;
                if (nuGetProject != null)
                {
                    MessageBox.Show("You want to add package " + AddPackageId.Text + "." + AddPackageVersion.Text);
                    var packageIdentity = new PackageIdentity(AddPackageId.Text, new NuGetVersion(AddPackageVersion.Text));

                    var packagePath = GetPackagePathFromMachineCache(packageIdentity);
                    if (File.Exists(packagePath))
                    {
                        using (var packageStream = File.OpenRead(packagePath))
                        {
                            await nuGetProject.InstallPackageAsync(packageIdentity, packageStream, MyControlNuGetProjectContext, CancellationToken.None);
                        }
                    }
                    else
                    {
                        MessageBox.Show("Package could not be found in machine cache");
                    }
                }
                else
                {
                    MessageBox.Show("No default NuGetProject available");
                }
            }
            catch (Exception ex)
            {
                MyControlNuGetProjectContext.Log(MessageLevel.Error, ex.ToString());
            }
        }
Exemple #2
0
        private async void RemovePackage(object sender, RoutedEventArgs e)
        {
            Init();
            try
            {
                var nuGetProject = SolutionManager.DefaultNuGetProject;
                if (nuGetProject != null)
                {
                    var addedPackageReference = (await nuGetProject.GetInstalledPackagesAsync(CancellationToken.None))
                                                .Where(i => RemovePackageId.Text.Equals(i.PackageIdentity.Id, StringComparison.OrdinalIgnoreCase))
                                                .FirstOrDefault();

                    if (addedPackageReference != null)
                    {
                        MessageBox.Show("You want to remove package " + addedPackageReference.PackageIdentity);
                        await nuGetProject.UninstallPackageAsync(addedPackageReference.PackageIdentity,
                                                                 MyControlNuGetProjectContext, CancellationToken.None);
                    }
                    else
                    {
                        MessageBox.Show("No version of package " + RemovePackageId.Text + " is found in the project");
                    }
                }
                else
                {
                    MessageBox.Show("No default NuGetProject available");
                }
            }
            catch (Exception ex)
            {
                MyControlNuGetProjectContext.Log(MessageLevel.Error, ex.ToString());
            }
        }
Exemple #3
0
 private void Init()
 {
     if (_initNeeded)
     {
         _initNeeded = false;
         //SolutionManager = new VSSolutionManager();
         SolutionManager = ServiceLocator.GetInstance <ISolutionManager>();
         MyControlNuGetProjectContext = new MyControlNuGetProjectContext(this);
     }
 }