Пример #1
0
        /// <summary>
        /// When building with only a wixproj 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(WixProjectNode project)
        {
            IVsSolution solution = WixHelperMethods.GetService <IVsSolution, SVsSolution>(project.Site);
            object      solutionPathObj;

            ErrorHandler.ThrowOnFailure(solution.GetProperty((int)__VSPROPID.VSPROPID_SolutionFileName, out solutionPathObj));
            string             solutionPath = (string)solutionPathObj;
            WixPackageSettings settings     = project.WixPackage.Settings;
            string             devEnvDir    = WixHelperMethods.EnsureTrailingDirectoryChar(Path.GetDirectoryName(settings.DevEnvPath));

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

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

                project.BuildProject.SetGlobalProperty(propertyName, propertyValue);
            }
        }
Пример #2
0
        // =========================================================================================
        // Methods
        // =========================================================================================

        /// <summary>
        /// Hides all of the tabs in the Add Reference dialog except for the browse tab, which will search for wixlibs.
        /// </summary>
        /// <param name="project">The project that will contain the reference.</param>
        /// <returns>If the method succeeds, it returns S_OK. If it fails, it returns an error code.</returns>
        internal static int AddProjectReference(WixProjectNode project)
        {
            CCITracing.TraceCall();

            Guid   showOnlyThisTabGuid = Guid.Empty;
            Guid   startOnThisTabGuid  = VSConstants.GUID_BrowseFilePage;
            string helpTopic           = "VS.AddReference";
            string machineName         = String.Empty;
            string browseFilters       = WixProjectReferenceNode.AddReferenceDialogFilter;
            string browseLocation      = WixProjectReferenceNode.GetAddReferenceDialogInitialDirectory(project.WixPackage);

            // initialize the structure that we have to pass into the dialog call
            VSCOMPONENTSELECTORTABINIT[] tabInitializers = new VSCOMPONENTSELECTORTABINIT[2];

            // tab 1 is the Project References tab: passing VSHPROPID_ShowProjInSolutionPage will tell the Add Reference
            // dialog to call into our GetProperty to determine if we should show ourself in the dialog
            tabInitializers[0].dwSize         = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT));
            tabInitializers[0].guidTab        = VSConstants.GUID_SolutionPage;
            tabInitializers[0].varTabInitInfo = (int)__VSHPROPID.VSHPROPID_ShowProjInSolutionPage;

            // tab 2 is the Browse tab
            tabInitializers[1].dwSize         = (uint)Marshal.SizeOf(typeof(VSCOMPONENTSELECTORTABINIT));
            tabInitializers[1].guidTab        = VSConstants.GUID_BrowseFilePage;
            tabInitializers[1].varTabInitInfo = 0;

            // initialize the flags to control the dialog
            __VSCOMPSELFLAGS flags = __VSCOMPSELFLAGS.VSCOMSEL_HideCOMClassicTab |
                                     __VSCOMPSELFLAGS.VSCOMSEL_HideCOMPlusTab |
                                     __VSCOMPSELFLAGS.VSCOMSEL_IgnoreMachineName |
                                     __VSCOMPSELFLAGS.VSCOMSEL_MultiSelectMode;

            // get the dialog service from the environment
            IVsComponentSelectorDlg dialog = WixHelperMethods.GetService <IVsComponentSelectorDlg, SVsComponentSelectorDlg>(project.Site);

            try
            {
                // show the dialog
                ErrorHandler.ThrowOnFailure(dialog.ComponentSelectorDlg(
                                                (uint)flags,
                                                (IVsComponentUser)project,
                                                WixProjectReferenceNode.AddReferenceDialogTitle,
                                                helpTopic,
                                                ref showOnlyThisTabGuid,
                                                ref startOnThisTabGuid,
                                                machineName,
                                                (uint)tabInitializers.Length,
                                                tabInitializers,
                                                browseFilters,
                                                ref browseLocation));
            }
            catch (COMException e)
            {
                CCITracing.Trace(e);
                return(e.ErrorCode);
            }

            return(VSConstants.S_OK);
        }
Пример #3
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

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

            if (serviceProvider != null)
            {
                // get the Visual Studio registry root
                ILocalRegistry3 localRegistry = WixHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider);
                ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot));
            }
        }
Пример #4
0
        /// <summary>
        /// When building a wixproj 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(WixProjectNode project)
        {
            StringBuilder configList = new StringBuilder();

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

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

            project.FindNodesOfType(referenceNodes);

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

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

                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);
                }
            }

            if (configList.Length > 0)
            {
                project.BuildProject.SetGlobalProperty("VSProjectConfigurations", configList.ToString());
            }
        }
Пример #5
0
        // =========================================================================================
        // Constructors
        // =========================================================================================

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

            // get the Visual Studio registry root
            ILocalRegistry3 localRegistry = WixHelperMethods.GetService <ILocalRegistry3, SLocalRegistry>(serviceProvider);

            ErrorHandler.ThrowOnFailure(localRegistry.GetLocalRegistryRoot(out this.visualStudioRegistryRoot));

            this.machineRootPath = WixHelperMethods.RegistryPathCombine(this.visualStudioRegistryRoot, @"InstalledProducts\WiX");

            // initialize all of the machine settings
            this.toolsDirectory = new MachineSettingString(this.machineRootPath, KeyNames.ToolsDirectory, String.Empty);
        }
