コード例 #1
0
ファイル: XenkoPackage.cs プロジェクト: xuebai5/xenko
        private void UpdateStartupProjectFromConfiguration()
        {
            var solution     = (IVsSolution)GetGlobalService(typeof(IVsSolution));
            var buildManager = (IVsSolutionBuildManager)GetGlobalService(typeof(IVsSolutionBuildManager));
            var dte          = (DTE)GetService(typeof(DTE));

            foreach (SolutionContext context in dte.Solution.SolutionBuild.ActiveConfiguration.SolutionContexts)
            {
                if (!context.ShouldBuild)
                {
                    continue;
                }

                foreach (var project in VsHelper.GetDteProjectsInSolution(solution))
                {
                    if (context.ProjectName != project.UniqueName || !IsProjectExecutable(project))
                    {
                        continue;
                    }

                    var startupProjects = (object[])dte.Solution.SolutionBuild.StartupProjects;
                    if (!startupProjects.Cast <string>().Contains(project.UniqueName))
                    {
                        buildManager.set_StartupProject(VsHelper.ToHierarchy(project));
                    }

                    previousProjectPlatforms[project] = context.PlatformName;
                    return;
                }
            }
        }
コード例 #2
0
ファイル: XenkoPackage.cs プロジェクト: xen2/stride
        private void solutionEventsListener_AfterSolutionBackgroundLoadComplete()
        {
            InitializeCommandProxy();

            var solution        = (IVsSolution)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(IVsSolution));
            var updatedProjects = new List <string>();

            foreach (var dteProject in VsHelper.GetDteProjectsInSolution(solution))
            {
                var buildProjects = ProjectCollection.GlobalProjectCollection.GetLoadedProjects(dteProject.FileName);
                foreach (var buildProject in buildProjects)
                {
                    var packageVersion        = buildProject.GetPropertyValue("XenkoPackageXenkoVersion");
                    var currentPackageVersion = buildProject.GetPropertyValue("XenkoPackageXenkoVersionLast");
                    if (!string.IsNullOrEmpty(packageVersion) && packageVersion != currentPackageVersion)
                    {
                        var buildPropertyStorage = VsHelper.ToHierarchy(dteProject) as IVsBuildPropertyStorage;
                        if (buildPropertyStorage != null)
                        {
                            buildPropertyStorage.SetPropertyValue("XenkoPackageXenkoVersionLast", string.Empty, (uint)_PersistStorageType.PST_USER_FILE, packageVersion);

                            // Only "touch" file if there was a version before (we don't want to trigger this on newly created projects)
                            if (!string.IsNullOrEmpty(currentPackageVersion))
                            {
                                updatedProjects.Add(buildProject.FullPath);
                            }
                        }
                    }
                }
            }

            if (updatedProjects.Count > 0)
            {
                var messageBoxResult = VsShellUtilities.ShowMessageBox(this,
                                                                       "Xenko needs to update IntelliSense cache for some projects.\nThis will resave the .csproj and Visual Studio will offer to reload them.\n\nProceed?",
                                                                       "Xenko IntelliSense cache",
                                                                       OLEMSGICON.OLEMSGICON_QUERY,
                                                                       OLEMSGBUTTON.OLEMSGBUTTON_YESNO,
                                                                       OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                if (messageBoxResult == 6) // Yes
                {
                    // Touch files so that VS reload them
                    foreach (var updatedProject in updatedProjects)
                    {
                        File.SetLastWriteTimeUtc(updatedProject, DateTime.UtcNow);
                    }
                }
            }
        }