예제 #1
0
        private void BuildProject(string solutionConfigurationName, string projectUniqueName)
        {
            SolutionConfiguration2 slnCfg = IdentifyMatchingSolution(solutionConfigurationName);

            if (slnCfg == null)
            {
                Console.WriteLine("No configurations matching " + solutionConfigurationName + " found.");
                return;
            }

            string buildConfig = slnCfg.Name + "|" + slnCfg.PlatformName;

            Console.WriteLine("Activating solution configuration '" + buildConfig + "'");
            slnCfg.Activate();

            if (options.Clean)
            {
                Console.WriteLine("Cleaning solution configuration '" + buildConfig + "'");
                sln.SolutionBuild.Clean(true);
                System.Threading.Thread.Sleep(1000);
            }

            Console.WriteLine("Building " + buildConfig + ":" + projectUniqueName);
            sln.SolutionBuild.BuildProject(buildConfig, projectUniqueName, true);
            System.Threading.Thread.Sleep(1000);

            PostBuildChecks();
        }
예제 #2
0
        //---------------------------------------------------------------------
        static IEnumerable <StartUpProjectSettings.CppProject> BuildCppProject(
            SolutionConfiguration2 activeConfiguration,
            IConfigurationManager configurationManager,
            List <ExtendedProject> projects)
        {
            var cppProjects = new List <StartUpProjectSettings.CppProject>();

            foreach (var project in projects)
            {
                var configuration = configurationManager.FindConfiguration(activeConfiguration, project);

                if (configuration != null)
                {
                    var cppProject = new StartUpProjectSettings.CppProject()
                    {
                        ModulePath  = configuration.PrimaryOutput,
                        SourcePaths = PathHelper.ComputeCommonFolders(project.Files.Select(f => f.FullPath)),
                        Path        = project.UniqueName
                    };
                    cppProjects.Add(cppProject);
                }
            }

            return(cppProjects);
        }
예제 #3
0
        //---------------------------------------------------------------------
        StartUpProjectSettings ComputeOptionalSettings(
            SolutionConfiguration2 activeConfiguration,
            ProjectSelectionKind kind)
        {
            var             solution = (Solution2)dte.Solution;
            var             projects = GetProjects(solution);
            ExtendedProject project  = null;

            switch (kind)
            {
            case ProjectSelectionKind.StartUpProject:
                project = GetOptionalStartupProject(solution, projects);
                break;

            case ProjectSelectionKind.SelectedProject:
                project = GetOptionalSelectedProject(projects);
                break;
            }

            if (project == null)
            {
                return(null);
            }

            return(ComputeOptionalSettings(activeConfiguration, projects, project));
        }
예제 #4
0
        //---------------------------------------------------------------------
        StartUpProjectSettings ComputeOptionalSettings(
            SolutionConfiguration2 activeConfiguration,
            List <ExtendedProject> projects,
            ExtendedProject project)
        {
            var startupConfiguration = this.configurationManager.GetConfiguration(
                activeConfiguration, project);
            var debugSettings = startupConfiguration.DebugSettings;

            var settings = new StartUpProjectSettings();

            settings.WorkingDir = startupConfiguration.Evaluate(debugSettings.WorkingDirectory);
            settings.Arguments  = startupConfiguration.Evaluate(debugSettings.CommandArguments);
            settings.Command    = startupConfiguration.Evaluate(debugSettings.Command);
            settings.SolutionConfigurationName =
                this.configurationManager.GetSolutionConfigurationName(activeConfiguration);
            settings.ProjectName = project.UniqueName;
            settings.CppProjects = BuildCppProject(
                activeConfiguration, this.configurationManager, projects);

            var vcclCompilerTool = startupConfiguration.OptionalVCCLCompilerTool;

            if (vcclCompilerTool == null)
            {
                return(null);
            }
            settings.IsOptimizedBuildEnabled = !vcclCompilerTool.IsOptimizeDisabled;
            settings.EnvironmentVariables    = GetEnvironmentVariables(startupConfiguration);

            return(settings);
        }
        private static void setConfigurationProperties(string previousConfiguration)
        {
            SolutionConfiguration2 configuration =
                (SolutionConfiguration2)_DTE2.Solution.SolutionBuild.ActiveConfiguration;

            if (configuration == null)
            {
                return;
            }

            List <DTEProject> projectsToInvalidate = DetermineProjectsToInvalidate(previousConfiguration);

            string configurationName = configuration.Name;
            string platformName      = configuration.PlatformName;

            ProjectCollection global = ProjectCollection.GlobalProjectCollection;

            ConfigureCollection(global, configurationName, platformName);
#if VS12
            if (VersionLessThan(DTEVersion.VS15))
            {
                SetVCProjectsConfigurationProperties(configurationName, platformName);
            }
#endif

            InvalidateProjects(projectsToInvalidate);
        }
예제 #6
0
        public static bool TryGetActiveSolutionConfiguration(
            IServiceProvider serviceProvider,
            out SolutionBuild solutionBuild,
            out SolutionConfiguration2 activeConfiguration)
        {
            Contract.Requires(serviceProvider != null);
            Contract.Ensures(Contract.ValueAtReturn(out solutionBuild) != null || !Contract.Result <bool>());
            Contract.Ensures(Contract.ValueAtReturn(out activeConfiguration) != null || !Contract.Result <bool>());

            solutionBuild       = null;
            activeConfiguration = null;

            DTE dte = VsServiceProviderHelper.GetService <DTE>(serviceProvider);

            if (dte == null)
            {
                return(false);
            }
            var solution = dte.Solution;

            if (solution == null)
            {
                return(false);
            }
            solutionBuild = solution.SolutionBuild;
            Contract.Assume(solutionBuild != null);
            activeConfiguration = solutionBuild.ActiveConfiguration as SolutionConfiguration2;

            return(solutionBuild != null && activeConfiguration != null);
        }
