Exemplo n.º 1
0
        private async Task <IVsWindowFrame> CreateNewWindowFrameAsync(Project project)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            var vsProject    = VsHierarchyUtility.ToVsHierarchy(project);
            var documentName = project.FullName;

            // Find existing hierarchy and item id of the document window if it's
            // already registered.
            var rdt = await GetServiceAsync(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;

            IVsHierarchy hier;
            uint         itemId;
            var          docData = IntPtr.Zero;
            int          hr;

            try
            {
                uint cookie;
                hr = rdt.FindAndLockDocument(
                    (uint)_VSRDTFLAGS.RDT_NoLock,
                    documentName,
                    out hier,
                    out itemId,
                    out docData,
                    out cookie);
                if (hr != VSConstants.S_OK)
                {
                    // the docuemnt window is not registered yet. So use the project as the
                    // hierarchy.
                    hier   = vsProject;
                    itemId = (uint)VSConstants.VSITEMID.Root;
                }
            }
            finally
            {
                if (docData != IntPtr.Zero)
                {
                    Marshal.Release(docData);
                    docData = IntPtr.Zero;
                }
            }

            // Create the doc window using the hiearchy & item id.
            return(await CreateDocWindowAsync(project, documentName, hier, itemId));
        }
Exemplo n.º 2
0
        int IVsTrackBatchRetargetingEvents.OnBatchRetargetingEnd()
        {
            ThreadHelper.JoinableTaskFactory.Run(async delegate
            {
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                _errorListProvider.Tasks.Clear();
                if (_platformRetargetingProject != null)
                {
                    try
                    {
                        var project = _dte.Solution.Item(_platformRetargetingProject);

                        if (project != null)
                        {
                            var nuGetProject = EnvDTEProjectUtility.GetNuGetProject(project, _solutionManager);

                            if (ProjectRetargetingUtility.IsProjectRetargetable(nuGetProject))
                            {
                                var frameworkName = EnvDTEProjectUtility.GetTargetFrameworkString(project);
                                if (NETCore451.Equals(frameworkName, StringComparison.OrdinalIgnoreCase) || Windows81.Equals(frameworkName, StringComparison.OrdinalIgnoreCase))
                                {
                                    IList <PackageIdentity> packagesToBeReinstalled = await ProjectRetargetingUtility.GetPackagesToBeReinstalled(nuGetProject);
                                    if (packagesToBeReinstalled.Count > 0)
                                    {
                                        // By asserting that NuGet is in use, we are also asserting that NuGet.VisualStudio.dll is already loaded
                                        // Hence, it is okay to call project.ToVsHierarchy()
                                        Debug.Assert(ProjectRetargetingUtility.IsNuGetInUse(project));
                                        IVsHierarchy projectHierarchy = VsHierarchyUtility.ToVsHierarchy(project);
                                        ShowRetargetingErrorTask(packagesToBeReinstalled.Select(p => p.Id), projectHierarchy, TaskErrorCategory.Error, TaskPriority.High);
                                    }
                                    ProjectRetargetingUtility.MarkPackagesForReinstallation(nuGetProject, packagesToBeReinstalled);
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        // If the solution does not contain a project named '_platformRetargetingProject', it will throw ArgumentException
                    }
                    _platformRetargetingProject = null;
                }
            });

            return(VSConstants.S_OK);
        }
        private void ShowWarningsForPackageReinstallation(Solution solution)
        {
            Debug.Assert(solution != null);

            foreach (Project project in solution.Projects)
            {
                var nuGetProject = EnvDTEProjectUtility.GetNuGetProject(project, _solutionManager);
                if (ProjectRetargetingUtility.IsProjectRetargetable(nuGetProject))
                {
                    var packageReferencesToBeReinstalled = ProjectRetargetingUtility.GetPackageReferencesMarkedForReinstallation(nuGetProject);
                    if (packageReferencesToBeReinstalled.Count > 0)
                    {
                        Debug.Assert(ProjectRetargetingUtility.IsNuGetInUse(project));
                        var projectHierarchy = VsHierarchyUtility.ToVsHierarchy(project);
                        ShowRetargetingErrorTask(packageReferencesToBeReinstalled.Select(p => p.PackageIdentity.Id), projectHierarchy, TaskErrorCategory.Warning, TaskPriority.Normal);
                    }
                }
            }
        }