Exemple #1
0
        private static bool IsClassLibrary(EnvDTEProject envDTEProject)
        {
            if (IsWebSite(envDTEProject))
            {
                return(false);
            }

            // Consider class libraries projects that have one project type guid and an output type of project library.
            var outputType = GetPropertyValue <prjOutputType>(envDTEProject, "OutputType");

            return(VsHierarchyUtility.GetProjectTypeGuids(envDTEProject).Length == 1 &&
                   outputType == prjOutputType.prjOutputTypeLibrary);
        }
        private static bool IsProjectPackageReferenceCompatible(Project project)
        {
            var projectGuids = VsHierarchyUtility.GetProjectTypeGuids(project);

            if (projectGuids.Any(t => UnupgradeableProjectTypes.Contains(t)))
            {
                return(false);
            }

            // Project is supported language, and not an unsupported type
            return(UpgradeableProjectTypes.Contains(project.Kind) &&
                   projectGuids.All(projectTypeGuid => !SupportedProjectTypes.IsUnsupported(projectTypeGuid)));
        }
Exemple #3
0
        public static IMSBuildNuGetProjectSystem CreateMSBuildNuGetProjectSystem(EnvDTEProject envDTEProject, INuGetProjectContext nuGetProjectContext)
        {
            if (envDTEProject == null)
            {
                throw new ArgumentNullException("project");
            }

            if (String.IsNullOrEmpty(envDTEProject.FullName))
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        Strings.DTE_ProjectUnsupported, EnvDTEProjectUtility.GetName(envDTEProject)));
            }

#if VS14
            if (EnvDTEProjectUtility.SupportsINuGetProjectSystem(envDTEProject))
            {
                throw new InvalidOperationException("Does not support INuGetProjectSystem");
            }
#endif

            var guids = VsHierarchyUtility.GetProjectTypeGuids(envDTEProject);
            if (guids.Contains(NuGetVSConstants.CppProjectTypeGuid)) // Got a cpp project
            {
                if (!EnvDTEProjectUtility.IsClr(envDTEProject))
                {
                    return(new NativeProjectSystem(envDTEProject, nuGetProjectContext));
                }
            }



            // Try to get a factory for the project type guid
            foreach (var guid in guids)
            {
                IMSBuildNuGetProjectSystemThunk factory;
                if (_factories.TryGetValue(guid, out factory))
                {
                    return(factory(envDTEProject, nuGetProjectContext));
                }
            }

            // Fall back to the default if we have no special project types
            return(new VSMSBuildNuGetProjectSystem(envDTEProject, nuGetProjectContext));
        }
        public static IMSBuildNuGetProjectSystem CreateMSBuildNuGetProjectSystem(EnvDTEProject envDTEProject, INuGetProjectContext nuGetProjectContext)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (envDTEProject == null)
            {
                throw new ArgumentNullException(nameof(envDTEProject));
            }

            if (String.IsNullOrEmpty(envDTEProject.FullName))
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture,
                                        Strings.DTE_ProjectUnsupported, EnvDTEProjectInfoUtility.GetName(envDTEProject)));
            }

            if (EnvDTEProjectUtility.SupportsINuGetProjectSystem(envDTEProject))
            {
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture, Strings.DTE_ProjectUnsupported, typeof(IMSBuildNuGetProjectSystem).FullName));
            }

            var guids = VsHierarchyUtility.GetProjectTypeGuids(envDTEProject);

            if (guids.Contains(VsProjectTypes.CppProjectTypeGuid)) // Got a cpp project
            {
                return(new NativeProjectSystem(envDTEProject, nuGetProjectContext));
            }

            // Try to get a factory for the project type guid
            foreach (var guid in guids)
            {
                IMSBuildNuGetProjectSystemThunk factory;
                if (_factories.TryGetValue(guid, out factory))
                {
                    return(factory(envDTEProject, nuGetProjectContext));
                }
            }

            // Fall back to the default if we have no special project types
            return(new VSMSBuildNuGetProjectSystem(envDTEProject, nuGetProjectContext));
        }
