Пример #1
0
        private void UpdateUnresolvedDependencies(ProjectState state, bool allowRestore)
        {
            var libraryManager      = state.ProjectContext.LibraryManager;
            var allDiagnostics      = libraryManager.GetAllDiagnostics();
            var unresolvedLibraries = libraryManager.GetLibraries().Where(dep => !dep.Resolved);
            var needRestore         = allDiagnostics.Any(diag => diag.ErrorCode == ErrorCodes.NU1006) || unresolvedLibraries.Any();

            if (needRestore)
            {
                var unresolvedDependencies = unresolvedLibraries.Select(library =>
                                                                        new PackageDependency
                {
                    Name    = library.Identity.Name,
                    Version = library.Identity.Version?.ToString()
                });

                var projectFile = state.ProjectContext.ProjectFile;

                if (allowRestore && _enableRestorePackages)
                {
                    _dotNetCliService.RestoreAsync(projectFile.ProjectDirectory, onFailure: () =>
                    {
                        _eventEmitter.UnresolvedDepdendencies(projectFile.ProjectFilePath, unresolvedDependencies);
                    });
                }
                else
                {
                    _eventEmitter.UnresolvedDepdendencies(projectFile.ProjectFilePath, unresolvedDependencies);
                }
            }
        }
Пример #2
0
        private void CheckForUnresolvedDependences(ProjectFileInfo projectFile, bool allowAutoRestore)
        {
            var unresolvedPackageReferences = _packageDepedencyResolver.FindUnresolvedPackageReferences(projectFile);

            if (unresolvedPackageReferences.IsEmpty)
            {
                return;
            }

            var unresolvedDependencies = unresolvedPackageReferences.Select(packageReference =>
                                                                            new PackageDependency
            {
                Name    = packageReference.Dependency.Id,
                Version = packageReference.Dependency.VersionRange.ToNormalizedString()
            });

            if (allowAutoRestore && _options.EnablePackageAutoRestore)
            {
                _dotNetCli.RestoreAsync(projectFile.Directory, onFailure: () =>
                {
                    _eventEmitter.UnresolvedDepdendencies(projectFile.FilePath, unresolvedDependencies);
                });
            }
            else
            {
                _eventEmitter.UnresolvedDepdendencies(projectFile.FilePath, unresolvedDependencies);
            }
        }
Пример #3
0
        public async Task Given_a_restored_project_the_references_are_emitted()
        {
            var emitter = new ProjectLoadTestEventEmitter();

            using var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld");

            var dotnetCliService = new DotNetCliService(LoggerFactory, emitter);
            await dotnetCliService.RestoreAsync(testProject.Directory);

            using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory));
            Assert.Single(emitter.ReceivedMessages);
            Assert.NotEmpty(emitter.ReceivedMessages[0].References.Where(reference => reference == GetHashedReference("system.core")));
        }
        public async Task Given_a_restored_project_the_references_are_emitted()
        {
            var messages = new List <ProjectConfigurationMessage>();
            var emitter  = new ProjectLoadTestEventEmitter(messages);

            var listener = new ProjectLoadListener(LoggerFactory, emitter);
            var exports  = new ExportDescriptorProvider[]
            {
                MefValueProvider.From <IMSBuildEventSink>(listener)
            };

            using (var testProject = await TestAssets.Instance.GetTestProjectAsync("HelloWorld"))
            {
                var dotnetCliService = new DotNetCliService(LoggerFactory, emitter);
                await dotnetCliService.RestoreAsync(testProject.Directory);

                using (var host = CreateMSBuildTestHost(testProject.Directory, exports))
                {
                    Assert.Single(messages);
                    Assert.NotEmpty(messages[0].References.Where(reference => reference == GetHashedReference("system.core")));
                }
            }
        }