예제 #7
0
 /// <summary>
 /// Compatible format: 'configname'|'platformname'
 /// http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivscfg.get_displayname.aspx
 /// </summary>
 public string SolutionCfgFormat(SolutionConfiguration2 cfg)
 {
     if (cfg == null)
     {
         return(String.Format("{0}|{0}", PROP_UNAV_STRING));
     }
     return(String.Format("{0}|{1}", cfg.Name, cfg.PlatformName));
 }
예제 #8
0
        private void UpdateConfigurationFromStartupProject()
        {
            if (currentStartupProject == null)
                return;

            var projectPlatform = GetProjectPlatform(currentStartupProject);
            var dte = (DTE)GetService(typeof(DTE));
            var activeConfiguration = dte.Solution.SolutionBuild.ActiveConfiguration;

            string startupPlatform;
            var hasPreviousPlatform = previousProjectPlatforms.TryGetValue(currentStartupProject, out startupPlatform);

            SolutionConfiguration2 newConfiguration = null;

            bool foundPreferredPlatform = false;
            foreach (SolutionConfiguration2 configuration in dte.Solution.SolutionBuild.SolutionConfigurations)
            {
                if (foundPreferredPlatform)
                    break;

                if (configuration.Name != activeConfiguration.Name)
                    continue;

                if ((projectPlatform == null) || !configuration.PlatformName.StartsWith(projectPlatform))
                    continue;

                foreach (SolutionContext context in configuration.SolutionContexts)
                {
                    if (!context.ShouldBuild || context.ProjectName != currentStartupProject.UniqueName)
                        continue;

                    if (hasPreviousPlatform && context.PlatformName != startupPlatform)
                        continue;

                    newConfiguration = configuration;

                    if (IsPreferredPlatform(projectPlatform, context.PlatformName))
                    {
                        foundPreferredPlatform = true;
                        break;
                    }
                }
            }

            if (newConfiguration != null && newConfiguration != activeConfiguration)
            {
                try
                {
                    configurationLock = true;
                    newConfiguration.Activate();
                }
                finally
                {
                    configurationLock = false;
                }
            }
        }
예제 #9
0
        //---------------------------------------------------------------------
        public DynamicVCConfiguration FindConfiguration(
            SolutionConfiguration2 activeConfiguration,
            ExtendedProject project)
        {
            string error;
            var    configuration = ComputeConfiguration(activeConfiguration, project, out error);

            return(configuration);
        }
예제 #10
0
        private bool IsRelease()
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            DTE2 dte = Package.GetGlobalService(typeof(DTE)) as DTE2;//await this.package.GetServiceAsync(typeof(DTE)) as DTE;

            Assumes.Present(dte);
            SolutionBuild          builder = dte.Application.Solution.SolutionBuild;
            SolutionConfiguration2 config  = (SolutionConfiguration2)builder.ActiveConfiguration;

            return(config.SolutionContexts.Item(1).ConfigurationName == "Release");
        }
예제 #11
0
        private void BuildSolutionConfiguration(string solutionConfigurationName)
        {
            SolutionConfiguration2 slnCfg = IdentifyMatchingSolution(solutionConfigurationName);

            if (slnCfg == null)
            {
                Console.WriteLine("No configurations matching " + solutionConfigurationName + " found.");
                return;
            }

            BuildSolutionConfiguration(slnCfg);
        }
예제 #12
0
        //---------------------------------------------------------------------
        public DynamicVCConfiguration GetConfiguration(
            SolutionConfiguration2 activeConfiguration,
            ExtendedProject project)
        {
            string error;
            var    configuration = ComputeConfiguration(activeConfiguration, project, out error);

            if (configuration == null)
            {
                throw new VSPackageException(error);
            }

            return(configuration);
        }
예제 #13
0
        public static void CreateConfigurationsForAllProjectTargets(IEnumerable <string> targets, Project project)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            if (targets == null || !targets.Any())
            {
                return;
            }

            //*****create a 'target-specific build' solution configuration if not available

            Solution solution = project.DTE.Solution;

            SolutionConfigurations solutionConfigurations      = solution.SolutionBuild.SolutionConfigurations;
            SolutionConfiguration2 targetSpecificConfiguration = solutionConfigurations.OfType <SolutionConfiguration2>()
                                                                 .Where(config => config.Name.Equals(targetBuildConfigName)).FirstOrDefault();

            if (targetSpecificConfiguration == null)
            {
                targetSpecificConfiguration = solutionConfigurations.Add(targetBuildConfigName, string.Empty, false) as SolutionConfiguration2;
                if (targetSpecificConfiguration == null)
                {
                    return;
                }
            }

            foreach (string target in targets)
            {
                CreateConfigurationsForTarget(target, project);
            }

            //***** set project configuration for solution configuration

            foreach (SolutionContext context in targetSpecificConfiguration.SolutionContexts)
            {
                if (context.ProjectName == project.UniqueName)
                {
                    if (context.ConfigurationName.Equals("Release - all Targets", StringComparison.OrdinalIgnoreCase) ||
                        context.ConfigurationName.Equals("Debug - all Targets", StringComparison.OrdinalIgnoreCase))
                    {
                        context.ConfigurationName = string.Format(releaseConfigurationNameRaw, targets.First());
                        break;
                    }
                }
            }
        }
