int IVsSolutionEvents.OnAfterOpenSolution(object pUnkReserved, int fNewSolution) { string solutionDirectory; string solutionFile; string userOptsFile; solution.GetSolutionInfo(out solutionDirectory, out solutionFile, out userOptsFile); solutionFile = solutionFile.Substring(solutionFile.LastIndexOf(("\\")) + 1); Dictionary <string, int> dictionary = new Dictionary <string, int>(); List <string> projectInfo = new List <string>(); List <string> projectUniqueName = new List <string>(); ProjectParser parser = new ProjectParser(); int enableInfo = 0; foreach (Project project in GetProjects(solution)) { if (project.FileName == "") { continue; } projectInfo.Add(project.FileName); projectUniqueName.Add(project.UniqueName); } for (int i = 0; i < projectInfo.Count; ++i) { string projectPathInfo = projectInfo[i]; parser.ModifyUnityBuildXML(projectPathInfo, solutionFile, false, projectUniqueName[i], true); enableInfo = parser.GetUnityBuildMenuInfo(); dictionary.Add(projectPathInfo, enableInfo); } SetUnityBuildDirectoryInfo(dictionary); return(VSConstants.S_OK); }
private void Execute(object sender, EventArgs e) { OleMenuCommand mc = sender as OleMenuCommand; ThreadHelper.ThrowIfNotOnUIThread(); string message = string.Format(CultureInfo.CurrentCulture, "UnityBuildProject", sender.GetType().FullName); EnvDTE.DTE dte; EnvDTE.Project project; object[] activeSolutionProjects; string title = "UnityBuildProject"; bool UnityBuild = false; ProjectParser projParser = new ProjectParser(); EnvDTE80.DTE2 dte2 = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE80.DTE2; string slnFilePath = dte2.Solution.FileName; slnFilePath = Path.GetDirectoryName(slnFilePath); string slnFileName = ""; DirectoryInfo directory = new DirectoryInfo(slnFilePath); foreach (FileInfo file in directory.GetFiles()) { if (file.Extension.ToLower().CompareTo(".sln") == 0) { slnFileName = file.Name.Substring(0, file.Name.Length); } } dte = (EnvDTE.DTE)Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider.GetService(typeof(EnvDTE.DTE)); activeSolutionProjects = dte.ActiveSolutionProjects as object[]; if (activeSolutionProjects != null) { foreach (object activeSolutionProject in activeSolutionProjects) { project = activeSolutionProject as EnvDTE.Project; if (project != null) { message = $"Called on {project.FullName}"; string projFileName = project.FileName; string uniqueName = project.UniqueName; int result = VsShellUtilities.ShowMessageBox( package, message, title, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); if (result == (int)VSConstants.MessageBoxResult.IDOK) { if (mc.CommandID.ID == 257) { UnityBuild = true; projParser.ModifyUnityBuildXML(projFileName, slnFileName, UnityBuild, uniqueName, false); } else if (mc.CommandID.ID == 258) { UnityBuild = false; projParser.ModifyUnityBuildXML(projFileName, slnFileName, UnityBuild, uniqueName, false); } for (int i = 0; i < listDic.Count; i++) { if (listDic[i].Key.Contains(projFileName)) { if (projectDic[projFileName] == 2) { projectDic[projFileName] = 0; } else if (projectDic[projFileName] == 1) { projectDic[projFileName] = 0; } else if (projectDic[projFileName] == 0) { projectDic[projFileName] = 1; } } } } } } } }
private void Execute(object sender, EventArgs e) { OleMenuCommand mc = sender as OleMenuCommand; ThreadHelper.ThrowIfNotOnUIThread(); string message = string.Format(CultureInfo.CurrentCulture, "SolutionUnityBuildProject", this.GetType().FullName); string title = "SolutionUnityBuildControl"; ProjectParser projParser = new ProjectParser(); DTE2 dte2 = Package.GetGlobalService(typeof(DTE)) as DTE2; string slnFilePath = dte2.Solution.FileName; slnFilePath = Path.GetDirectoryName(slnFilePath); string slnFileName = ""; DirectoryInfo directory = new DirectoryInfo(slnFilePath); foreach (FileInfo file in directory.GetFiles()) { if (file.Extension.ToLower().CompareTo(".sln") == 0) { slnFileName = file.Name.Substring(0, file.Name.Length); } } List <string> projFiles = new List <string>(); IList <Project> projFilePaths; projFilePaths = Projects(); bool unitybuild = false; int result = VsShellUtilities.ShowMessageBox( this.package, message, title, OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); if (result == (int)VSConstants.MessageBoxResult.IDOK) { if (mc.CommandID.ID == 0x0103) { unitybuild = true; } else if (mc.CommandID.ID == 0x0104) { unitybuild = false; } for (int i = 0; i < listDic.Count; i++) { projParser.ModifyUnityBuildXML(listDic[i].Key, slnFileName, unitybuild, projFilePaths[i].UniqueName, false); if (listDic[i].Key.Contains(listDic[i].Key)) { if (unitybuild == true) { projectDic[listDic[i].Key] = 0; } else { projectDic[listDic[i].Key] = 1; } } } } }