Example #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;
                }
            }
        }
        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="'$(StrideCurrentPackagePath)' != '' and '$(StrideIsExecutable)' == 'true'"
                var projectInstance      = new ProjectInstance(dteProject.FileName, globalProperties, null);
                var packagePathProperty  = projectInstance.Properties.FirstOrDefault(x => x.Name == "StrideCurrentPackagePath");
                var isExecutableProperty = projectInstance.Properties.FirstOrDefault(x => x.Name == "StrideIsExecutable");
                if (packagePathProperty == null || isExecutableProperty == null || isExecutableProperty.EvaluatedValue.ToLowerInvariant() != "true")
                {
                    return;
                }

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

            currentStartupProject = VsHelper.ToDteProject(hierarchy);

            UpdateConfigurationFromStartupProject();
        }
Example #4
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 StrideCurrentPackagePath
            var projectInstance     = new ProjectInstance(project.FileName, globalProperties, null);
            var packagePathProperty = projectInstance.Properties.FirstOrDefault(x => x.Name == "StrideCurrentPackagePath");

            if (packagePathProperty == null)
            {
                return;
            }

            // Prepare build request
            var request         = new BuildRequestData(project.FileName, globalProperties, null, new[] { "StrideCleanAsset" }, 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");
        }