Ejemplo n.º 1
0
        public async Task <IEnumerable <RuntimeDescription> > GetRuntimeIdentifiersAsync()
        {
            _threadingService.ThrowIfNotOnUIThread();

            var unparsedRuntimeIdentifer = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.RuntimeIdentifier);

            var unparsedRuntimeIdentifers = await BuildProperties.GetPropertyValueAsync(
                ProjectBuildProperties.RuntimeIdentifiers);

            var runtimes = Enumerable.Empty <string>();

            if (unparsedRuntimeIdentifer != null)
            {
                runtimes = runtimes.Concat(new[] { unparsedRuntimeIdentifer });
            }

            if (unparsedRuntimeIdentifers != null)
            {
                runtimes = runtimes.Concat(unparsedRuntimeIdentifers.Split(';'));
            }

            runtimes = runtimes
                       .Select(x => x.Trim())
                       .Where(x => !string.IsNullOrEmpty(x));

            return(runtimes
                   .Select(runtime => new RuntimeDescription(runtime)));
        }
        public bool TryCreateNuGetProject(
            IVsProjectAdapter vsProjectAdapter,
            ProjectProviderContext context,
            bool forceProjectType,
            out NuGetProject result)
        {
            Assumes.Present(vsProjectAdapter);
            Assumes.Present(context);

            _threadingService.ThrowIfNotOnUIThread();

            result = null;

            var projectSystem = MSBuildNuGetProjectSystemFactory.CreateMSBuildNuGetProjectSystem(
                vsProjectAdapter,
                context.ProjectContext);

            var projectServices = CreateProjectServices(vsProjectAdapter, projectSystem);

            var folderNuGetProjectFullPath = context.PackagesPathFactory();

            // Project folder path is the packages config folder path
            var packagesConfigFolderPath = vsProjectAdapter.FullPath;

            result = new VsMSBuildNuGetProject(
                vsProjectAdapter,
                projectSystem,
                folderNuGetProjectFullPath,
                packagesConfigFolderPath,
                projectServices);

            return(result != null);
        }
Ejemplo n.º 3
0
        public async Task <IVsProjectAdapter> CreateAdapterForFullyLoadedProjectAsync(EnvDTE.Project dteProject)
        {
            Assumes.Present(dteProject);

            _threadingService.ThrowIfNotOnUIThread();

            var vsHierarchyItem = VsHierarchyItem.FromDteProject(dteProject);
            Func <IVsHierarchy, EnvDTE.Project> loadDteProject = _ => dteProject;

            IProjectBuildProperties vsBuildProperties;

            if (vsHierarchyItem.VsHierarchy is IVsBuildPropertyStorage)
            {
                vsBuildProperties = new VsManagedLanguagesProjectBuildProperties(
                    vsHierarchyItem.VsHierarchy as IVsBuildPropertyStorage, _threadingService);
            }
            else
            {
                vsBuildProperties = new VsCoreProjectBuildProperties(dteProject, _threadingService);
            }

            var projectNames = await ProjectNames.FromDTEProjectAsync(dteProject);

            var fullProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(dteProject);

            return(new VsProjectAdapter(
                       vsHierarchyItem,
                       projectNames,
                       fullProjectPath,
                       dteProject.Kind,
                       loadDteProject,
                       vsBuildProperties,
                       _threadingService));
        }
        public bool TryCreateNuGetProject(
            IVsProjectAdapter vsProjectAdapter,
            ProjectProviderContext context,
            bool forceProjectType,
            out NuGetProject result)
        {
            Assumes.Present(vsProjectAdapter);
            Assumes.Present(context);

            _threadingService.ThrowIfNotOnUIThread();

            result = null;

            var projectServices = _threadingService.ExecuteSynchronously(
                () => TryCreateProjectServicesAsync(
                    vsProjectAdapter,
                    forceCreate: forceProjectType));

            if (projectServices == null)
            {
                return(false);
            }

            result = new LegacyPackageReferenceProject(
                vsProjectAdapter,
                vsProjectAdapter.ProjectId,
                projectServices,
                _threadingService);

            return(true);
        }
