Пример #1
0
        protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            DTE2 dte = await VS.GetDTEAsync();

            if (dte?.ActiveDocument == null)
            {
                return;
            }

            try
            {
                IWpfTextView view = await VS.Editor.GetCurrentWpfTextViewAsync();

                if (view != null)
                {
                    ResetZoom(dte, view);
                }
            }
            catch (Exception ex)
            {
                await ex.LogAsync();
            }
        }
        protected override async Task <object> InitializeToolWindowAsync(Type toolWindowType, int id, CancellationToken cancellationToken)
        {
            PropertyInfo[] properties = typeof(KnownMonikers).GetProperties(BindingFlags.Static | BindingFlags.Public);

            return(new ServicesDTO
            {
                Monikers = properties.Select(p => new KnownMonikersViewModel(p.Name, (ImageMoniker)p.GetValue(null, null))),
                DTE = await VS.GetDTEAsync()
            });
        }
        public override async Task <FrameworkElement> CreateAsync(int toolWindowId, CancellationToken cancellationToken)
        {
            // Simulate long running background task
            await Task.Delay(2000);

            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            DTE2 dte = await VS.GetDTEAsync();

            return(new RunnerWindowControl(dte));
        }
        /// <summary>Adds one or more files to the project.</summary>
        public static async Task AddFilesToProjectAsync(this Project project, params string[] files)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (project == null || project.IsKind(ProjectTypes.ASPNET_CORE) || project.IsKind(ProjectTypes.DOTNET_CORE) || project.IsKind(ProjectTypes.SSDT))
            {
                return;
            }

            DTE2?dte = await VS.GetDTEAsync();

            if (project.IsKind(ProjectTypes.WEBSITE))
            {
                Command command = dte.Commands.Item("SolutionExplorer.Refresh");

                if (command.IsAvailable)
                {
                    dte.ExecuteCommand(command.Name);
                }

                return;
            }

            IVsSolution?solutionService = await VS.GetRequiredServiceAsync <SVsSolution, IVsSolution>();

            solutionService.GetProjectOfUniqueName(project.UniqueName, out IVsHierarchy? hierarchy);

            if (hierarchy == null)
            {
                return;
            }

            var ip     = (IVsProject)hierarchy;
            var result = new VSADDRESULT[files.Count()];

            ip.AddItem(VSConstants.VSITEMID_ROOT,
                       VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE,
                       string.Empty,
                       (uint)files.Count(),
                       files.ToArray(),
                       IntPtr.Zero,
                       result);
        }
        /// <summary>
        /// Builds the specified project asynchronously
        /// </summary>
        /// <returns>Returns <c>true</c> if the project builds successfully.</returns>
        public static async Task <bool> BuildAsync(this Project project)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var buildTaskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);

            DTE2?dte = await VS.GetDTEAsync();

            dte.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
            var configuration = dte.Solution.SolutionBuild.ActiveConfiguration.Name;

            dte.Solution.SolutionBuild.BuildProject(configuration, project.UniqueName, false);
            return(await buildTaskCompletionSource.Task);

            void BuildEvents_OnBuildDone(vsBuildScope scope, vsBuildAction action)
            {
                dte.Events.BuildEvents.OnBuildDone -= BuildEvents_OnBuildDone;

                // Returns 'true' if the number of failed projects == 0
                buildTaskCompletionSource.TrySetResult(dte.Solution.SolutionBuild.LastBuildInfo == 0);
            }
        }
Пример #6
0
        public override async Task <FrameworkElement> CreateAsync(int toolWindowId, CancellationToken cancellationToken)
        {
            EnvDTE80.DTE2 dte = await VS.GetDTEAsync();

            return(new MyToolWindowControl(dte));
        }