public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync(
            Common.ILogger logger, CancellationToken _)
        {
            var results = new List <ProjectRestoreReference>();

            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var vcProject = await _vcProject.GetValueAsync();

            var  references           = vcProject.VCReferences as VCReferences;
            var  projectReferences    = references.GetReferencesOfType((uint)vcRefType.VCRT_PROJECT);
            bool hasMissingReferences = false;

            foreach (var reference in projectReferences)
            {
                try
                {
                    var vcReference = reference as VCProjectReference;
                    if (vcReference.UseInBuild)
                    {
                        if (vcReference.ReferencedProject != null)
                        {
                            var referencedProject       = vcReference.ReferencedProject as Project;
                            var childProjectPath        = referencedProject.FileName;
                            var projectRestoreReference = new ProjectRestoreReference()
                            {
                                ProjectPath       = childProjectPath,
                                ProjectUniqueName = childProjectPath
                            };

                            results.Add(projectRestoreReference);
                        }
                        else
                        {
                            hasMissingReferences = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    hasMissingReferences = true;

                    logger.LogDebug(ex.ToString());
                }
            }

            if (hasMissingReferences)
            {
                // Log a generic message once per project if any items could not be resolved.
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.UnresolvedItemDuringProjectClosureWalk,
                    _vsProjectAdapter.UniqueName);

                logger.LogVerbose(message);
            }

            return(results);
        }
        public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync(
            Common.ILogger logger, CancellationToken _)
        {
            var unconfiguredProject = await _unconfiguredProject.GetValueAsync();

            IBuildDependencyProjectReferencesService service = await GetProjectReferencesService(unconfiguredProject);

            if (service == null)
            {
                return(Enumerable.Empty <ProjectRestoreReference>());
            }

            var results = new List <ProjectRestoreReference>();
            var hasMissingReferences = false;

            foreach (IUnresolvedBuildDependencyProjectReference projectReference in await service.GetUnresolvedReferencesAsync())
            {
                try
                {
                    if (await projectReference.GetReferenceOutputAssemblyAsync())
                    {
                        string childProjectPath        = projectReference.EvaluatedIncludeAsFullPath;
                        var    projectRestoreReference = new ProjectRestoreReference()
                        {
                            ProjectPath       = childProjectPath,
                            ProjectUniqueName = childProjectPath
                        };

                        results.Add(projectRestoreReference);
                    }
                }
                catch (Exception ex)
                {
                    hasMissingReferences = true;
                    logger.LogDebug(ex.ToString());
                }
            }

            if (hasMissingReferences)
            {
                // Log a generic message once per project if any items could not be resolved.
                // In most cases this can be ignored, but in the rare case where the unresolved
                // item is actually a project the restore result will be incomplete.
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.UnresolvedItemDuringProjectClosureWalk,
                    _vsProjectAdapter.UniqueName);

                logger.LogVerbose(message);
            }

            return(results);
        }
示例#3
0
        public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync(
            Common.ILogger logger, CancellationToken _)
        {
            // DTE calls need to be done from the main thread
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var results = new List <ProjectRestoreReference>();
            var hasMissingReferences = false;
            var hasProjectsWithUnresolvedMetadata = false;

            // find all references in the project
            foreach (var childReference in GetVSProjectReferences())
            {
                try
                {
                    var reference3 = childReference as Reference3;

                    // Verify that this is a project reference
                    if (IsProjectReference(reference3, logger))
                    {
                        // Verify that this is a valid and resolved project reference
                        if (!IsReferenceResolved(reference3, logger))
                        {
                            hasMissingReferences = true;
                            continue;
                        }

                        if (await EnvDTEProjectUtility.HasUnsupportedProjectCapabilityAsync(reference3.SourceProject))
                        {
                            // Skip this shared project
                            continue;
                        }

                        var childProjectPath = reference3.SourceProject.GetFullProjectPath();

                        // Skip projects which have ReferenceOutputAssembly=false
                        var addProject = true;

                        if (childReference is Reference6 reference6)
                        {
                            reference6.GetMetadata(_referenceMetadata, out Array _, out Array metadataValues);
                            var referenceOutputAssembly = GetReferenceMetadataValue(metadataValues);
                            addProject = string.IsNullOrEmpty(referenceOutputAssembly) ||
                                         !string.Equals(bool.FalseString, referenceOutputAssembly, StringComparison.OrdinalIgnoreCase);
                        }
                        else
                        {
                            hasProjectsWithUnresolvedMetadata = true;
                        }

                        if (addProject)
                        {
                            results.Add(new ProjectRestoreReference()
                            {
                                ProjectPath       = childProjectPath,
                                ProjectUniqueName = childProjectPath
                            });
                        }
                    }
                    else
                    {
                        hasMissingReferences = true;
                    }
                }
                catch (Exception ex)
                {
                    // Exceptions are expected in some scenarios for native projects,
                    // ignore them and show a warning
                    hasMissingReferences = true;

                    logger.LogDebug(ex.ToString());

                    Debug.Fail("Unable to find project dependencies: " + ex.ToString());
                }
            }

            if (hasMissingReferences)
            {
                // Log a generic message once per project if any items could not be resolved.
                // In most cases this can be ignored, but in the rare case where the unresolved
                // item is actually a project the restore result will be incomplete.
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.UnresolvedItemDuringProjectClosureWalk,
                    _vsProjectAdapter.UniqueName);

                logger.LogVerbose(message);
            }

            if (hasProjectsWithUnresolvedMetadata)
            {
                IList <string> excludedProjects = await GetExcludedProjectsAsync(logger);

                if (excludedProjects.Count > 0)
                {
                    results = results.Where(e => !excludedProjects.Contains(e.ProjectPath, StringComparer.OrdinalIgnoreCase)).ToList();
                }
            }

            return(results);
