作者:朱金灿
来源:http://blog.csdn.net/clever101
main(); function main() { try { var WSShell = WScript.CreateObject("WScript.Shell"); var num = WScript.ScriptFullName.lastIndexOf("\"); // 获取当前路径 var strCurPath = WScript.ScriptFullName.substr(0,num); var FileSys = WScript.CreateObject("Scripting.FileSystemObject"); // 判断当前文件夹是否存在 if (FileSys.FolderExists(strCurPath)) { // 获取vs2008d的dte对象 var DTE = new ActiveXObject("VisualStudio.DTE.9.0"); DTE.MainWindow.Visible = false; var strPluginFolder = strCurPath + "\Plugin"; // 判断临时文件夹是否存在,若不存在就创建。临时文件夹用于存放创建 var strTempPath = strCurPath + "\temp"; var strSolution = strTempPath+"\AllPlugin.sln"; if (FileSys.FileExists(strSolution)) FileSys.DeleteFile(strSolution); var sln = DTE.Solution; if(!FileSys.FolderExists(strTempPath)) { FileSys.CreateFolder(strTempPath); } // 创建空白的解决方案 sln.Create(strTempPath,"AllPlugin"); sln.SaveAs(strSolution); sln.Open(strSolution); var PluginFolder = FileSys.GetFolder(strPluginFolder); // 获取所有子文件夹,遍历所有的子文件夹 var PlugSet = new Enumerator(PluginFolder.SubFolders); for (var i = 0 ; !PlugSet.atEnd(); PlugSet.moveNext(),i++) { var strProjectFolder = strPluginFolder + "\"; strProjectFolder = strProjectFolder + PlugSet.item().Name; var ProjectFolder = FileSys.GetFolder(strProjectFolder); // 获取所有的文件 var fenum = new Enumerator(ProjectFolder.Files); for (var j = 0 ; !fenum.atEnd(); fenum.moveNext(),j++) { var strPrjFileName = fenum.item().Name; var strSuff = FileSys.GetExtensionName(strPrjFileName); // 假如文件是vc工程文件,就加到解决方案中 if((strSuff=="vcproj")) { try { var strProjectFolder = strProjectFolder + "\"; strPrjFileName = strProjectFolder + strPrjFileName; sln.AddFromFile(strPrjFileName); sln.SaveAs(strSolution); WScript.Sleep(3000); } catch(e) { WScript.Echo(e.description); } break; } } } sln.Close(); // 关闭解决方案 } else { WScript.Echo("the current path isnot exist!"); } } catch(e) { WScript.Echo(e.description); } }