/// <summary>
        /// When building with only a xsproj in the solution, the SolutionX variables are not
        /// defined, so we have to define them here.
        /// </summary>
        /// <param name="project">The project where the properties are defined.</param>
        internal static void DefineSolutionProperties(ProjectNode project)
        {
            IVsSolution solution = XHelperMethods.GetService <IVsSolution, SVsSolution>(project.Site);
            object      solutionPathObj;

            ErrorHandler.ThrowOnFailure(solution.GetProperty((int)__VSPROPID.VSPROPID_SolutionFileName, out solutionPathObj));
            string           solutionPath = (string)solutionPathObj;
            XPackageSettings settings     = XSharpProjectPackage.Instance.Settings;
            string           devEnvDir    = XHelperMethods.EnsureTrailingDirectoryChar(Path.GetDirectoryName(settings.DevEnvPath));

            string[][] properties = new string[][]
            {
                new string[] { XProjectFileConstants.DevEnvDir, devEnvDir },
                new string[] { XProjectFileConstants.SolutionPath, solutionPath },
                new string[] { XProjectFileConstants.SolutionDir, XHelperMethods.EnsureTrailingDirectoryChar(Path.GetDirectoryName(solutionPath)) },
                new string[] { XProjectFileConstants.SolutionExt, Path.GetExtension(solutionPath) },
                new string[] { XProjectFileConstants.SolutionFileName, Path.GetFileName(solutionPath) },
                new string[] { XProjectFileConstants.SolutionName, Path.GetFileNameWithoutExtension(solutionPath) },
            };

            foreach (string[] property in properties)
            {
                string propertyName  = property[0];
                string propertyValue = property[1];

                project.BuildProject.SetGlobalProperty(propertyName, propertyValue);
            }
        }
예제 #2
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

        /// <summary>
        /// Initializes a new instance of the <see cref="XPackageSettings"/> class.
        /// </summary>
        /// <param name="serviceProvider">The <see cref="IServiceProvider"/> to use.</param>
        public XPackageSettings(IServiceProvider serviceProvider)
        {
            XHelperMethods.VerifyNonNullArgument(serviceProvider, "serviceProvider");

            if (serviceProvider != null)
            {
                // get the Visual Studio registry root
                ILocalRegistry3 localRegistry = XHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider);
                ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot));
            }
        }
예제 #3
0
        /// <summary>
        /// Sets the expanded state of the folder.
        /// </summary>
        /// <param name="expanded">Flag that indicates the expanded state of the folder.
        /// This should be 'true' for expanded and 'false' for collapsed state.</param>
        protected void SetExpanded(bool expanded)
        {
            this.IsExpanded = expanded;
            this.SetProperty((int)__VSHPROPID.VSHPROPID_Expanded, expanded);

            // If we are in automation mode then skip the ui part
            if (!Utilities.IsInAutomationFunction(this.ProjectMgr.Site))
            {
                IVsUIHierarchyWindow uiWindow = UIHierarchyUtilities.GetUIHierarchyWindow(this.ProjectMgr.Site, SolutionExplorer);
                if (null != uiWindow)
                {
                    ErrorHandler.ThrowOnFailure(uiWindow.ExpandItem(this.ProjectMgr, this.ID, expanded ? EXPANDFLAGS.EXPF_ExpandFolder : EXPANDFLAGS.EXPF_CollapseFolder));
                }

                // then post the expand command to the shell. Folder verification and creation will
                // happen in the setlabel code...
                IVsUIShell shell = XHelperMethods.GetService <IVsUIShell, SVsUIShell>(this.ProjectMgr.Site);

                object dummy    = null;
                Guid   cmdGroup = VsMenus.guidStandardCommandSet97;
                ErrorHandler.ThrowOnFailure(shell.PostExecCommand(ref cmdGroup, (uint)(expanded ? VsCommands.Expand : VsCommands.Collapse), 0, ref dummy));
            }
        }
        /// <summary>
        /// When building a project in VS, the configuration of referenced projects cannot be determined
        /// by MSBuild or from within an MSBuild task. So we'll get them from the VS project system here.
        /// </summary>
        /// <param name="project">The project where the properties are being defined; also the project
        /// whose references are being examined.</param>
        internal static void DefineProjectReferenceConfigurations(XProjectNode project)
        {
            StringBuilder configList = new StringBuilder();

            IVsSolutionBuildManager solutionBuildManager =
                XHelperMethods.GetService <IVsSolutionBuildManager, SVsSolutionBuildManager>(project.Site);

            List <ProjectReferenceNode> referenceNodes = new List <ProjectReferenceNode>();

            project.FindNodesOfType(referenceNodes);

            foreach (ProjectReferenceNode referenceNode in referenceNodes)
            {
                try
                {
                    IVsHierarchy hierarchy = VsShellUtilities.GetHierarchy(referenceNode.ProjectMgr.Site, referenceNode.ReferencedProjectGuid);

                    string          configuration   = null;
                    IVsProjectCfg2  projectCfg2     = null;
                    IVsProjectCfg[] projectCfgArray = new IVsProjectCfg[1];

                    // this can fail for some reason... this code was copied from Wix and probably isn't stable yet.
                    // this routine is called from InvokeMSBuild and we don't want that to fix because of
                    // some bug here, so this code is surrounded by try/catch until we figure this out
                    int hr = solutionBuildManager.FindActiveProjectCfg(IntPtr.Zero, IntPtr.Zero, hierarchy, projectCfgArray);
                    ErrorHandler.ThrowOnFailure(hr);

                    projectCfg2 = projectCfgArray[0] as IVsProjectCfg2;

                    if (projectCfg2 != null)
                    {
                        hr = projectCfg2.get_DisplayName(out configuration);
                        if (hr != 0)
                        {
                            Marshal.ThrowExceptionForHR(hr);
                        }
                    }

                    if (configuration != null)
                    {
                        if (configList.Length > 0)
                        {
                            configList.Append(';');
                        }

                        configList.Append(referenceNode.ReferencedProjectName);
                        configList.Append('=');
                        configList.Append(configuration);
                    }
                }
                catch (Exception)
                {
                    ;
                }
            }

            if (configList.Length > 0)
            {
                project.BuildProject.SetGlobalProperty("VSProjectConfigurations", configList.ToString());
            }
        }