예제 #14
0
        //---------------------------------------------------------------------
        SolutionContext ComputeContext(
            SolutionConfiguration2 activeConfiguration,
            ExtendedProject project,
            ref string error)
        {
            var contexts = activeConfiguration.SolutionContexts.Cast <SolutionContext>();
            var context  = contexts.FirstOrDefault(c => c.ProjectName == project.UniqueName);

            if (context == null)
            {
                error = string.Format("Cannot find {0} in project contexts. "
                                      + "Please check your solution Configuration Manager.",
                                      project.UniqueName);
                return(null);
            }

            return(context);
        }
예제 #15
0
        private static void RunTestProject(Project project, Solution solution)
        {
            //System.Diagnostics.Debug.WriteLine("RunTestsMenuCommand.MenuItemCallback()! " + project.Name + " ");
            //System.Diagnostics.Debug.WriteLine(project.Properties.Item("OutputFileName").Value.ToString());
            //System.Diagnostics.Debug.WriteLine(project.Properties.Item("FullPath").Value.ToString());
            //System.Diagnostics.Debug.WriteLine(GetVisualStudioInstallationPath());
            SolutionConfiguration2 solutionConfiguration2 = (SolutionConfiguration2)solution.SolutionBuild.ActiveConfiguration;
            string ProjectFullPath = project.Properties.Item("FullPath").Value.ToString();

            string buildDir = ProjectFullPath + "bin\\" + solutionConfiguration2.Name + "\\";

            string CommandLine = GetVisualStudioInstallationPath() + "mstest.exe /noresults /resultsfile:\"" + buildDir + "appmon_test_results.trx\" /testcontainer:\"" + buildDir + project.Properties.Item("OutputFileName").Value.ToString() + "\"";

            //System.Diagnostics.Debug.WriteLine(CommandLine);

            System.Diagnostics.Process process = LaunchCommand.Instance.Launcher.LaunchProcess(GetVisualStudioInstallationPath() + "\\mstest.exe", "/noresults /resultsfile:\"" + buildDir + "appmon_test_results.trx\" /testcontainer:\"" + buildDir + project.Properties.Item("OutputFileName").Value.ToString() + "\"", buildDir, "vs");
            process.WaitForExit();
        }
예제 #16
0
        public static async void EnsureVCProjectsPropertiesConfigured(IVsHierarchy hierarchy)
        {
            DTEProject project = hierarchy.GetProject();

            if (project == null || project.GetKindGuid() != VSConstants.UICONTEXT.VCProject_guid)
            {
                return;
            }

            if (VersionGreaterEqualTo(DTEVersion.VS15))
            {
                // VS2017 needs project to be invalidated after loaded to apply the
                // global properties, supplied with MEF component. Trying to save the
                // project at this point may result in a crash if the project is inside
                // a Solution Folder (why???). Fortunately, at this point to invalidate
                // the project is not neeeded to save
                InvalidateProject(project, false);
                return;
            }

            using (await _VCLock.LockAsync())
            {
                if (_VCProjectCollectionLoaded)
                {
                    return;
                }

                SolutionConfiguration2 configuration =
                    (SolutionConfiguration2)_DTE2.Solution.SolutionBuild.ActiveConfiguration;

                // When creating a completely new project the solution doesn't exist yet
                // so the ActiveConfiguration is null
                if (configuration == null)
                {
                    return;
                }

                // This is the first VC Project loaded, so we don't need to take
                // measures to ensure all projects are correctly marked as dirty
                await SetVCProjectsConfigurationProperties(project, configuration.Name, configuration.PlatformName);
            }
        }
예제 #17
0
        //---------------------------------------------------------------------
        DynamicVCConfiguration ComputeConfiguration(
            SolutionConfiguration2 activeConfiguration,
            ExtendedProject project,
            out string error)
        {
            error = null;
            var context = ComputeContext(activeConfiguration, project, ref error);

            if (context == null)
            {
                return(null);
            }

            if (!context.ShouldBuild)
            {
                error = string.Format(ProjectNotMarkedAsBuildError, project.UniqueName);
                return(null);
            }

            return(ComputeConfiguration(project, context, ref error));
        }
예제 #18
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName);
            string title   = "LaunchDebugger";

            // Show a message box to prove we were here
            //VsShellUtilities.ShowMessageBox(
            //    this.ServiceProvider,
            //    message,
            //    title,
            //    OLEMSGICON.OLEMSGICON_INFO,
            //    OLEMSGBUTTON.OLEMSGBUTTON_OK,
            //    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

            FASTBuildPackage fbPackage = (FASTBuildPackage)this.package;

            if (null == fbPackage.m_dte.Solution)
            {
                return;
            }

            Solution               sln = fbPackage.m_dte.Solution;
            SolutionBuild          sb  = sln.SolutionBuild;
            SolutionConfiguration2 sc  = sb.ActiveConfiguration as SolutionConfiguration2;

            string startupProject = "";

            foreach (String item in (Array)sb.StartupProjects)
            {
                startupProject += item;
            }
            var proj = sln.Item(startupProject).Object as VCProject;

            fbPackage.m_dte.ToolWindows.SolutionExplorer.GetItem("ConsoleApplication1\\ConsoleApplication1").Select(vsUISelectionType.vsUISelectionTypeSelect);
            fbPackage.m_dte.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance");
        }
