Пример #1
0
        public static string GetProjectDirectory(Project project)
        {
            DTE dte = (DTE)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(DTE));

            if (dte == null)
            {
                return(string.Empty);
            }

            if (project == null)
            {
                return(string.Empty);
            }

            var solutionDirectory = Path.GetDirectoryName(dte.Solution.FullName);

            string projectFolder = solutionDirectory;

            foreach (Property prop in project.Properties)
            {
                if (prop.Name == "FullPath" || prop.Name == "ProjectDirectory")
                {
                    projectFolder = prop.Value.ToString();
                    break;
                }
            }

            return(projectFolder);
        }
Пример #2
0
        private static Project GetProjectFromSelection()
        {
            IntPtr             hierarchyPointer, selectionContainerPointer;
            uint               projectItemId;
            IVsMultiItemSelect multiItemSelect;

            IVsMonitorSelection monitorSelection = (IVsMonitorSelection)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(SVsShellMonitorSelection));

            int currentSelectionResult = monitorSelection.GetCurrentSelection(out hierarchyPointer, out projectItemId, out multiItemSelect, out selectionContainerPointer);

            if (currentSelectionResult != VSConstants.S_OK)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Error retrieving current selection from the selection monitor, error code {0}", currentSelectionResult));
            }

            IVsHierarchy selectedHierarchy = Marshal.GetTypedObjectForIUnknown(hierarchyPointer, typeof(IVsHierarchy)) as IVsHierarchy;

            object objProj;

            int getPropertyResult = selectedHierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out objProj);

            if (getPropertyResult != VSConstants.S_OK)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Error getting property from the selected hierarchy, error code {0}", getPropertyResult));
            }

            var project = objProj as EnvDTE.Project;

            return(project);
        }
Пример #3
0
        public static string GetTargetFile()
        {
            string targetFile = string.Empty;

            try
            {
                var componentModel = (IComponentModel)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(SComponentModel));
                if (componentModel == null)
                {
                    return(string.Empty);
                }

                IVsPackageInstallerServices installerServices = componentModel.GetService <IVsPackageInstallerServices>();

                var packageDir = installerServices.GetInstalledPackages().Where(o => o.Id == CloudFoundryVisualStudioPackage.PackageId).FirstOrDefault().InstallPath;

                targetFile = System.IO.Path.Combine(packageDir, "cf-msbuild-tasks.targets");
            }
            catch (Exception ex)
            {
                Logger.Error("Error retrieving nuget package service", ex);
            }

            return(targetFile);
        }
Пример #4
0
        public static string GetPublishProfilePath(Project project)
        {
            IVsSolution solution = (IVsSolution)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(IVsSolution));

            if (solution == null)
            {
                return(string.Empty);
            }

            string projectFolder = GetProjectDirectory(project);

            IVsHierarchy hierarchy;

            int getProjectResult = solution.GetProjectOfUniqueName(project.UniqueName, out hierarchy);

            if (getProjectResult != VSConstants.S_OK)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Error retrieving project of unique name, error code: {0}", getProjectResult));
            }

            IVsAggregatableProject aggregatable = (IVsAggregatableProject)hierarchy;

            string projectTypes      = string.Empty;
            int    projectTypeResult = aggregatable.GetAggregateProjectTypeGuids(out projectTypes);

            if (projectTypeResult != VSConstants.S_OK)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Error retrieving aggregate project types, error code: {0}", projectTypeResult));
            }

            string result = System.IO.Path.Combine(projectFolder, "PublishProfiles");

            if (projectTypes.ToUpperInvariant().Contains("{E24C65DC-7377-472B-9ABA-BC803B73C61A}"))
            {
                result = System.IO.Path.Combine(projectFolder, "App_Data", "PublishProfiles");
            }

            if (projectTypes.ToUpperInvariant().Contains("{349C5851-65DF-11DA-9384-00065B846F21}"))
            {
                result = System.IO.Path.Combine(projectFolder, "Properties", "PublishProfiles");
            }

            return(FileUtilities.PathAddBackslash(result));
        }
Пример #5
0
        public static object GetVisualStudioSetting(string category, string page, string propertyName)
        {
            DTE dte = (DTE)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(DTE));

            if (dte == null)
            {
                return(null);
            }

            EnvDTE.Properties propertyList = dte.get_Properties(category, page);
            foreach (EnvDTE.Property prop in propertyList)
            {
                if (prop.Name == propertyName)
                {
                    return(prop.Value);
                }
            }

            return(null);
        }
Пример #6
0
        public static Project GetSelectedProject()
        {
            DTE dte = (DTE)CloudFoundryVisualStudioPackage.GetGlobalService(typeof(DTE));

            if (dte == null)
            {
                return(null);
            }

            foreach (EnvDTE.SelectedItem item in dte.SelectedItems)
            {
                Project current = item.Project as Project;
                if (current != null)
                {
                    return(current);
                }
            }

            return(GetProjectFromSelection());
        }