/// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            var dte = GetGlobalService(typeof(DTE)) as DTE2;

            Host.Instance.DTE = dte;
            Host.Instance.SolutionOpendAction = () =>
            {
                var sln      = Host.Instance.Solution2;
                var projects = dte.GetSolutionProjects().ToList();
                var sp       = new SolutionProperties
                {
                    Projects         = projects,
                    ClassicProjects  = projects.Where(p => !string.IsNullOrWhiteSpace(p.FileName) && p.IsNetFrameworkProject()).ToList(),
                    SdkBasedProjects = projects.Where(p => !string.IsNullOrWhiteSpace(p.FileName) && p.IsSdkBased()).ToList()
                };
                SolutionDataCache.Instance.AddOrUpdate(sln.FileName, sp, (k, v) =>
                {
                    v = sp;
                    return(v);
                });
            };

            AddNuSpecCommand.Initialize(this);
            NuGetDeployCommand.Initialize(this);
            AssemblyInfoEditCommand.Initialize(this);
            AddDirectoryBuildPropsCommand.Initialize(this);

            //LoadCustomCommands();
        }
Exemple #2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();



            var dte = GetGlobalService(typeof(DTE)) as DTE2;

            Host.Instance.DTE = dte;

            AddNuSpecCommand.Initialize(this);
            NuGetDeployCommand.Initialize(this);
            AssemblyInfoEditCommand.Initialize(this);
            UnifiedAssemblyInfoEditCommand.Initialize(this);

            LoadCustomCommands();
        }
Exemple #3
0
        protected override async Task  InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            var dte = GetGlobalService(typeof(DTE)) as DTE2;

            Host.Instance.DTE = dte;

            bool isSolutionLoaded = await IsSolutionLoadedAsync();

            if (isSolutionLoaded)
            {
                HandleOpenSolution();
            }

            // Listen for subsequent solution events
            Microsoft.VisualStudio.Shell.Events.SolutionEvents.OnAfterOpenSolution += HandleOpenSolution;


            dte.Events.SolutionEvents.ProjectAdded += p =>
            {
                if (string.IsNullOrWhiteSpace(p.FileName) ||
                    !Common.SupportedProjectTypes.Any(t => p.FileName.EndsWith(t, StringComparison.OrdinalIgnoreCase)))
                {
                    return;
                }
                var sln = Host.Instance.Solution2;
                SolutionDataCache.Instance.TryGetValue(sln.FileName, out var sp);
                sp?.AddProject(p);
            };
            dte.Events.SolutionEvents.ProjectRemoved += p =>
            {
                var sln = Host.Instance.Solution2;
                SolutionDataCache.Instance.TryGetValue(sln.FileName, out var sp);
                sp?.RemoveProject(p);
            };

            //var commandService =  await this.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;

            AddNuSpecCommand.Initialize(this);
            NuGetDeployCommand.Initialize(this);
            AssemblyInfoEditCommand.Initialize(this);
            AddDirectoryBuildPropsCommand.Initialize(this);
        }