示例#4
0
        public async Task <IEnumerable <ProjectRestoreReference> > GetProjectReferencesAsync(
            Common.ILogger logger, CancellationToken _)
        {
            // DTE calls need to be done from the main thread
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            var results = new List <ProjectRestoreReference>();

            var itemsFactory = ServiceLocator.GetInstance <IVsEnumHierarchyItemsFactory>();

            // Verify ReferenceOutputAssembly
            var excludedProjects     = GetExcludedReferences(itemsFactory, logger);
            var hasMissingReferences = false;

            // find all references in the project
            foreach (var childReference in GetVSProjectReferences())
            {
                try
                {
                    var reference3 = childReference as Reference3;

                    // Verify that this is a project reference
                    if (IsProjectReference(reference3, logger))
                    {
                        // Verify that this is a valid and resolved project reference
                        if (!IsReferenceResolved(reference3, logger))
                        {
                            hasMissingReferences = true;
                            continue;
                        }

                        if (EnvDTEProjectUtility.HasUnsupportedProjectCapability(reference3.SourceProject))
                        {
                            // Skip this shared project
                            continue;
                        }

                        var childProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(reference3.SourceProject);

                        // Skip projects which have ReferenceOutputAssembly=false
                        if (!string.IsNullOrEmpty(childProjectPath) &&
                            !excludedProjects.Contains(childProjectPath, StringComparer.OrdinalIgnoreCase))
                        {
                            var restoreReference = new ProjectRestoreReference()
                            {
                                ProjectPath       = childProjectPath,
                                ProjectUniqueName = childProjectPath
                            };

                            results.Add(restoreReference);
                        }
                    }
                    else
                    {
                        hasMissingReferences = true;
                    }
                }
                catch (Exception ex)
                {
                    // Exceptions are expected in some scenarios for native projects,
                    // ignore them and show a warning
                    hasMissingReferences = true;

                    logger.LogDebug(ex.ToString());

                    Debug.Fail("Unable to find project dependencies: " + ex.ToString());
                }
            }

            if (hasMissingReferences)
            {
                // Log a generic message once per project if any items could not be resolved.
                // In most cases this can be ignored, but in the rare case where the unresolved
                // item is actually a project the restore result will be incomplete.
                var message = string.Format(
                    CultureInfo.CurrentCulture,
                    Strings.UnresolvedItemDuringProjectClosureWalk,
                    _vsProjectAdapter.UniqueName);

                logger.LogVerbose(message);
            }

            return(results);
        }
        private async Task <T> SearchPage <T>(
            Func <Uri, Task <T> > getResultAsync,
            string searchTerm,
            SearchFilter filters,
            int skip,
            int take,
            Common.ILogger log,
            CancellationToken cancellationToken)
        {
            log.LogVerbose($"Found {_searchEndpoints.Length} search endpoints.");

            for (var i = 0; i < _searchEndpoints.Length; i++)
            {
                var endpoint = _searchEndpoints[i];

                // The search term comes in already encoded from VS
                var queryUrl    = new UriBuilder(endpoint.AbsoluteUri);
                var queryString =
                    "q=" + searchTerm +
                    "&skip=" + skip.ToString() +
                    "&take=" + take.ToString() +
                    "&prerelease=" + filters.IncludePrerelease.ToString().ToLowerInvariant();

                if (filters.IncludeDelisted)
                {
                    queryString += "&includeDelisted=true";
                }

                if (filters.SupportedFrameworks != null &&
                    filters.SupportedFrameworks.Any())
                {
                    var frameworks =
                        string.Join("&",
                                    filters.SupportedFrameworks.Select(
                                        fx => "supportedFramework=" + fx.ToString()));
                    queryString += "&" + frameworks;
                }

                if (filters.PackageTypes != null &&
                    filters.PackageTypes.Any())
                {
                    var types = string.Join("&",
                                            filters.PackageTypes.Select(
                                                s => "packageTypeFilter=" + s));
                    queryString += "&" + types;
                }

                queryString += "&semVerLevel=2.0.0";

                queryUrl.Query = queryString;

                var searchResult = default(T);
                try
                {
                    log.LogVerbose($"Querying {queryUrl.Uri}");

                    searchResult = await getResultAsync(queryUrl.Uri);
                }
                catch (OperationCanceledException)
                {
                    throw;
                }
                catch when(i < _searchEndpoints.Length - 1)
                    {
                        // Ignore all failures until the last endpoint
                    }