/// <summary> /// Called when the whole build completes. /// /// Calculate and display the total build time. Also sort the project durations and display them. /// </summary> public void OnBuildDone(EnvDTE.vsBuildScope Scope, EnvDTE.vsBuildAction Action) { // Check if we are actually timing this build if (amTiming) { amTiming = false; dtEnd = DateTime.Now; m_OutputWindowPane.OutputString(String.Format("\n 现在结束编译,开始时间为: {0},结束时间:{1}\n", dtStart, dtEnd)); TimeSpan tsElapsed = dtEnd - dtStart; m_OutputWindowPane.OutputString(String.Format("\n全部编译时间为: {0}\n", tsElapsed)); } if (m_IsBuildOrRebuild) { m_IsBuildOrRebuild = false; if (m_envcfgs == null) { m_envcfgs = new ThkEnvCfgs(); m_envcfgs.LoadConfig(); } ThkVCDirSet vcset = m_envcfgs.GetVCConfig(); if (vcset == null) { m_OutputWindowPane.OutputString("\n跨过:未找到森科编译环境配置信息\n"); return; } ThkVCDirItem curVc = vcset.GetCurVCItem(); if (curVc != null && curVc.StrVCDir != null && curVc.StrVCDir.Length > 0) { Environment.SetEnvironmentVariable("VCInstallDir", curVc.StrVCDir, EnvironmentVariableTarget.Process); } if (curVc.StrVCVer == null) { curVc.StrVCVer = "未知版本"; } m_OutputWindowPane.OutputString("\n森科开发项目编译结束,自动转换成缺省配置.." + curVc.StrVCVer + "....成功!\n"); } }
/// <summary> /// Called when each project build begins. /// /// Record the start time of the project. /// </summary> void OnBuildProjConfigBegin(string Project, string ProjectConfig, string Platform, string SolutionConfig) { m_OutputWindowPane.OutputString("\n正准备生成项目 " + Project + ":" + ProjectConfig + ":" + Platform + ":" + SolutionConfig); m_OutputWindowPane.OutputString("\n森科开发环境将自动进行编译环境处理......\n"); if (m_envcfgs == null) { m_envcfgs = new ThkEnvCfgs(); m_envcfgs.LoadConfig(); } ThkVCDirSet vcset = m_envcfgs.GetVCConfig(); if (vcset == null) { m_OutputWindowPane.OutputString("\n错误:未找到森科编译环境配置信息\n"); return; } ThkVCDirItem curVc = new ThkVCDirItem(); if (ProjectConfig.IndexOf("WF") != -1 || ProjectConfig.IndexOf("VC9") != -1 || ProjectConfig.IndexOf("ThkRelease") != -1) { curVc = vcset.GetVcItem("VC2008"); } else if (ProjectConfig.IndexOf("CR") != -1) { curVc = vcset.GetVcItem("VC2010"); } else { curVc = vcset.GetCurVCItem(); } //if (curVc != null && curVc.StrVCDir != null && curVc.StrVCDir.Length > 0) //{ // Environment.SetEnvironmentVariable("VCInstallDir", curVc.StrVCDir, EnvironmentVariableTarget.Process); //} //if (curVc.StrVCVer == null) // curVc.StrVCVer = "未知版本"; //m_OutputWindowPane.OutputString("\n森科开发环境开始进行."+Platform+".平台配置.....\n"); ThkEnvConfig enc = m_envcfgs.GetCurEnvConfig(); if (enc != null) { ThkEnvCfgItem[] encitems = enc.EnvConfigItems; foreach (ThkEnvCfgItem ci in encitems) { if (String.Compare(ci.EnvCfgFlatform, Platform, true) == 0) { Environment.SetEnvironmentVariable(ci.EnvCfgItem, ci.EnvCfgValue, EnvironmentVariableTarget.Process); } } } m_OutputWindowPane.OutputString("\n森科开发环境切换.." + curVc.StrVCVer + "....成功!\n"); string strthkapi = Environment.GetEnvironmentVariable("ThkApi"); if (strthkapi == null || strthkapi.Length == 0) { strthkapi = "未配置"; } m_OutputWindowPane.OutputString("\n当前...ThkApi 内容为." + strthkapi + "....\n"); strthkapi = Environment.GetEnvironmentVariable("ThkProApi"); if (strthkapi == null || strthkapi.Length == 0) { strthkapi = "未配置"; } m_OutputWindowPane.OutputString("\n当前...ThkProApi 内容为." + strthkapi + "....\n"); }
/// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary> /// <param term='application'>宿主应用程序的根对象。</param> /// <param term='connectMode'>描述外接程序的加载方式。</param> /// <param term='addInInst'>表示此外接程序的对象。</param> /// <seealso class='IDTExtensibility2' /> public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; OutputWindow outputWindow = (OutputWindow)_applicationObject.Windows.Item(Constants.vsWindowKindOutput).Object; bool bbuildok = true; try { m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("生成"); } catch { //我们试图查找“工具”一词的本地化版本,但未能找到。 // 默认值为 en-US 单词,该值可能适用于当前区域性。 bbuildok = false; } if (!bbuildok) { try { m_OutputWindowPane = outputWindow.OutputWindowPanes.Item("Build"); } catch { //我们试图查找“工具”一词的本地化版本,但未能找到。 // 默认值为 en-US 单词,该值可能适用于当前区域性。 bbuildok = false; } } // Register for the various build events taht we're hooking in to EnvDTE.Events events = _applicationObject.Events; m_BuildEvents = (EnvDTE.BuildEvents)events.BuildEvents; m_BuildEvents.OnBuildProjConfigBegin += new _dispBuildEvents_OnBuildProjConfigBeginEventHandler(OnBuildProjConfigBegin); m_BuildEvents.OnBuildProjConfigDone += new _dispBuildEvents_OnBuildProjConfigDoneEventHandler(OnBuildProjConfigDone); m_BuildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin); m_BuildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(this.OnBuildDone); m_envcfgs = new ThkEnvCfgs(); if (m_envcfgs.LoadConfig()) { ThkEnvConfig enc = m_envcfgs.GetCurEnvConfig(); if (enc != null) { //if (m_OutputWindowPane != null) //{ // m_OutputWindowPane.OutputString("现在开始自动设置配置信息中的环境变量\n"); //} ThkEnvCfgItem[] encitems = enc.EnvConfigItems; foreach (ThkEnvCfgItem ci in encitems) { if (ci.EnvCfgFlatform == null || ci.EnvCfgFlatform.Length == 0 || ci.EnvCfgFlatform == "全部" || ci.EnvCfgFlatform == "") { Environment.SetEnvironmentVariable(ci.EnvCfgItem, ci.EnvCfgValue, EnvironmentVariableTarget.Process); //if (m_OutputWindowPane !=null) //{ // m_OutputWindowPane.OutputString(ci.EnvCfgItem + ":" + ci.EnvCfgValue+"\n"); //} } } } else { MessageBox.Show("获取配置中的环境变量信息失败"); } } else { MessageBox.Show("加载配置变量配置文件失败"); } { string path = System.Environment.CurrentDirectory; Assembly myAssembly = Assembly.GetEntryAssembly(); if (myAssembly == null) { myAssembly = Assembly.GetExecutingAssembly(); } if (myAssembly != null) { path = myAssembly.Location; DirectoryInfo dr = new DirectoryInfo(path); path = dr.Parent.FullName; //当前目录的上一级目录 } Environment.SetEnvironmentVariable("THK_VS_ADDIN_PATH", path, EnvironmentVariableTarget.Process); } //debug ThkVCDirSet vcset = m_envcfgs.GetVCConfig(); if (vcset != null && vcset.EnvConfigItems.Length < 2) { //vcset.AddVcConfig("VC6", @"D:\develop\VS60\VC98\", ""); //vcset.AddVcConfig("VC2003", @"D:\develop\vs2002\Vc7\", ""); //vcset.AddVcConfig("VC2003", @"D:\develop\vs2003\Vc7\", ""); //vcset.AddVcConfig("VC2005", @"D:\develop\vs2005\Vc\", ""); //vcset.AddVcConfig("VC2008", @"D:\develop\vs2008\Vc\", ""); //vcset.AddVcConfig("VC2010", @"D:\develop\vs2010\Vc\", ""); //vcset.AddVcConfig("VC2012", @"D:\develop\vs2012\Vc\", ""); //vcset.AddVcConfig("VC2013", @"D:\develop\vs2013\Vc\", ""); //m_envcfgs.SaveConfig(); } //end of debug if (connectMode == ext_ConnectMode.ext_cm_CommandLine || connectMode == ext_ConnectMode.ext_cm_AfterStartup || connectMode == ext_ConnectMode.ext_cm_UISetup || connectMode == ext_ConnectMode.ext_cm_Startup) { object[] contextGUIDS = new object[] { }; Commands2 commands = (Commands2)_applicationObject.Commands; string toolsMenuName; try { //若要将此命令移动到另一个菜单,则将“工具”一词更改为此菜单的英文版。 // 此代码将获取区域性,将其追加到菜单名中,然后将此命令添加到该菜单中。 // 您会在此文件中看到全部顶级菜单的列表 // CommandBar.resx. string resourceName; ResourceManager resourceManager = new ResourceManager("ThkDevEnc.CommandBar", Assembly.GetExecutingAssembly()); CultureInfo cultureInfo = new CultureInfo(_applicationObject.LocaleID); if (cultureInfo.TwoLetterISOLanguageName == "zh") { System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent; resourceName = String.Concat(parentCultureInfo.Name, "Tools"); } else { resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, "Tools"); } toolsMenuName = resourceManager.GetString(resourceName); if (toolsMenuName == null || toolsMenuName.Length == 0) { toolsMenuName = "工具"; } } catch { //我们试图查找“工具”一词的本地化版本,但未能找到。 // 默认值为 en-US 单词,该值可能适用于当前区域性。 toolsMenuName = "Tools"; } //将此命令置于“工具”菜单上。 //查找 MenuBar 命令栏,该命令栏是容纳所有主菜单项的顶级命令栏: Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["MenuBar"]; //在 MenuBar 命令栏上查找“工具”命令栏: CommandBarControl toolsControl = menuBarCommandBar.Controls[toolsMenuName]; CommandBarPopup toolsPopup = (CommandBarPopup)toolsControl; //如果希望添加多个由您的外接程序处理的命令,可以重复此 try/catch 块, // 只需确保更新 QueryStatus/Exec 方法,使其包含新的命令名。 //////////////try //////////////{ ////////////// //将一个命令添加到 Commands 集合: ////////////// Command command = commands.AddNamedCommand2(_addInInstance, "ProUnlock", "解锁ProE插件", "Executes the command for ProUnlock", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); ////////////// //将对应于该命令的控件添加到“工具”菜单: ////////////// if ((command != null) && (toolsPopup != null)) ////////////// { ////////////// command.AddControl(toolsPopup.CommandBar, 1); ////////////// } //////////////} //////////////catch (System.ArgumentException) //////////////{ ////////////// //如果出现此异常,原因很可能是由于具有该名称的命令 ////////////// // 已存在。如果确实如此,则无需重新创建此命令,并且 ////////////// // 可以放心忽略此异常。 //////////////} try { //将一个命令添加到 Commands 集合: Command command = commands.AddNamedCommand2(_addInInstance, "ProeAttach", "调试ProE", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //将对应于该命令的控件添加到“工具”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } try { //将一个命令添加到 Commands 集合: Command command = commands.AddNamedCommand2(_addInInstance, "CatiaAttach", "调试Catia", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //将对应于该命令的控件添加到“工具”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } try { //将一个命令添加到 Commands 集合: Command command = commands.AddNamedCommand2(_addInInstance, "DevEnvCfg", "森科开发环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //将对应于该命令的控件添加到“工具”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } try { //将一个命令添加到 Commands 集合: Command command = commands.AddNamedCommand2(_addInInstance, "VCSet", "当前编译环境", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //将对应于该命令的控件添加到“工具”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } try { //将一个命令添加到 Commands 集合: Command command = commands.AddNamedCommand2(_addInInstance, "UnAttach", "全部分离调试", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //将对应于该命令的控件添加到“工具”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } try { //将一个命令添加到 Commands 集合: Command command = commands.AddNamedCommand2(_addInInstance, "CopyFile", "文件拷贝", "Executes the command for ThkDevEnc", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton); //将对应于该命令的控件添加到“工具”菜单: if ((command != null) && (toolsPopup != null)) { command.AddControl(toolsPopup.CommandBar, 1); } } catch (System.ArgumentException) { //如果出现此异常,原因很可能是由于具有该名称的命令 // 已存在。如果确实如此,则无需重新创建此命令,并且 // 可以放心忽略此异常。 } } }