Exemple #5
0
        public async Task <string[]> GetProjectTypeGuidsAsync()
        {
            if (!IsDeferred)
            {
                return(VsHierarchyUtility.GetProjectTypeGuids(Project));
            }
            else
            {
                // Get ProjectTypeGuids from msbuild property, if it doesn't exist, fall back to projectTypeGuid.
                var projectTypeGuids = await BuildProperties.GetPropertyValueAsync(ProjectBuildProperties.ProjectTypeGuids);

                if (!string.IsNullOrEmpty(projectTypeGuids))
                {
                    return(MSBuildStringUtility.Split(projectTypeGuids));
                }

                if (!string.IsNullOrEmpty(_projectTypeGuid))
                {
                    return(new string[] { _projectTypeGuid });
                }

                return(Array.Empty <string>());
            }
        }
        public async Task <string[]> GetProjectTypeGuidsAsync()
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            return(VsHierarchyUtility.GetProjectTypeGuids(VsHierarchy, Project.Kind));
        }
Exemple #7
0
 public static bool IsWindowsStoreApp(EnvDTEProject envDTEProject)
 {
     string[] types = VsHierarchyUtility.GetProjectTypeGuids(envDTEProject);
     return(types.Contains(NuGetVSConstants.WindowsStoreProjectTypeGuid, StringComparer.OrdinalIgnoreCase));
 }
Exemple #8
0
 public static bool IsWebProject(EnvDTEProject envDTEProject)
 {
     string[] types = VsHierarchyUtility.GetProjectTypeGuids(envDTEProject);
     return(types.Contains(NuGetVSConstants.WebSiteProjectTypeGuid, StringComparer.OrdinalIgnoreCase) ||
            types.Contains(NuGetVSConstants.WebApplicationProjectTypeGuid, StringComparer.OrdinalIgnoreCase));
 }
Exemple #9
0
        public static async Task <bool> IsNuGetProjectUpgradeableAsync(NuGetProject nuGetProject, Project envDTEProject = null)
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (nuGetProject == null && envDTEProject == null)
            {
                return(false);
            }

            if (nuGetProject == null)
            {
                var solutionManager = ServiceLocator.GetInstance <IVsSolutionManager>();

                var projectSafeName = await EnvDTEProjectInfoUtility.GetCustomUniqueNameAsync(envDTEProject);

                nuGetProject = await solutionManager.GetNuGetProjectAsync(projectSafeName);

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

            // check if current project is packages.config based or not
            var msBuildNuGetProject = nuGetProject as MSBuildNuGetProject;

            if (msBuildNuGetProject == null || !msBuildNuGetProject.PackagesConfigNuGetProject.PackagesConfigExists())
            {
                return(false);
            }

            // this further check if current project system supports VSProject4 or not which is essential to skip
            // projects like c++ which currently doesn't support VSProject4 implementation for PackageReference
            if (!msBuildNuGetProject.ProjectServices.Capabilities.SupportsPackageReferences)
            {
                return(false);
            }

            if (envDTEProject == null)
            {
                var vsmsBuildNuGetProjectSystem =
                    msBuildNuGetProject.ProjectSystem as VsMSBuildProjectSystem;
                if (vsmsBuildNuGetProjectSystem == null)
                {
                    return(false);
                }
                envDTEProject = vsmsBuildNuGetProjectSystem.VsProjectAdapter.Project;
            }

            if (!EnvDTEProjectUtility.IsSupported(envDTEProject))
            {
                return(false);
            }
            var projectGuids = VsHierarchyUtility.GetProjectTypeGuids(envDTEProject);

            if (projectGuids.Any(t => UnupgradeableProjectTypes.Contains(t)))
            {
                return(false);
            }

            // Project is supported language, and not an unsupported type
            return(UpgradeableProjectTypes.Contains(envDTEProject.Kind) &&
                   projectGuids.All(projectTypeGuid => !SupportedProjectTypes.IsUnsupported(projectTypeGuid)));
        }