예제 #19
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void MenuItemCallback(object sender, EventArgs e)
        {
            FASTBuildPackage fbPackage = (FASTBuildPackage)this.package;

            if (null == fbPackage.m_dte.Solution)
            {
                return;
            }

            MenuCommand eventSender = sender as MenuCommand;

            fbPackage.m_outputPane.Activate();
            fbPackage.m_outputPane.Clear();

            if (eventSender == null)
            {
                fbPackage.m_outputPane.OutputString("VSIX failed to cast sender to OleMenuCommand.\r");
                return;
            }

            if (fbPackage.m_dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode)
            {
                fbPackage.m_outputPane.OutputString("Build not launched due to active debugger.\r");
                return;
            }

            if (!IsFBuildFindable(fbPackage.OptionFBPath))
            {
                fbPackage.m_outputPane.OutputString(string.Format("Could not find fbuild at the provided path: {0}, please verify in the msfastbuild options.\r", fbPackage.OptionFBPath));
                return;
            }

            fbPackage.m_dte.ExecuteCommand("File.SaveAll");

            string fbCommandLine      = "";
            string fbWorkingDirectory = "";

            Solution               sln  = fbPackage.m_dte.Solution;
            SolutionBuild          sb   = sln.SolutionBuild;
            SolutionConfiguration2 sc   = sb.ActiveConfiguration as SolutionConfiguration2;
            VCProject              proj = null;

            if (eventSender.CommandID.ID != SlnCommandId && eventSender.CommandID.ID != SlnContextCommandId)
            {
                if (fbPackage.m_dte.SelectedItems.Count > 0)
                {
                    Project envProj = (fbPackage.m_dte.SelectedItems.Item(1).Project as EnvDTE.Project);
                    if (envProj != null)
                    {
                        proj = envProj.Object as VCProject;
                    }
                }

                if (proj == null)
                {
                    string startupProject = "";
                    foreach (String item in (Array)sb.StartupProjects)
                    {
                        startupProject += item;
                    }
                    proj = sln.Item(startupProject).Object as VCProject;
                }

                if (proj == null)
                {
                    fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r");
                    return;
                }

                fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r");
                fbCommandLine      = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -e \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath);
                fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile);
            }
            else
            {
                fbCommandLine      = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3}\" -e \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath);
                fbWorkingDirectory = Path.GetDirectoryName(sln.FileName);
            }

            if (fbPackage.OptionBrokerage.Length > 0)
            {
                fbCommandLine += " -b " + fbPackage.OptionBrokerage;
            }
            if (fbPackage.OptionFBUnity)
            {
                fbCommandLine += " -u true";
            }

            string msfastbuildPath = Assembly.GetAssembly(typeof(msfastbuild.msfastbuild)).Location;

            try
            {
                fbPackage.m_outputPane.OutputString("Launching msfastbuild with command line: " + fbCommandLine + "\r");

                System.Diagnostics.Process FBProcess = new System.Diagnostics.Process();
                FBProcess.StartInfo.FileName               = msfastbuildPath;
                FBProcess.StartInfo.Arguments              = fbCommandLine;
                FBProcess.StartInfo.WorkingDirectory       = fbWorkingDirectory;
                FBProcess.StartInfo.RedirectStandardOutput = true;
                FBProcess.StartInfo.UseShellExecute        = false;
                FBProcess.StartInfo.CreateNoWindow         = true;
                var SystemEncoding = System.Globalization.CultureInfo.GetCultureInfo(GetSystemDefaultLCID()).TextInfo.OEMCodePage;
                FBProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(SystemEncoding);

                System.Diagnostics.DataReceivedEventHandler OutputEventHandler = (Sender, Args) => {
                    if (Args.Data != null)
                    {
                        fbPackage.m_outputPane.OutputString(Args.Data + "\r");
                    }
                };

                FBProcess.OutputDataReceived += OutputEventHandler;
                FBProcess.Start();
                FBProcess.BeginOutputReadLine();
                //FBProcess.WaitForExit();
            }
            catch (Exception ex)
            {
                fbPackage.m_outputPane.OutputString("VSIX exception launching msfastbuild. Could be a broken VSIX? Exception: " + ex.Message + "\r");
            }
        }
