Пример #1
0
        public async Task AddDependency(PickablePackageViewModel pickablePackageViewModel)
        {
            using (var transaction = UndoRedoService.CreateTransaction())
            {
                var dependency = pickablePackageViewModel.DependencyRange;

                // Check if package isn't a dependency yet
                if (Package.Container.DirectDependencies.Any(x => x.Name == dependency.Name))
                {
                    return;
                }

                var reference = new DirectDependencyReferenceViewModel(dependency, this, Dependencies, true);
                UndoRedoService.SetName(transaction, $"Add dependency to package '{reference.Name}'");

                // Update dependencies with NuGet
                if (Package.Container is SolutionProject project2)
                {
                    var log = new LoggerResult();
                    await VSProjectHelper.RestoreNugetPackages(log, project2.FullPath);

                    PackageSession.UpdateDependencies(project2, false, true);

                    // If the package is not part of session yet, make sure it gets added at this point
                    foreach (var projectDependency in project2.FlattenedDependencies)
                    {
                        if (projectDependency.Package == null && projectDependency.Type == DependencyType.Package)
                        {
                            var packageFile = PackageStore.Instance.GetPackageFileName(projectDependency.Name, new PackageVersionRange(projectDependency.Version));
                            if (packageFile != null && File.Exists(packageFile))
                            {
                                var dependencyPackageViewModel = await Session.AddExistingProject(packageFile);

                                projectDependency.Package = dependencyPackageViewModel.Package;
                            }
                        }
                    }
                }
            }
        }