Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        private void OnProjectOpened(IVsHierarchy vsHierarchy)
        {
            // Register pipe url so that MSBuild can transfer it
            var vsProject = vsHierarchy as IVsProject;

            if (vsProject != null)
            {
                var dteProject = VsHelper.ToDteProject(vsProject);

                // We will only deal with .csproj files for now
                // Should we support C++/CLI .vcxproj as well?
                if (!dteProject.FileName.EndsWith(".csproj"))
                {
                    return;
                }

                // Find current project active configuration
                var configManager = dteProject.ConfigurationManager;
                if (configManager == null)
                {
                    return;
                }

                EnvDTE.Configuration activeConfig;
                try
                {
                    activeConfig = configManager.ActiveConfiguration;
                }
                catch (Exception)
                {
                    if (configManager.Count == 0)
                    {
                        return;
                    }

                    activeConfig = configManager.Item(1);
                }

                // Get global parameters for Configuration and Platform
                var globalProperties = new Dictionary <string, string>();
                globalProperties["Configuration"] = activeConfig.ConfigurationName;
                globalProperties["Platform"]      = activeConfig.PlatformName == "Any CPU" ? "AnyCPU" : activeConfig.PlatformName;

                // Check if project matches: Condition="'$(XenkoCurrentPackagePath)' != '' and '$(XenkoIsExecutable)' == 'true'"
                var projectInstance      = new ProjectInstance(dteProject.FileName, globalProperties, null);
                var packagePathProperty  = projectInstance.Properties.FirstOrDefault(x => x.Name == "XenkoCurrentPackagePath");
                var isExecutableProperty = projectInstance.Properties.FirstOrDefault(x => x.Name == "XenkoIsExecutable");
                if (packagePathProperty == null || isExecutableProperty == null || isExecutableProperty.EvaluatedValue.ToLowerInvariant() != "true")
                {
                    return;
                }

                var buildProjects = ProjectCollection.GlobalProjectCollection.GetLoadedProjects(dteProject.FileName);
                foreach (var buildProject in buildProjects)
                {
                    buildProject.SetGlobalProperty("XenkoBuildEngineLogPipeUrl", logPipeUrl);
                }
            }
        }
Ejemplo n.º 3
0
        private void SolutionEventsListener_OnStartupProjectChanged(IVsHierarchy hierarchy)
        {
            if (configurationLock || hierarchy == null)
                return;

            currentStartupProject = VsHelper.ToDteProject(hierarchy);

            UpdateConfigurationFromStartupProject();
        }
Ejemplo n.º 4
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private static async Task CleanIntermediateAsset(DTE2 dte, Project project)
        {
            if (project.FileName == null || Path.GetExtension(project.FileName) != ".csproj")
            {
                return;
            }

            // Find current project active configuration
            var configManager = project.ConfigurationManager;
            var activeConfig  = configManager.ActiveConfiguration;

            // Get global parameters for Configuration and Platform
            var globalProperties = new Dictionary <string, string>();

            globalProperties["Configuration"] = activeConfig.ConfigurationName;
            globalProperties["Platform"]      = activeConfig.PlatformName == "Any CPU" ? "AnyCPU" : activeConfig.PlatformName;

            // Check if project has a XenkoCurrentPackagePath
            var projectInstance     = new ProjectInstance(project.FileName, globalProperties, null);
            var packagePathProperty = projectInstance.Properties.FirstOrDefault(x => x.Name == "XenkoCurrentPackagePath");

            if (packagePathProperty == null)
            {
                return;
            }

            // Prepare build request
            var request         = new BuildRequestData(project.FileName, globalProperties, null, new[] { "XenkoCleanAsset" }, null);
            var pc              = new Microsoft.Build.Evaluation.ProjectCollection();
            var buildParameters = new BuildParameters(pc);
            var buildLogger     = new IDEBuildLogger(GetOutputPane(), new TaskProvider(ServiceProvider), VsHelper.ToHierarchy(project));

            buildParameters.Loggers = new[] { buildLogger };

            // Trigger async build
            buildLogger.OutputWindowPane.OutputStringThreadSafe(string.Format("Cleaning assets for project {0}...\r\n", project.Name));
            BuildManager.DefaultBuildManager.BeginBuild(buildParameters);
            var         submission  = BuildManager.DefaultBuildManager.PendBuildRequest(request);
            BuildResult buildResult = await submission.ExecuteAsync();

            BuildManager.DefaultBuildManager.EndBuild();
            buildLogger.OutputWindowPane.OutputStringThreadSafe("Done\r\n");
        }