VSL 2013はVSL 2008の共同コンパイルを使ってプロジェクトコンパイルを行う.
23150 ワード
会社開発C++はVs 2008を使って、コンパイルする時にインタークリエードを使ってコンパイルします.vs 2008でvisual assityxを使用しています.コードが長すぎると、スクロールする時にたまにページの文字化けが発生します.また、時には虚数関数の位置付けに問題があります.vs 2013の使用は便利ではありませんが、vs 2013では直接コンパイルできません.すべての考えをプラグインにして翻訳問題を解決します.
プロジェクトファイルはすべてvc 9を使って生成されたので、すべてvs 2013を使って開くと、自動的にプロジェクトのアップグレードが行われ、アップグレードが完了した後、vc 9とvs 2013の工事会が同時に存在します.vs 2013でvs 2008のコンパイラを呼び出したいならば、共同コンパイルでvs 2008のプロジェクトファイルのコンパイルを呼び出すことができます.
1、vs 2013のプラグインプロジェクトを作成する.
2、connect.csでは関数OnConnectionを修正し、最後にコードを追加し、メニューを追加します.
4、実行する時、獲得したプロジェクトファイルに基づいて、パスを解析し、共同コンパイルを使ったスクリプトを作成すればいいです.
プロジェクトファイルはすべてvc 9を使って生成されたので、すべてvs 2013を使って開くと、自動的にプロジェクトのアップグレードが行われ、アップグレードが完了した後、vc 9とvs 2013の工事会が同時に存在します.vs 2013でvs 2008のコンパイラを呼び出したいならば、共同コンパイルでvs 2008のプロジェクトファイルのコンパイルを呼び出すことができます.
1、vs 2013のプラグインプロジェクトを作成する.
2、connect.csでは関数OnConnectionを修正し、最後にコードを追加し、メニューを追加します.
1 try
2 {
3 //Add a command to the Commands collection:
4 Command command = commands.AddNamedCommand2(_addInInstance, "MyAddin1", "MyAddin1", "Executes the command for MyAddin1", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
5
6 //Add a control for the command to the tools menu:
7 if((command != null) && (toolsPopup != null))
8 {
9 command.AddControl(toolsPopup.CommandBar, 1);
10 }
11 CommandBar slnCommandBar = GetCommandBarByName("Project");
12 // Add a new command
13 AddNamedCommand2(slnCommandBar, "Build",
14 "Build By IncreBuild", "Build By IncreBuild", false, 0, 1);
15 }
16 catch(System.ArgumentException)
17 {
18 //If we are here, then the exception is probably because a command with that name
19 // already exists. If so there is no need to recreate the command and we can
20 // safely ignore the exception.
21 }
3、関数QuerySttusを変更してメニューを表示します. 1 public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText)
2 {
3 if(neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone)
4 {
5 if(commandName == "MyAddin1.Connect.MyAddin1")
6 {
7 status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported|vsCommandStatus.vsCommandStatusEnabled;
8 return;
9 }
10 if (commandName == "MyAddin1.Connect.Build")
11 {
12 status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
13 return;
14 }
15 }
16 }
4、実行する時、獲得したプロジェクトファイルに基づいて、パスを解析し、共同コンパイルを使ったスクリプトを作成すればいいです.
1 public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
2 {
3 handled = false;
4 if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
5 {
6 if(commandName == "MyAddin1.Connect.MyAddin1")
7 {
8 handled = true;
9 return;
10 }
11 else if (commandName == "MyAddin1.Connect.Build")
12 {
13 try
14 {
15 SelectedItems items = _applicationObject.SelectedItems;
16 System.Array projs = items.DTE.ActiveSolutionProjects as System.Array;
17 string projectname = null;
18 foreach (Project item in projs)
19 {
20 projectname = item.UniqueName;
21 }
22 if (null != projectname)
23 {
24 BuildProject(projectname);
25 }
26 }
27 catch(Exception e)
28 {
29
30 }
31 handled = true;
32 return;
33 }
34 }
35 }
36
37 private void BuildProject(string Proj)
38 {
39 if(!File.Exists(Proj))
40 {
41 return;
42 }
43 if(!Proj.Contains("vcxproj"))
44 {
45 return;
46 }
47 string oldprj = Proj.Replace("vcxproj", "vcproj");
48 if(!File.Exists(oldprj))
49 {
50 return;
51 }
52 XmlDocument xdoc = new XmlDocument();
53 xdoc.Load(oldprj);
54 XmlElement root=xdoc.SelectSingleNode("VisualStudioProject") as XmlElement;
55 if(root.GetAttribute("ProjectType") != "Visual C++" ||
56 root.GetAttribute("Version") != "9.00")
57 {
58 return;
59 }
60 string projname=root.GetAttribute("Name");
61 List<string> lstconfig = new List<string>();
62 XmlNodeList lstconfignode = xdoc.SelectNodes("//VisualStudioProject/Configurations/Configuration");
63 foreach(XmlElement item in lstconfignode)
64 {
65 lstconfig.Add(item.GetAttribute("Name"));
66 }
67 if(lstconfig.Count<=0)
68 {
69 return;
70 }
71
72 DirectoryInfo dir = Directory.GetParent(oldprj);
73 string batfile = dir.ToString() +"\\"+ projname + ".bat";
74 StreamWriter sw = new StreamWriter(batfile);
75 sw.Write("buildconsole ");
76 sw.Write(oldprj);
77 sw.Write(" /prj=\"");
78 sw.Write(projname);
79 sw.Write("\" /build /OpenMonitor /cfg=\"");
80 sw.Write(lstconfig[0]);
81 sw.Write("\"\r
");
82 sw.Flush();
83 sw.Close();
84
85
86
87 System.Threading.Thread t = new System.Threading.Thread(new ThreadStart(() => {
88 ProcessStartInfo info = new ProcessStartInfo(batfile);
89 info.CreateNoWindow = true;
90 info.RedirectStandardOutput = false;
91 info.RedirectStandardInput = false;
92 info.UseShellExecute = true;
93 System.Diagnostics.Process p = System.Diagnostics.Process.Start(info);
94 p.WaitForExit();
95 }));
96 t.Start();
97
98
99 }