Ejemplo n.º 5
0
        public bool TryCreateNuGetProject(
            IVsProjectAdapter vsProjectAdapter,
            ProjectProviderContext context,
            bool forceProjectType,
            out NuGetProject result)
        {
            Assumes.Present(vsProjectAdapter);
            Assumes.Present(context);

            result = null;

            _threadingService.ThrowIfNotOnUIThread();

            var guids = vsProjectAdapter.ProjectTypeGuids;

            // Web sites cannot have project.json
            if (guids.Contains(VsProjectTypes.WebSiteProjectTypeGuid, StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            // Find the project file path
            var projectFilePath = vsProjectAdapter.FullProjectPath;

            if (!string.IsNullOrEmpty(projectFilePath))
            {
                var msbuildProjectFile         = new FileInfo(projectFilePath);
                var projectNameFromMSBuildPath = Path.GetFileNameWithoutExtension(msbuildProjectFile.Name);

                // Treat projects with project.json as build integrated projects
                // Search for projectName.project.json first, then project.json
                // If the name cannot be determined, search only for project.json
                string projectJsonPath = null;
                if (string.IsNullOrEmpty(projectNameFromMSBuildPath))
                {
                    projectJsonPath = Path.Combine(msbuildProjectFile.DirectoryName,
                                                   Common.ProjectJsonPathUtilities.ProjectConfigFileName);
                }
                else
                {
                    projectJsonPath = Common.ProjectJsonPathUtilities.GetProjectConfigPath(
                        msbuildProjectFile.DirectoryName,
                        projectNameFromMSBuildPath);
                }

                if (File.Exists(projectJsonPath))
                {
                    var projectServices = CreateProjectServicesAsync(vsProjectAdapter);

                    result = new VsProjectJsonNuGetProject(
                        projectJsonPath,
                        msbuildProjectFile.FullName,
                        vsProjectAdapter,
                        projectServices);
                }
            }

            return(result != null);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Tries to create an instance of <see cref="NuGetProject"/> by calling registered
        /// providers in predefined order.
        /// </summary>
        /// <param name="vsProjectAdapter">A project adapter.</param>
        /// <param name="context">Project context</param>
        /// <param name="result">New project instance when <code>true</code> is returned.
        /// Otherwise - <code>null</code>.</param>
        /// <returns><code>true</code> when new project instance has been successfully created.</returns>
        public bool TryCreateNuGetProject(
            IVsProjectAdapter vsProjectAdapter,
            ProjectProviderContext context,
            out NuGetProject result)
        {
            Assumes.Present(vsProjectAdapter);
            Assumes.Present(context);

            _threadingService.ThrowIfNotOnUIThread();

            var exceptions = new List <Exception>();

            result = _providers
                     .Select(p =>
            {
                try
                {
                    if (p.TryCreateNuGetProject(
                            vsProjectAdapter,
                            context,
                            forceProjectType: false,
                            result: out var nuGetProject))
                    {
                        return(nuGetProject);
                    }
                }
                catch (Exception e)
                {
                    // Ignore failures. If this method returns null, the problem falls
                    // into one of the other NuGet project types.
                    exceptions.Add(e);
                }

                return(null);
            })
                     .FirstOrDefault(p => p != null);

            if (result == null)
            {
                exceptions.ForEach(e => _logger.LogError(e.ToString()));
            }

            return(result != null);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Tries to create an instance of <see cref="NuGetProject"/> by calling registered
        /// providers in predefined order.
        /// </summary>
        /// <param name="vsProjectAdapter">A project adapter.</param>
        /// <param name="context">Project context</param>
        /// <param name="result">New project instance when <code>true</code> is returned.
        /// Otherwise - <code>null</code>.</param>
        /// <returns><code>true</code> when new project instance has been successfully created.</returns>
        public async Task <NuGetProject> TryCreateNuGetProjectAsync(
            IVsProjectAdapter vsProjectAdapter,
            ProjectProviderContext context)
        {
            Assumes.Present(vsProjectAdapter);
            Assumes.Present(context);

            _threadingService.ThrowIfNotOnUIThread();

            var exceptions = new List <Exception>();

            foreach (var provider in _providers)
            {
                try
                {
                    var nuGetProject = await provider.TryCreateNuGetProjectAsync(
                        vsProjectAdapter,
                        context,
                        forceProjectType : false);

                    if (nuGetProject != null)
                    {
                        return(nuGetProject);
                    }
                }
                catch (Exception e)
                {
                    // Ignore failures. If this method returns null, the problem falls
                    // into one of the other NuGet project types.
                    exceptions.Add(e);
                }
            }

            exceptions.ForEach(e => _logger.LogError(e.ToString()));

            return(null);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get the unique names of all references which have ReferenceOutputAssembly set to false.
        /// </summary>
        private IList <string> GetExcludedReferences(
            IVsEnumHierarchyItemsFactory itemsFactory,
            Common.ILogger logger)
        {
            _threadingService.ThrowIfNotOnUIThread();

            var excludedReferences = new List <string>();

            var hierarchy = _vsProjectAdapter.VsHierarchy;

            // Get all items in the hierarchy, this includes project references, files, and everything else.
            IEnumHierarchyItems items;

            if (ErrorHandler.Succeeded(itemsFactory.EnumHierarchyItems(
                                           hierarchy,
                                           (uint)__VSEHI.VSEHI_Leaf,
                                           (uint)VSConstants.VSITEMID.Root,
                                           out items)))
            {
                var buildPropertyStorage = (IVsBuildPropertyStorage)hierarchy;

                // Loop through all items
                uint fetched;
                var  item = new VSITEMSELECTION[1];
                while (ErrorHandler.Succeeded(items.Next(1, item, out fetched)) && fetched == 1)
                {
                    // Check if the item has ReferenceOutputAssembly. This will
                    // return null for the vast majority of items.
                    string value;
                    if (ErrorHandler.Succeeded(buildPropertyStorage.GetItemAttribute(
                                                   item[0].itemid,
                                                   "ReferenceOutputAssembly",
                                                   out value)) &&
                        value != null)
                    {
                        // We only need to go farther if the flag exists and is not true
                        if (!string.Equals(value, bool.TrueString, StringComparison.OrdinalIgnoreCase))
                        {
                            // Get the DTE Project reference for the item id. This checks for nulls incase this is
                            // somehow not a project reference that had the ReferenceOutputAssembly flag.
                            object childObject;
                            if (ErrorHandler.Succeeded(hierarchy.GetProperty(
                                                           item[0].itemid,
                                                           (int)__VSHPROPID.VSHPROPID_ExtObject,
                                                           out childObject)))
                            {
                                // 1. Verify that this is a project reference
                                // 2. Check that it is valid and resolved
                                // 3. Follow the reference to the DTE project and get the unique name
                                var reference = childObject as Reference3;

                                if (IsProjectReference(reference, logger) && IsReferenceResolved(reference, logger))
                                {
                                    var childPath = EnvDTEProjectInfoUtility
                                                    .GetFullProjectPath(reference.SourceProject);

                                    excludedReferences.Add(childPath);
                                }
                            }
                        }
                    }
                }
            }

            return(excludedReferences);
        }