コード例 #1
0
        private static async Task <bool> IncludeExistingFolderToProjectAsync(EnvDTE.Project envDTEProject, string folderRelativePath)
        {
            // Execute command to include the existing folder into project. Must do this on UI thread.
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            IVsUIHierarchy projectHierarchy = (IVsUIHierarchy)VsHierarchyUtility.ToVsHierarchy(envDTEProject);

            uint itemId;
            int  hr = projectHierarchy.ParseCanonicalName(folderRelativePath, out itemId);

            if (!ErrorHandler.Succeeded(hr))
            {
                return(false);
            }

            hr = projectHierarchy.ExecCommand(
                itemId,
                ref VsMenus.guidStandardCommandSet2K,
                (int)VSConstants.VSStd2KCmdID.INCLUDEINPROJECT,
                0,
                IntPtr.Zero,
                IntPtr.Zero);

            return(ErrorHandler.Succeeded(hr));
        }
コード例 #2
0
        public static bool IncludeExistingFolderToProject(this Project project, string folderRelativePath)
        {
            IVsUIHierarchy projectHierarchy = (IVsUIHierarchy)project.ToVsHierarchy();

            uint itemId;
            int  hr = projectHierarchy.ParseCanonicalName(folderRelativePath, out itemId);

            if (!ErrorHandler.Succeeded(hr))
            {
                return(false);
            }

            // Execute command to include the existing folder into project. Must do this on UI thread.
            hr = ThreadHelper.Generic.Invoke(() =>
                                             projectHierarchy.ExecCommand(
                                                 itemId,
                                                 ref VsMenus.guidStandardCommandSet2K,
                                                 (int)VSConstants.VSStd2KCmdID.INCLUDEINPROJECT,
                                                 0,
                                                 IntPtr.Zero,
                                                 IntPtr.Zero));

            return(ErrorHandler.Succeeded(hr));
        }