コード例 #1
0
        public static IVsPathContext GetVsPathContext(string projectUniqueName)
        {
            var provider = ServiceLocator.GetInstance <IVsPathContextProvider>();

            IVsPathContext context;

            if (provider.TryCreateContext(projectUniqueName, out context))
            {
                return(context);
            }

            return(null);
        }
コード例 #2
0
ファイル: VSHelper.cs プロジェクト: An575/NuGet.Client
        private static async Task <string[]> GetErrorTasksAsync(vsBuildErrorLevel errorLevel)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var dte = ServiceLocator.GetInstance <DTE>();

            dte.ExecuteCommand("View.ErrorList", " ");

            Window errorListWindow = null;

            foreach (Window window in dte.Windows)
            {
                if (window.Caption.StartsWith(ErrorListWindowCaption, System.StringComparison.OrdinalIgnoreCase))
                {
                    errorListWindow = window;
                    break;
                }
            }

            if (errorListWindow == null)
            {
                throw new InvalidOperationException("Unable to locate the error list");
            }

            errorListWindow.Object.ShowErrors   = true;
            errorListWindow.Object.ShowWarnings = true;
            errorListWindow.Object.ShowMessages = true;

            var errorItems = errorListWindow.Object.ErrorItems as ErrorItems;

            if (errorItems == null)
            {
                throw new InvalidOperationException("Unable to retrieve the error list");
            }

            var errorTasks = new List <ErrorItem>();

            for (int i = 1; i <= errorItems.Count; i++)
            {
                var errorItem         = errorItems.Item(i);
                var currentErrorLevel = (vsBuildErrorLevel)errorItem.ErrorLevel;
                if (currentErrorLevel == errorLevel)
                {
                    errorTasks.Add(errorItem);
                }
            }

            var items = errorTasks.Select(e => e.Description as string).ToArray();

            return(items);
        }
コード例 #3
0
        private static async Task <string> GetBuildOutputAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var dte       = ServiceLocator.GetInstance <DTE>();
            var dte2      = (DTE2)dte;
            var buildPane = dte2.ToolWindows.OutputWindow.OutputWindowPanes.Item(BuildOutputPaneName);
            var doc       = buildPane.TextDocument;
            var sel       = doc.Selection;

            sel.StartOfDocument(Extend: false);
            sel.EndOfDocument(Extend: true);
            var text = sel.Text;

            return(text);
        }
コード例 #4
0
        public static bool ExecuteInitScript(string id, string version)
        {
            var scriptExecutor = ServiceLocator.GetInstance <IVsGlobalPackagesInitScriptExecutor>();
            // It is important that this method does not wait on ExecuteInitScriptAsync on the calling thread.
            // Calling thread is powershell execution thread and ExecuteInitScriptAsync needs to switch to
            // Powershell execution thread to execute the scripts
            var task = Task.Run(async() => await scriptExecutor.ExecuteInitScriptAsync(id, version));

            Task.WaitAny(task, Task.Delay(30000));
            if (task.IsCompleted)
            {
                return(task.Result);
            }

            return(false);
        }
コード例 #5
0
        public static async Task <IVsProjectJsonToPackageReferenceMigrateResult> MigrateJsonProject(string projectName)
        {
            var migrator = ServiceLocator.GetInstance <IVsProjectJsonToPackageReferenceMigrator>();

            return((IVsProjectJsonToPackageReferenceMigrateResult)await migrator.MigrateProjectJsonToPackageReferenceAsync(projectName));
        }
コード例 #6
0
        public static void ProjectCacheEventApi_DetachHandler()
        {
            var vsSolutionManager = ServiceLocator.GetInstance <ISolutionManager>();

            vsSolutionManager.AfterNuGetCacheUpdated -= _cacheUpdateEventHandler.Invoke;
        }
コード例 #7
0
        private static async Task <object> NewProjectAsync(
            string templatePath,
            string outputPath,
            string templateName,
            string projectName,
            string solutionFolderName)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            await VSSolutionHelper.EnsureSolutionAsync(outputPath);

            string projectTemplateFilePath = null;

            var     dte                   = ServiceLocator.GetInstance <DTE>();
            var     dte2                  = (DTE2)dte;
            var     solution2             = dte2.Solution as Solution2;
            Project solutionFolderProject = null;

            dynamic newProject = null;

            projectTemplateFilePath = await GetProjectTemplateFilePathAsync(solution2, templateName, templatePath);

            var solutionDir = Path.GetDirectoryName(solution2.FullName);

            string destPath = null;

            if (string.IsNullOrEmpty(solutionFolderName))
            {
                destPath = Path.Combine(solutionDir, projectName);
            }
            else
            {
                destPath = Path.Combine(solutionDir, Path.Combine(solutionFolderName, projectName));
            }

            var window = dte2.ActiveWindow as Window2;

            solutionFolderProject = await CreateProjectFromTemplateAsync(
                solution2,
                solutionFolderName,
                projectTemplateFilePath,
                destPath,
                projectName);

            await CloseOpenDocumentsAsync(dte2);

            await Activatex86ConfigurationsAsync(dte2);

            window.SetFocus();

            await GetProjectAsync(solution2, projectName, solutionFolderProject);

            // HACK: May need to be fixed
            if (newProject == null)
            {
                newProject = await GetProjectAsync(solution2, projectName, solutionFolderProject);
            }

            if (newProject == null)
            {
                throw new InvalidOperationException(
                          "Could not create new project or could not locate newly created project");
            }

            return(newProject);
        }