예제 #20
0
		/// <summary>
		/// This function is the callback used to execute the command when the menu item is clicked.
		/// See the constructor to see how the menu item is associated with this function using
		/// OleMenuCommandService service and MenuCommand class.
		/// </summary>
		/// <param name="sender">Event sender.</param>
		/// <param name="e">Event args.</param>
		private void MenuItemCallback(object sender, EventArgs e)
		{
			FASTBuildPackage fbPackage = (FASTBuildPackage)this.package;
			if (null == fbPackage.m_dte.Solution)
				return;

			MenuCommand eventSender = sender as MenuCommand;

			fbPackage.m_outputPane.Activate();
			fbPackage.m_outputPane.Clear();

			if (eventSender == null)
			{
				fbPackage.m_outputPane.OutputString("VSIX failed to cast sender to OleMenuCommand.\r");
				return;
			}

			if (fbPackage.m_dte.Debugger.CurrentMode != dbgDebugMode.dbgDesignMode)
			{
				fbPackage.m_outputPane.OutputString("Build not launched due to active debugger.\r");
				return;
			}

			if (!IsFBuildFindable(fbPackage.OptionFBPath))
			{
				fbPackage.m_outputPane.OutputString(string.Format("Could not find fbuild at the provided path: {0}, please verify in the msfastbuild options.\r", fbPackage.OptionFBPath));
				return;
			}

			fbPackage.m_dte.ExecuteCommand("File.SaveAll");

			string fbCommandLine = "";
			string fbWorkingDirectory = "";

			Solution sln = fbPackage.m_dte.Solution;
			SolutionBuild sb = sln.SolutionBuild;
			SolutionConfiguration2 sc = sb.ActiveConfiguration as SolutionConfiguration2;
			VCProject proj = null;

			if (eventSender.CommandID.ID == ContextCommandId)
			{
				if (fbPackage.m_dte.SelectedItems.Count > 0)
				{
					Project envProj = (fbPackage.m_dte.SelectedItems.Item(1).Project as EnvDTE.Project);
					if (envProj != null)
					{
						proj = envProj.Object as VCProject;
					}
				}

				if (proj == null)
				{
					string startupProject = "";
					foreach (String item in (Array)sb.StartupProjects)
					{
						startupProject += item;
					}
					proj = sln.Item(startupProject).Object as VCProject;
				}

				if (proj == null)
				{
					fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r");
					return;
				}

				fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r");
				fbCommandLine = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -b \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath);
				fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile);
			}
			else if (eventSender.CommandID.ID == CommandId)
			{
				if (fbPackage.m_dte.ActiveDocument == null ||
					fbPackage.m_dte.ActiveDocument.ProjectItem == null ||
					fbPackage.m_dte.ActiveDocument.ProjectItem.ContainingProject == null)
				{
					fbPackage.m_outputPane.OutputString("No valid vcproj selected for building.\r");
					return;
				}

				Project envProj = fbPackage.m_dte.ActiveDocument.ProjectItem.ContainingProject;
				if (envProj != null)
				{
					proj = envProj.Object as VCProject;
				}

				if (proj == null)
				{
					fbPackage.m_outputPane.OutputString("No valid vcproj selected for building or set as the startup project.\r");
					return;
				}

				fbPackage.m_outputPane.OutputString("Building " + Path.GetFileName(proj.ProjectFile) + " " + sc.Name + " " + sc.PlatformName + "\r");
				fbCommandLine = string.Format("-p \"{0}\" -c {1} -f {2} -s \"{3}\" -a\"{4}\" -b \"{5}\"", Path.GetFileName(proj.ProjectFile), sc.Name, sc.PlatformName, sln.FileName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath);
				fbWorkingDirectory = Path.GetDirectoryName(proj.ProjectFile);
			}
			else if (eventSender.CommandID.ID == SlnCleanCommandId || eventSender.CommandID.ID == SlnContextCleanCommandId)
			{
				fbCommandLine = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3} -clean\" -b \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath);
				fbWorkingDirectory = Path.GetDirectoryName(sln.FileName);

				fbPackage.m_dte.Solution.SolutionBuild.Clean(true);
				fbPackage.m_outputPane.Activate();
			}
			else if (eventSender.CommandID.ID == SlnCleanBffCommandId)
			{
				fbWorkingDirectory = Path.GetDirectoryName(sln.FileName);

				var files = Directory.EnumerateFiles(fbWorkingDirectory, "*.*", SearchOption.AllDirectories).Where(s => s.EndsWith(".fdb") || s.EndsWith(".bff"));
				foreach (string file in files)
				{
					File.Delete(file);
				}

				fbPackage.m_outputPane.OutputString("bff file deleted.\r");
				fbPackage.m_outputPane.OutputString("========== 정리: 성공 ==========\r");

				Window output_window = fbPackage.m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
				output_window.Activate();

				return;
			}
			else if (eventSender.CommandID.ID == SlnStopCommandId)
			{
				if (FBProcess == null)
				{
					return;
				}

				if (FBProcess.HasExited)
				{
					return;
				}

				FBProcess.CancelOutputRead();
				FBProcess.Kill();

				fbPackage.m_outputPane.OutputString("빌드가 취소되었습니다.\r");

				Window output_window = fbPackage.m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
				output_window.Activate();

				return;
			}
			else
			{
				fbCommandLine = string.Format("-s \"{0}\" -c {1} -f {2} -a\"{3}\" -b \"{4}\"", sln.FileName, sc.Name, sc.PlatformName, fbPackage.OptionFBArgs, fbPackage.OptionFBPath);
				fbWorkingDirectory = Path.GetDirectoryName(sln.FileName);
			}

			if (fbPackage.OptionFBUnity)
			{
				fbCommandLine += " -u true";
			}

			if (fbPackage.OptionFBUseRelative)
			{
				fbCommandLine += " -t true";
			}

			if (fbPackage.OptionFBUseLightCache)
			{
				fbCommandLine += " -l true";
			}

			string msfastbuildPath = Assembly.GetAssembly(typeof(msfastbuild.msfastbuild)).Location;
			try
			{
				fbPackage.m_outputPane.OutputString("Launching msfastbuild with command line: " + fbCommandLine + "\r");

				FBProcess = new System.Diagnostics.Process();
				FBProcess.StartInfo.FileName = msfastbuildPath;
				FBProcess.StartInfo.Arguments = fbCommandLine;
				FBProcess.StartInfo.WorkingDirectory = fbWorkingDirectory;
				FBProcess.StartInfo.RedirectStandardOutput = true;
				FBProcess.StartInfo.UseShellExecute = false;
				FBProcess.StartInfo.CreateNoWindow = true;
				var SystemEncoding = System.Globalization.CultureInfo.GetCultureInfo(GetSystemDefaultLCID()).TextInfo.OEMCodePage;
				FBProcess.StartInfo.StandardOutputEncoding = System.Text.Encoding.GetEncoding(SystemEncoding);

				System.Diagnostics.DataReceivedEventHandler OutputEventHandler = (Sender, Args) =>
				{
					if (Args.Data != null)
						fbPackage.m_outputPane.OutputString(Args.Data + "\r");
				};

				FBProcess.OutputDataReceived += OutputEventHandler;
				FBProcess.Start();
				FBProcess.BeginOutputReadLine();
				//FBProcess.WaitForExit();
			}
			catch (Exception ex)
			{
				fbPackage.m_outputPane.OutputString("VSIX exception launching msfastbuild. Could be a broken VSIX? Exception: " + ex.Message + "\r");
			}

			Window window = fbPackage.m_dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
			window.Activate();
		}
        void GetVariableValues(VarValues var_values)
        {
            DTE2        dte = (DTE2)m_Package.GetInterface(typeof(DTE));
            IVsSolution vs_solution = (IVsSolution)m_Package.GetInterface(typeof(IVsSolution));
            string      temp_solution_dir, temp_solution_options;

            if (VSConstants.S_OK != vs_solution.GetSolutionInfo(out temp_solution_dir, out var_values.sln_path, out temp_solution_options) || var_values.sln_path == null)
            {
                var_values.sln_path = "";
            }

            IVsDebugger debugger = (IVsDebugger)m_Package.GetInterface(typeof(IVsDebugger));

            DBGMODE[] adbgmode = new DBGMODE[] { DBGMODE.DBGMODE_Design };
            if (VSConstants.S_OK != debugger.GetMode(adbgmode))
            {
                adbgmode[0] = DBGMODE.DBGMODE_Design;
            }
            var_values.dbgmode = adbgmode[0] & ~DBGMODE.DBGMODE_EncMask;

            var_values.sln_dirty = !dte.Solution.Saved;

            try
            {
                SolutionConfiguration2 active_cfg = (SolutionConfiguration2)dte.Solution.SolutionBuild.ActiveConfiguration;
                if (active_cfg != null)
                {
                    var_values.configuration = active_cfg.Name == null ? "" : active_cfg.Name;;
                    var_values.platform      = active_cfg.PlatformName == null ? "" : active_cfg.PlatformName;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                Project startup_project = GetStartupProject(dte.Solution);
                if (startup_project != null)
                {
                    var_values.startup_proj       = startup_project.Name;
                    var_values.startup_proj_path  = startup_project.FullName;
                    var_values.startup_proj_dirty = !startup_project.Saved;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                Document active_document = dte.ActiveDocument;
                if (active_document != null)
                {
                    var_values.doc_path  = active_document.FullName;
                    var_values.doc_dirty = !active_document.Saved;
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                foreach (Document doc in dte.Documents)
                {
                    if (!doc.Saved)
                    {
                        var_values.any_doc_dirty = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                foreach (Project proj in dte.Solution.Projects)
                {
                    if (!proj.Saved)
                    {
                        var_values.any_proj_dirty = true;
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            try
            {
                var_values.wnd_minimized  = m_Package.VSMainWindow.Minimized;
                var_values.wnd_foreground = m_Package.VSMainWindow.IsForegroundWindow();
                var_values.app_active     = m_Package.VSMainWindow.IsAppActive;
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }

            IntPtr active_wnd = GetActiveWindow();

            if (active_wnd != IntPtr.Zero)
            {
                var_values.active_wnd_title = GetWindowText(active_wnd);
                var_values.active_wnd_class = GetWindowClassName(active_wnd);
            }

            var_values.orig_title = m_Package.VSMainWindow.OriginalTitle;

            try
            {
                var_values.cmdline = Marshal.PtrToStringAuto(GetCommandLine());
            }
            catch (System.Exception ex)
            {
                var_values.exceptions.Add(ex);
            }
        }
예제 #22
0
 /// <summary>
 /// Compatible format: 'configname'|'platformname'
 /// http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivscfg.get_displayname.aspx
 /// </summary>
 public string SolutionCfgFormat(SolutionConfiguration2 cfg)
 {
     if(cfg == null) {
         return String.Format("{0}|{0}", PROP_UNAV_STRING);
     }
     return String.Format("{0}|{1}", cfg.Name, cfg.PlatformName);
 }
예제 #23
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void ExecuteAsync(object sender, EventArgs e)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            string title = "TrustSource Scanner";

            logger.Debug($"TrustSource scanner Initiated");
            string OptionalBranch = "", OptionalTag = "";

            TrustSourceSettings tsSettings = ((TrustSourceToolsOptions)package).TrustSourceApiSettings;
            bool IsApiConfigured           = !(tsSettings == null || string.IsNullOrEmpty(tsSettings.ApiKey));

            if (!IsApiConfigured)
            {
                string message = "TrustSource Api credentials are not avialable. Please go to Tools preferences and set TrustSource credentails.";
                logger.Debug(message);

                VsShellUtilities.ShowMessageBox(
                    this.package,
                    message,
                    title,
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return;
            }

            DTE dte = (DTE)await ServiceProvider.GetServiceAsync(typeof(DTE));

            if (dte != null && !dte.Application.Solution.IsOpen)
            {
                string message = "There is no solution open. Please first open a solution and try again.";
                logger.Debug(message);

                VsShellUtilities.ShowMessageBox(
                    this.package,
                    message,
                    title,
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return;
            }

            IVsStatusbar statusBar = (IVsStatusbar)await ServiceProvider.GetServiceAsync(typeof(SVsStatusbar));

            if (statusBar != null)
            {
                // Make sure the status bar is not frozen
                int frozen;

                statusBar.IsFrozen(out frozen);

                if (frozen != 0)
                {
                    statusBar.FreezeOutput(0);
                }

                statusBar.SetText("TrustSource Scanner is in progress..");
                statusBar.FreezeOutput(1);
            }

            if (tsSettings.AskOptional)
            {
                string message = "Dialog for optional parameters";
                logger.Debug(message);

                var  optionalParamsWindow = new OptionalParamsWindow();
                bool?IsProceed            = optionalParamsWindow.ShowDialog();

                if (IsProceed.HasValue && IsProceed.Value)
                {
                    OptionalBranch = optionalParamsWindow.Branch;
                    OptionalTag    = optionalParamsWindow.TagValue;
                }
            }

            try
            {
                SolutionBuild          builder = dte.Application.Solution.SolutionBuild;
                SolutionConfiguration2 config  = (SolutionConfiguration2)builder.ActiveConfiguration;

                /*
                 *              var activeProject = Helper.GetActiveProject(dte);
                 *              if (activeProject == null)
                 *              {
                 *                  throw new Exception("No project is selected. Please, select a project in the solution explorer.");
                 *              }
                 *
                 *              string projectPath = activeProject.FullName;
                 */

                var activeSolution = dte.Solution;
                if (activeSolution == null)
                {
                    throw new Exception("No active solution is found.");
                }

                var projectPath = activeSolution.FullName;

                logger.Debug($"TrustSource Api Key: {tsSettings.ApiKey}");
                logger.Debug($"Project Path: {projectPath}");
                logger.Debug($"Branch (optional): {OptionalBranch}");
                logger.Debug($"Tag (optional): {OptionalTag}");

                logger.Debug($"TrustSource scanner started process");
                Scanner.Initiate(projectPath, tsSettings.ApiKey, "", OptionalBranch, OptionalTag);

                statusBar.FreezeOutput(0);
                statusBar.Clear();
                statusBar.SetText("TrustSource Scan is completed");
                statusBar.FreezeOutput(1);
                statusBar.Clear();

                logger.Debug($"Scan completed successfully.");
                System.Windows.Forms.MessageBox.Show("TrustSource scan is completed", "TrustSource");
            }
            catch (Exception ex)
            {
                logger.Debug($"Exception - Error message: {ex.Message}");
                logger.Debug($"Exception - Stack Trace: {ex.StackTrace}");

                logger.Error($"Scan failed.");

                // Show a message box to prove we were here
                VsShellUtilities.ShowMessageBox(
                    this.package,
                    ex.Message,
                    title,
                    OLEMSGICON.OLEMSGICON_CRITICAL,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                statusBar.SetText("TrustSource Scan: Something went wrong");
                statusBar.FreezeOutput(0);
                statusBar.Clear();

                return;
            }
        }
예제 #24
0
        public void Exec(string commandName,
                         EnvDTE.vsCommandExecOption executeOption,
                         ref object varIn,
                         ref object varOut,
                         ref bool handled)
        {
            try
            {
                handled = false;
                if (executeOption == EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
                {
                    switch (commandName)
                    {
                    case Res.LaunchDesignerFullCommand:
                        handled = true;
                        extLoader.loadDesigner(null);
                        break;

                    case Res.LaunchLinguistFullCommand:
                        handled = true;
                        ExtLoader.loadLinguist(null);
                        break;

                    case Res.LaunchAssistantFullCommand:
                        handled = true;
                        ExtLoader.loadAssistant();
                        break;

                    case Res.ImportProFileFullCommand:
                        handled = true;
                        ExtLoader.ImportProFile();
                        break;

                    case Res.ImportPriFileFullCommand:
                        handled = true;
                        ExtLoader.ImportPriFile(HelperFunctions.GetSelectedQtProject(_applicationObject));
                        break;

                    case Res.ExportPriFileFullCommand:
                        handled = true;
                        ExtLoader.ExportPriFile();
                        break;

                    case Res.ExportProFileFullCommand:
                        handled = true;
                        ExtLoader.ExportProFile();
                        break;

                    case Res.ChangeSolutionQtVersionFullCommand:
                        QtVersionManager vManager = QtVersionManager.The();
                        if (formChangeQtVersion == null)
                        {
                            formChangeQtVersion = new FormChangeQtVersion();
                        }
                        formChangeQtVersion.UpdateContent(ChangeFor.Solution);
                        if (formChangeQtVersion.ShowDialog() == DialogResult.OK)
                        {
                            string newQtVersion = formChangeQtVersion.GetSelectedQtVersion();
                            if (newQtVersion != null)
                            {
                                string currentPlatform = null;
                                try
                                {
                                    SolutionConfiguration  config  = _applicationObject.Solution.SolutionBuild.ActiveConfiguration;
                                    SolutionConfiguration2 config2 = config as SolutionConfiguration2;
                                    currentPlatform = config2.PlatformName;
                                }
                                catch
                                {
                                }
                                if (string.IsNullOrEmpty(currentPlatform))
                                {
                                    return;
                                }

                                vManager.SetPlatform(currentPlatform);

                                foreach (Project project in HelperFunctions.ProjectsInSolution(_applicationObject))
                                {
                                    if (HelperFunctions.IsQt5Project(project))
                                    {
                                        string OldQtVersion = vManager.GetProjectQtVersion(project, currentPlatform);
                                        if (OldQtVersion == null)
                                        {
                                            OldQtVersion = vManager.GetDefaultVersion();
                                        }

                                        QtProject qtProject         = QtProject.Create(project);
                                        bool      newProjectCreated = false;
                                        qtProject.ChangeQtVersion(OldQtVersion, newQtVersion, ref newProjectCreated);
                                    }
                                }
                                vManager.SaveSolutionQtVersion(_applicationObject.Solution, newQtVersion);
                            }
                        }
                        break;

                    case Res.ProjectQtSettingsFullCommand:
                        handled = true;
                        EnvDTE.DTE dte = _applicationObject;
                        Project    pro = HelperFunctions.GetSelectedQtProject(dte);
                        if (pro != null)
                        {
                            if (formProjectQtSettings == null)
                            {
                                formProjectQtSettings = new FormProjectQtSettings();
                            }
                            formProjectQtSettings.SetProject(pro);
                            formProjectQtSettings.StartPosition = FormStartPosition.CenterParent;
                            MainWinWrapper ww = new MainWinWrapper(dte);
                            formProjectQtSettings.ShowDialog(ww);
                        }
                        else
                        {
                            MessageBox.Show(SR.GetString("NoProjectOpened"));
                        }
                        break;

                    case Res.ChangeProjectQtVersionFullCommand:
                        handled = true;
                        dte     = _applicationObject;
                        pro     = HelperFunctions.GetSelectedProject(dte);
                        if (pro != null && HelperFunctions.IsQMakeProject(pro))
                        {
                            if (formChangeQtVersion == null)
                            {
                                formChangeQtVersion = new FormChangeQtVersion();
                            }
                            formChangeQtVersion.UpdateContent(ChangeFor.Project);
                            MainWinWrapper ww = new MainWinWrapper(dte);
                            if (formChangeQtVersion.ShowDialog(ww) == DialogResult.OK)
                            {
                                string           qtVersion = formChangeQtVersion.GetSelectedQtVersion();
                                QtVersionManager vm        = QtVersionManager.The();
                                string           qtPath    = vm.GetInstallPath(qtVersion);
                                HelperFunctions.SetDebuggingEnvironment(pro, "PATH=" + qtPath + "\\bin;$(PATH)", true);
                            }
                        }
                        break;

                    case Res.VSQtOptionsFullCommand:
                        handled = true;
                        if (formQtVersions == null)
                        {
                            formQtVersions = new FormVSQtSettings();
                            formQtVersions.LoadSettings();
                        }
                        formQtVersions.StartPosition = FormStartPosition.CenterParent;
                        MainWinWrapper mww = new MainWinWrapper(_applicationObject);
                        if (formQtVersions.ShowDialog(mww) == DialogResult.OK)
                        {
                            formQtVersions.SaveSettings();
                        }
                        break;

                    case Res.CreateNewTranslationFileFullCommand:
                        handled = true;
                        pro     = HelperFunctions.GetSelectedQtProject(_applicationObject);
                        Translation.CreateNewTranslationFile(pro);
                        break;

                    case Res.CommandBarName + ".Connect.lupdate":
                        handled = true;
                        Translation.RunlUpdate(HelperFunctions.GetSelectedFiles(_applicationObject),
                                               HelperFunctions.GetSelectedQtProject(_applicationObject));
                        break;

                    case Res.CommandBarName + ".Connect.lrelease":
                        handled = true;
                        Translation.RunlRelease(HelperFunctions.GetSelectedFiles(_applicationObject));
                        break;

                    case Res.lupdateProjectFullCommand:
                        handled = true;
                        pro     = HelperFunctions.GetSelectedQtProject(Connect._applicationObject);
                        Translation.RunlUpdate(pro);
                        break;

                    case Res.lreleaseProjectFullCommand:
                        handled = true;
                        pro     = HelperFunctions.GetSelectedQtProject(Connect._applicationObject);
                        Translation.RunlRelease(pro);
                        break;

                    case Res.lupdateSolutionFullCommand:
                        handled = true;
                        Translation.RunlUpdate(Connect._applicationObject.Solution);
                        break;

                    case Res.lreleaseSolutionFullCommand:
                        handled = true;
                        Translation.RunlRelease(Connect._applicationObject.Solution);
                        break;

                    case Res.ConvertToQtFullCommand:
                    case Res.ConvertToQMakeFullCommand:
                        if (MessageBox.Show(SR.GetString("ConvertConfirmation"), SR.GetString("ConvertTitle"), MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            handled = true;
                            dte     = _applicationObject;
                            pro     = HelperFunctions.GetSelectedProject(dte);
                            HelperFunctions.ToggleProjectKind(pro);
                        }
                        break;
                    }
                }
            }
            catch (System.Exception e)
            {
                MessageBox.Show(e.Message + "\r\n\r\nStacktrace:\r\n" + e.StackTrace);
            }
        }
예제 #25
0
 //---------------------------------------------------------------------
 public string GetSolutionConfigurationName(SolutionConfiguration2 activeConfiguration)
 {
     return(activeConfiguration.Name + '|' + activeConfiguration.PlatformName);
 }
예제 #26
0
 /// <summary>
 /// Compatible format: 'configname'|'platformname'
 /// http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.shell.interop.ivscfg.get_displayname.aspx
 /// </summary>
 public string SolutionCfgFormat(SolutionConfiguration2 cfg)
 {
     return String.Format("{0}|{1}", cfg.Name, cfg.PlatformName);
 }
예제 #27
0
    public static bool TryGetActiveSolutionConfiguration(
        IServiceProvider serviceProvider,
        out SolutionBuild solutionBuild,
        out SolutionConfiguration2 activeConfiguration)
    {
      Contract.Requires(serviceProvider != null);
      Contract.Ensures(Contract.ValueAtReturn(out solutionBuild) != null || !Contract.Result<bool>());
      Contract.Ensures(Contract.ValueAtReturn(out activeConfiguration) != null || !Contract.Result<bool>());

      solutionBuild = null;
      activeConfiguration = null;

      DTE dte = VsServiceProviderHelper.GetService<DTE>(serviceProvider);
      if (dte == null)
        return false;
      var solution = dte.Solution;
      if (solution == null)
        return false;
      solutionBuild = solution.SolutionBuild;
      Contract.Assume(solutionBuild != null);
      activeConfiguration = solutionBuild.ActiveConfiguration as SolutionConfiguration2;

      return solutionBuild != null && activeConfiguration != null;
    }
예제 #28
0
 public SolutionConfiguration(SolutionConfiguration2 c)
 {
     Name          = c.Name;
     PlatformName  = c.PlatformName;
     Configuration = c;
 }