Пример #6
0
        /// <summary>
        /// Gets the font provided by the VS environment for dialog UI.
        /// </summary>
        /// <returns>Dialog font, or null if it is not available.</returns>
        public static Font GetDialogFont()
        {
            if (WixPackage.Instance != null)
            {
                IUIHostLocale uiHostLocale = WixHelperMethods.GetService <IUIHostLocale, IUIHostLocale>(WixPackage.Instance);
                if (uiHostLocale != null)
                {
                    UIDLGLOGFONT[] pLOGFONT = new UIDLGLOGFONT[1];
                    if (uiHostLocale.GetDialogFont(pLOGFONT) == 0)
                    {
                        return(Font.FromLogFont(pLOGFONT[0]));
                    }
                }
            }

            return(null);
        }
Пример #7
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 = WixHelperMethods.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));
            }
        }
Пример #8
0
        public override int UpgradeProject(string fileName, uint upgradeFlag, string copyLocation, out string upgradedFullyQualifiedFileName, IVsUpgradeLogger logger, out int upgradeRequired, out Guid newProjectFactory)
        {
            uint   ignore;
            string projectName = Path.GetFileNameWithoutExtension(fileName);

            upgradedFullyQualifiedFileName = fileName;

            this.UpgradeProject_CheckOnly(fileName, logger, out upgradeRequired, out newProjectFactory, out ignore);
            if (upgradeRequired == 0)
            {
                upgradedFullyQualifiedFileName = fileName;
                return(VSConstants.S_OK);
            }

            IVsQueryEditQuerySave2 queryEditQuerySave = WixHelperMethods.GetService <IVsQueryEditQuerySave2, SVsQueryEditQuerySave>(this.Site);

            int  qef = (int)tagVSQueryEditFlags.QEF_ReportOnly | (int)__VSQueryEditFlags2.QEF_AllowUnopenedProjects;
            uint verdict;
            uint moreInfo;

            string[] files = new string[1];
            files[0] = fileName;

            bool continueUpgrade = false;

            ErrorHandler.ThrowOnFailure(queryEditQuerySave.QueryEditFiles((uint)qef, 1, files, null, null, out verdict, out moreInfo));
            if (verdict == (uint)tagVSQueryEditResult.QER_EditOK)
            {
                continueUpgrade = true;
            }

            if (verdict == (uint)tagVSQueryEditResult.QER_EditNotOK)
            {
                logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, fileName, WixStrings.ReadOnlyFile);
                if ((moreInfo & (uint)tagVSQueryEditResultFlags.QER_ReadOnlyUnderScc) != 0)
                {
                    qef = (int)tagVSQueryEditFlags.QEF_DisallowInMemoryEdits | (int)__VSQueryEditFlags2.QEF_AllowUnopenedProjects | (int)tagVSQueryEditFlags.QEF_ForceEdit_NoPrompting;
                    ErrorHandler.ThrowOnFailure(queryEditQuerySave.QueryEditFiles((uint)qef, 1, files, null, null, out verdict, out moreInfo));
                    if (verdict == (uint)tagVSQueryEditResult.QER_EditOK)
                    {
                        continueUpgrade = true;
                    }
                }

                if (continueUpgrade)
                {
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, fileName, WixStrings.CheckoutSuccess);
                }
                else
                {
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_ERROR, projectName, fileName, WixStrings.FailedToCheckoutProject);
                    throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, WixStrings.FailedToCheckoutFile, fileName));
                }
            }

            // If file was modified during the checkout, maybe upgrade is not needed
            if ((moreInfo & (uint)tagVSQueryEditResultFlags.QER_MaybeChanged) != 0)
            {
                this.UpgradeProject_CheckOnly(fileName, logger, out upgradeRequired, out newProjectFactory, out ignore);
                if (upgradeRequired == 0)
                {
                    if (logger != null)
                    {
                        logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, fileName, WixStrings.UpgradeNoNeedToUpgradeAfterCheckout);
                    }

                    return(VSConstants.S_OK);
                }
            }

            if (continueUpgrade)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(fileName);
                xmlDoc.DocumentElement.SetAttribute(WixProjectFileConstants.ToolsVersion, "4.0");

                bool targetsPathUpdated = false;
                foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
                {
                    if (WixProjectFileConstants.PropertyGroup == node.Name)
                    {
                        foreach (XmlNode propertyNode in node.ChildNodes)
                        {
                            if (WixProjectFileConstants.WixTargetsPath == propertyNode.Name)
                            {
                                if (propertyNode.InnerText.Contains("\\Microsoft\\WiX\\v3.0\\"))
                                {
                                    targetsPathUpdated     = true;
                                    propertyNode.InnerText = propertyNode.InnerText.Replace("\\Microsoft\\WiX\\v3.0\\", "\\Microsoft\\WiX\\v3.x\\");
                                }
                                else if (propertyNode.InnerText.Contains("\\Microsoft\\WiX\\v3.5\\"))
                                {
                                    targetsPathUpdated     = true;
                                    propertyNode.InnerText = propertyNode.InnerText.Replace("\\Microsoft\\WiX\\v3.5\\", "\\Microsoft\\WiX\\v3.x\\");
                                }

                                if (propertyNode.InnerText.Contains("\\Wix2010.targets"))
                                {
                                    targetsPathUpdated     = true;
                                    propertyNode.InnerText = propertyNode.InnerText.Replace("\\Wix2010.targets", "\\Wix.targets");
                                }
                            }
                        }
                    }
                }

                if (targetsPathUpdated)
                {
                    logger.LogMessage((uint)__VSUL_ERRORLEVEL.VSUL_INFORMATIONAL, projectName, fileName, WixStrings.WixTargetsPathUpdated);
                }

                xmlDoc.Save(fileName);
                upgradedFullyQualifiedFileName = fileName;
            }

            return(VSConstants.S_OK);
        }