最近闲得无事,不过也是为了以后设计的一个环节,做了一个Add-Ins
主要是XSD To Entity的操作。
Step 1:先配置一下
把相关的AddIn、DLL Copy To 当前用户\文档\Visual Studio 200X\Addins
Step 2:Tools\Add-In Manager勾选即可
Step 3:现在随便打开一个project,然后在Code Windows中右击,就可以看到XSD To Entity
界面
选择一个XSD File
转换完成
转换文件
代码方面:
Connect.cs:
1 public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)XSDToEntityFrm.cs
2 {
3 _applicationObject = (DTE2)application;
4 _addInInstance = (AddIn)addInInst;
5
6 // Get the CommandBar for the window in which you want to add the menuitem.
7 //I am going to add it to the code window.
8 CommandBar oCommandBar = ((CommandBars)_applicationObject.CommandBars)["Code Window"];
9
10 // I am going to add a MenuItem and a submenuitem to that.
11 // So I go ahead and create a PopUp Item.
12 CommandBarPopup oPopup = (CommandBarPopup)oCommandBar.Controls.Add(MsoControlType.msoControlPopup,
13 System.Reflection.Missing.Value,
14 System.Reflection.Missing.Value, 1, true);
15 // Set the caption of the menuitem
16 oPopup.Caption = "XSD To Entity";
17
18 // Now I go ahead and add a Submenu item to the added Menuitem.
19 CommandBarControl oControl = oPopup.Controls.Add(MsoControlType.msoControlButton,
20 System.Reflection.Missing.Value,
21 System.Reflection.Missing.Value, 1, true);
22 // Set the caption of the submenuitem
23 oControl.Caption = "Execute";
24
25 // Now that we have added the menu items,
26 // we will associate the click events for these items.
27 // I will associate a click event only for the SubMenuitem at present.
28 oSubMenuItemHandler = (CommandBarEvents)_applicationObject.Events.get_CommandBarEvents(oControl);
29 oSubMenuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(oSubMenuItemHandler_Click);
30 }
31
32 /// <summary>
33 /// Invoked on click of sub menu item.
34 /// </summary>
35 protected void oSubMenuItemHandler_Click(object CommandaBarControl, ref bool handled, ref bool cancelDefault)
36 {
37 XSDToEntityFrm frm = new XSDToEntityFrm();
38 frm.ShowDialog();
39 }
System.Diagnostics.Process p = new System.Diagnostics.Process(); { p.StartInfo.FileName = "cmd.exe"; p.StartInfo.UseShellExecute = false; p.StartInfo.RedirectStandardInput = true; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.CreateNoWindow = true; p.Start(); p.StandardInput.WriteLine( String.Concat( @"%comspec% /k """"" , txtVsPath.Text , @""""" x86" ) ); p.StandardInput.WriteLine( String.Concat( @"xsd /c /language:CS " , selectFile , @" /out:" , txtOutPath.Text ) ); p.StandardInput.WriteLine( "Exit" ); p.Close(); }
完整程序 XSDToEntity
XML To XSD : xsd test.xml /outputdir:D:\
XSD TO DataSet : xsd /dataset /language:CS Test.xsd (不过,不是每个xsd都是可以转换的)
DLL To XSD : xsd Test.dll (不过,不是每个DLL都是可以转换的)