private object[] CreateList(SolutionItem solutionItem) { ArrayList arrayList = new ArrayList(); arrayList.Add("Any"); if (solutionItem.ItemType == SolutionItemType.Solution) { SolutionConfigurations solutionConfigurations = solutionItem.Solution.SolutionBuild.SolutionConfigurations; string a = ""; foreach (SolutionConfiguration solutionConfiguration in solutionConfigurations) { if (a != solutionConfiguration.Name) { arrayList.Add(solutionConfiguration.Name); a = solutionConfiguration.Name; } } } else { object[] array = (object[])solutionItem.Project.ConfigurationManager.ConfigurationRowNames; object[] array2 = array; for (int i = 0; i < array2.Length; i++) { object value = array2[i]; arrayList.Add(value); } } return arrayList.ToArray(); }
/// <summary> /// Called when a build begin event has occured. /// </summary> /// <param name="Scope">The scope.</param> /// <param name="Action">The action.</param> public void OnBuildBegin(vsBuildScope scope, vsBuildAction action) { Logger.Write("BuildEvents_OnBuildBegin scope: " + scope.ToString() + " action " + action.ToString(), LogLevel.Debug); _currentBuildState = vsBuildState.vsBuildStateInProgress; _currentBuildAction = action; _currentBuildScope = scope; _buildStartDate = DateTime.Now; ExecuteIncrement(); _updatedItems.Clear(); #if OLD try { if (action == vsBuildAction.vsBuildActionBuild || action == vsBuildAction.vsBuildActionRebuildAll) { _currentBuildVersion = CreateBuildVersion(); if (scope == vsBuildScope.vsBuildScopeSolution) { SolutionItem solutionItem = new SolutionItem(_connect.ApplicationObject.Solution); Execute(solutionItem); } else { Array projects = (Array)_connect.ApplicationObject.ActiveSolutionProjects; foreach (Project p in projects) { SolutionItem solutionItem = new SolutionItem(p); Execute(solutionItem); } } } } #endif }
public int Compare(object x, object y) { SolutionItem xItem = (SolutionItem)((TreeNode)x).Tag; SolutionItem yItem = (SolutionItem)((TreeNode)y).Tag; if (xItem != null && yItem != null) { if (xItem.ItemType == SolutionItemType.Folder) { if (yItem.ItemType == SolutionItemType.Folder) { return(string.Compare(xItem.Name, yItem.Name)); } else { return(-1); } } else if (yItem.ItemType == SolutionItemType.Folder) { return(1); } } else { if (yItem == null) { return(1); } if (yItem == null) { return(-1); } } return(string.Compare(xItem.Name, yItem.Name)); }
private void PrepareSolutionItem(SolutionItem solutionItem) { if (solutionItem.ProjectType == LanguageType.None) { string extension = Path.GetExtension(solutionItem.Filename); string text = extension; if (text != null) { if (!(text == ".vbproj")) { if (!(text == ".vcproj") && !(text == ".vcxproj")) { if (text == ".csproj") { solutionItem.ProjectType = LanguageType.CSharp; } } else { solutionItem.ProjectType = LanguageType.CPPManaged; } } else { solutionItem.ProjectType = LanguageType.VisualBasic; } } ProjectItem projectItem = solutionItem.FindProjectItem("AssemblyInfo.cpp"); if (projectItem == null) { if (extension == ".vcproj" || extension == ".vcxproj") { solutionItem.ProjectType = LanguageType.CPPUnmanaged; } } } }
private bool ActiveConfigurationMatch(SolutionItem solutionItem) { try { if (solutionItem.ItemType == SolutionItemType.Folder) { return(false); } string activeConfigName; if (solutionItem.ItemType == SolutionItemType.Solution) { activeConfigName = solutionItem.Solution.SolutionBuild.ActiveConfiguration.Name; } else { activeConfigName = solutionItem.Project.ConfigurationManager.ActiveConfiguration.ConfigurationName; } if (solutionItem.IncrementSettings.ConfigurationName == "Any" || solutionItem.IncrementSettings.ConfigurationName == activeConfigName) { return(true); } } catch (Exception ex) { if (!solutionItem.UniqueName.EndsWith("contentproj")) // XNA content project { Logger.Write("Couldn't get the active configuration name for \"" + solutionItem.UniqueName + "\": \"" + ex.Message + "\"\nSkipping ...", LogLevel.Info); } } return(false); }
public SolutionItemIncrementSettings(SolutionItem solutionItem) { this._solutionItem = solutionItem; }
private static void CopySettingsToAll(SolutionItem item, BaseIncrementSettings settings) { if (item.ItemType == SolutionItemType.Solution || item.ItemType == SolutionItemType.Project) { Logger.Write("Copying IncrementSettings to \"" + item.Name + "\"", LogLevel.Debug); item.IncrementSettings.CopyFrom(settings); } foreach (SolutionItem current in item.SubItems) { AddInSettingsForm.CopySettingsToAll(current, settings); } }
private void Update(SolutionItem solutionItem, string attribute) { if (solutionItem.IncrementSettings.BuildAction == BuildActionType.Both || (solutionItem.IncrementSettings.BuildAction == BuildActionType.Build && _currentBuildAction == vsBuildAction.vsBuildActionBuild) || (solutionItem.IncrementSettings.BuildAction == BuildActionType.ReBuild && _currentBuildAction == vsBuildAction.vsBuildActionRebuildAll)) { if ((solutionItem.IncrementSettings.IncrementBeforeBuild) != (_currentBuildState == vsBuildState.vsBuildStateInProgress)) { return; } Logger.Write($"Updating attribute {attribute} of project {solutionItem.Name}", LogLevel.Debug); var filename = GetAssemblyInfoFilename(solutionItem); if (filename == null || !File.Exists(filename)) { return; } switch (solutionItem.ProjectType) { case LanguageType.CSharp: case LanguageType.VisualBasic: case LanguageType.CppManaged: UpdateVersion(solutionItem, $"^[\\[<]assembly:\\s*{attribute}(Attribute)?\\s*\\(\\s*\"(?<FullVersion>\\S+\\.\\S+(\\.(?<Version>[^\"]+))?)\"\\s*\\)[\\]>]", filename, attribute); break; case LanguageType.CppUnmanaged: if (attribute == Constants.ATTRIBUTE_ASSEMBLY_VERSION) { attribute = Constants.ATTRIBUTE_PRODUCT_VERSION; } if (attribute == Constants.ATTRIBUTE_ASSEMBLY_FILE_VERSION) { attribute = Constants.ATTRIBUTE_FILE_VERSION; } UpdateVersion(solutionItem, $"^[\\s]*VALUE\\ \"{attribute}\",\\ \"(?<FullVersion>\\S+[.,\\s]+\\S+[.,\\s]+\\S+[.,\\s]+[^\\s\"]+)\"", filename, attribute); UpdateVersion(solutionItem, $"^[\\s]*{attribute.ToUpper()}\\ (?<FullVersion>\\S+[.,]+\\S+[.,]+\\S+[.,]+\\S+)", filename, attribute.ToUpper()); break; case LanguageType.None: break; default: throw new ArgumentOutOfRangeException(); } } }
private string GetAssemblyInfoFilename(SolutionItem solutionItem) { var filename = "AssemblyInfo"; var ext = Path.GetExtension(solutionItem.Filename); solutionItem.ProjectType = LanguageType.None; switch (ext) { case ".vbproj": filename += ".vb"; solutionItem.ProjectType = LanguageType.VisualBasic; break; case ".vcproj": case ".vcxproj": filename += ".cpp"; solutionItem.ProjectType = LanguageType.CppManaged; break; case ".csproj": filename += ".cs"; solutionItem.ProjectType = LanguageType.CSharp; break; case ".sln": if (string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { Logger.Write( "Can't update build version for a solution without specifying an assembly info file.", LogLevel.Error); return(null); } solutionItem.ProjectType = GetLanguageType(solutionItem.IncrementSettings.AssemblyInfoFilename); if (solutionItem.ProjectType == LanguageType.None) { Logger.Write( "Can't infer solution's assembly info file language. Please add extension to filename.", LogLevel.Error); } break; default: Logger.Write("Unknown project file type: \"" + ext + "\"", LogLevel.Error); return(null); } if (!string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { var basePath = Path.GetDirectoryName(solutionItem.Filename); return(Common.MakeAbsolutePath(basePath, solutionItem.IncrementSettings.AssemblyInfoFilename)); } var assemblyInfo = solutionItem.FindProjectItem(filename); if (assemblyInfo == null) { if (ext == ".vcproj" || ext == ".vcxproj") { filename = solutionItem.Name + ".rc"; assemblyInfo = solutionItem.FindProjectItem(filename); solutionItem.ProjectType = LanguageType.CppUnmanaged; } if (assemblyInfo == null) { Logger.Write($"Could not locate \"{filename}\" in project.", LogLevel.Warn); return(null); } } var ret = assemblyInfo.FileNames[0]; if (string.IsNullOrEmpty(ret)) { Logger.Write($"Located \"{filename}\" project item but failed to get filename.", LogLevel.Error); return(null); } Logger.Write($"Found \"{ret}\"", LogLevel.Debug); return(ret); }
private string GetAssemblyInfoFilename(SolutionItem solutionItem) { string text = "AssemblyInfo"; string extension = Path.GetExtension(solutionItem.Filename); solutionItem.ProjectType = LanguageType.None; string text2 = extension; string result; if (text2 != null) { if (!(text2 == ".vbproj")) { if (!(text2 == ".vcproj") && !(text2 == ".vcxproj")) { if (!(text2 == ".csproj")) { if (!(text2 == ".sln")) { goto IL_12F; } if (string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { Logger.Write("Can't update build version for a solution without specifying an assembly info file.", LogLevel.Error, solutionItem.Filename, 1); result = null; return(result); } solutionItem.ProjectType = this.GetLanguageType(solutionItem.IncrementSettings.AssemblyInfoFilename); if (solutionItem.ProjectType == LanguageType.None) { Logger.Write("Can't infer solution's assembly info file language. Please add extension to filename.", LogLevel.Error, solutionItem.Filename, 1); } } else { text += ".cs"; solutionItem.ProjectType = LanguageType.CSharp; } } else { text += ".cpp"; solutionItem.ProjectType = LanguageType.CPPManaged; } } else { text += ".vb"; solutionItem.ProjectType = LanguageType.VisualBasic; } if (!string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { string directoryName = Path.GetDirectoryName(solutionItem.Filename); result = Common.MakeAbsolutePath(directoryName, solutionItem.IncrementSettings.AssemblyInfoFilename); return(result); } ProjectItem projectItem = solutionItem.FindProjectItem(text); if (projectItem == null) { if (extension == ".vcproj" || extension == ".vcxproj") { text = solutionItem.Name + ".rc"; projectItem = solutionItem.FindProjectItem(text); solutionItem.ProjectType = LanguageType.CPPUnmanaged; } if (projectItem == null) { Logger.Write("Could not locate \"" + text + "\" in project.", LogLevel.Warning); result = null; return(result); } } string text3 = projectItem.get_FileNames(0); if (string.IsNullOrEmpty(text3)) { Logger.Write("Located \"" + text + "\" project item but failed to get filename.", LogLevel.Error); result = null; return(result); } Logger.Write("Found \"" + text3 + "\"", LogLevel.Debug); result = text3; return(result); } IL_12F: Logger.Write("Unknown project file type: \"" + extension + "\"", LogLevel.Error, solutionItem.Filename, 1); result = null; return(result); }
/// <summary> /// Increments the specified version. /// </summary> /// <param name="currentVersion">The current version.</param> /// <param name="buildStartDate">The build start date.</param> /// <param name="projectStartDate">The project start date.</param> /// <returns>The incremented version.</returns> internal StringVersion Increment(StringVersion currentVersion, DateTime buildStartDate, DateTime projectStartDate, SolutionItem solutionItem) { IncrementContext context = new IncrementContext(currentVersion, buildStartDate, projectStartDate, solutionItem.Filename); BaseIncrementor[] incrementors = new BaseIncrementor[] { Major, Minor, Build, Revision }; for (int i = 0; i < 4; i++) { BaseIncrementor incrementor = incrementors[i]; if (incrementor == null) { continue; } VersionComponent component = (VersionComponent)i; incrementor.Increment(context, component); if (!context.Continue) { break; } } return(context.NewVersion); /*int major = Major == null ? currentVersion.Major : Major.Increment(currentVersion.Major, buildStartDate, projectStartDate, solutionItem.Filename); * int minor = Minor == null ? currentVersion.Minor : Minor.Increment(currentVersion.Minor, buildStartDate, projectStartDate, solutionItem.Filename); * int build = Build == null ? currentVersion.Build : Build.Increment(currentVersion.Build, buildStartDate, projectStartDate, solutionItem.Filename); * int revision = Revision == null ? currentVersion.Revision : Revision.Increment(currentVersion.Revision, buildStartDate, projectStartDate, solutionItem.Filename); * * return new Version(major, minor, build, revision);*/ }
private static void FillSolutionTree(Connect connect, SolutionItem solutionItem, ProjectItems projectItems) { if (projectItems != null) { foreach (ProjectItem projectItem in projectItems) { SolutionItem solutionItem2 = SolutionItem.ConstructSolutionItem(connect, projectItem.SubProject); if (solutionItem2 != null) { solutionItem.SubItems.Add(solutionItem2); } } } }
private void BuildTree() { try { this._solution = new SolutionItem(this.Connect, this.Connect.ApplicationObject.Solution); TreeNode treeNode = this.solutionTreeView.Nodes.Add(this._solution.Name); treeNode.SelectedImageIndex = (treeNode.ImageIndex = this._iconListManager.AddFileIcon(this._solution.Filename)); treeNode.Tag = this._solution; this.BuildTree(treeNode, this._solution); treeNode.Expand(); this.solutionTreeView.SelectedNode = treeNode; this.solutionTreeView.TreeViewNodeSorter = new AddInSettingsForm.TreeNodeSort(); this.solutionTreeView.Sort(); this.solutionTreeView.AfterCollapse += new TreeViewEventHandler(this.solutionTreeView_AfterCollapse); this.solutionTreeView.AfterExpand += new TreeViewEventHandler(this.solutionTreeView_AfterExpand); } catch (Exception ex) { MessageBox.Show("Error occored while building solution tree.\n" + ex.ToString(), "Error"); } }
internal StringVersion Increment(StringVersion currentVersion, DateTime buildStartDate, DateTime projectStartDate, SolutionItem solutionItem) { IncrementContext incrementContext = new IncrementContext(currentVersion, buildStartDate, projectStartDate, solutionItem.Filename); BaseIncrementor[] array = new BaseIncrementor[] { this.Major, this.Minor, this.Build, this.Revision }; for (int i = 0; i < 4; i++) { BaseIncrementor baseIncrementor = array[i]; if (baseIncrementor != null) { VersionComponent versionComponent = (VersionComponent)i; baseIncrementor.Increment(incrementContext, versionComponent); if (!incrementContext.Continue) { break; } } } return(incrementContext.NewVersion); }
private string GetAssemblyInfoFilename(SolutionItem solutionItem) { if (!string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { string basePath = Path.GetDirectoryName(solutionItem.Filename); return(Common.MakeAbsolutePath(basePath, solutionItem.IncrementSettings.AssemblyInfoFilename)); } string ext = Path.GetExtension(solutionItem.Filename); string filename = "AssemblyInfo"; solutionItem.ProjectType = LanguageType.None; switch (ext) { case ".vbproj": filename += ".vb"; solutionItem.ProjectType = LanguageType.VisualBasic; break; case ".vcproj": filename += ".cpp"; solutionItem.ProjectType = LanguageType.CPPManaged; break; case ".csproj": filename += ".cs"; solutionItem.ProjectType = LanguageType.CSharp; break; case ".sln": Logger.Write("Can't update build version for a solution without specifying an assembly info file.", LogLevel.Error, solutionItem.Filename, 1); return(null); default: Logger.Write("Unknown project file type: \"" + ext + "\"", LogLevel.Error, solutionItem.Filename, 1); return(null); } string ret = null; ProjectItem assemblyInfo = solutionItem.FindProjectItem(filename); if (assemblyInfo == null) { // we couldn't locate the file, but, if it is a C-Project, is also could be an unmanaged project if (ext == ".vcproj") { filename = solutionItem.Name + ".rc"; assemblyInfo = solutionItem.FindProjectItem(filename); solutionItem.ProjectType = LanguageType.CPPUnmanaged; } if (assemblyInfo == null) { Logger.Write("Could not locate \"" + filename + "\" in project.", LogLevel.Warning); return(null); } } ret = assemblyInfo.get_FileNames(0); if (string.IsNullOrEmpty(ret)) { Logger.Write("Located \"" + filename + "\" project item but failed to get filename.", LogLevel.Error); return(null); } Logger.Write("Found \"" + ret + "\"", LogLevel.Debug); return(ret); }
/// <summary> /// Creates the build version. /// </summary> /// <param name="solutionItem">The solution item.</param> /// <param name="currentVersion">The current version as found in the assembly info.</param> /// <returns>The new build version</returns> private Version CreateBuildVersion(SolutionItem solutionItem, Version currentVersion) { //OLD_BuildVersioningStyleType buildVersioningStyleType = solutionItem.BuildVersioningStyle; DateTime startDate = solutionItem.StartDate; string dayOfyear = _buildStartDate.DayOfYear.ToString("000"); string yearDecade = _buildStartDate.ToString("yy"); int build = currentVersion.Build >= 0 ? currentVersion.Build : 0; int revision = currentVersion.Revision; switch (buildVersioningStyleType) { case OLD_BuildVersioningStyleType.DeltaBaseDate: // this is the original style TimeSpan ts = _buildStartDate.Subtract(startDate); DateTime dt = DateTime.MinValue + ts; build = Int32.Parse(string.Format("{0}{1:00}", dt.Year * 12 + dt.Month, dt.Day)); // Timestamp revision = Int32.Parse(string.Format("{0:00}{1:00}", dt.Hour, dt.Minute)); break; case OLD_BuildVersioningStyleType.YearDayOfYear_Timestamp: // m.n.9021.2106 <= 1/21/2009 21:16 build = Int32.Parse(string.Format("{0}{1:000}", yearDecade, dayOfyear)); revision = Int32.Parse(string.Format("{0:HHmm}", _buildStartDate)); break; case OLD_BuildVersioningStyleType.YearDayOfYear_AutoIncrement: build = int.Parse(string.Format("{0}{1:000}", yearDecade, dayOfyear)); if (build == currentVersion.Build) { revision = currentVersion.Revision + 1; } else { revision = 0; } break; case OLD_BuildVersioningStyleType.DeltaBaseYear: int baseYear = startDate.Year; int deltaYears = _buildStartDate.Year - baseYear; build = Int32.Parse(string.Format("{0}{1:000}", deltaYears, dayOfyear)); revision = Int32.Parse(string.Format("{0:HHmm}", _buildStartDate)); break; case OLD_BuildVersioningStyleType.AutoIncrementBuildVersion: build += 1; break; default: throw new ArgumentOutOfRangeException("buildVersioningStyleType", buildVersioningStyleType, "The build Versioning Style was not recognized."); } if (revision >= 0) { return(new Version(currentVersion.Major, currentVersion.Minor, build, revision)); } else { return(new Version(currentVersion.Major, currentVersion.Minor, build)); } }
private void UpdateVersion(SolutionItem solutionItem, string regexPattern, string assemblyFile, string debugAttribute) { string filecontent = File.ReadAllText(assemblyFile); try { RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase; Match m = Regex.Match(filecontent, regexPattern, options); if (!m.Success) { Logger.Write("Failed to locate attribute \"" + debugAttribute + "\" in file \"" + assemblyFile + "\".", LogLevel.Error, assemblyFile, 1); return; } Match sep = Regex.Match(m.Groups["FullVersion"].Value, "(?<Separator>[\\s,.]+)", options); if (!sep.Success) { Logger.Write("Failed to fetch version separator on attribute \"" + debugAttribute + "\" in file \"" + assemblyFile + "\".", LogLevel.Error, assemblyFile, 2); return; } Version currentVersion = null; try { // Make sure we don't have anything what is not a number in the version //currentVersion = new Version(m.Groups["FullVersion"].Value.Replace("*", "0")); currentVersion = new Version(Regex.Replace(m.Groups["FullVersion"].Value, "[^\\d" + sep.Groups["Separator"].Value + "]+", "0").Replace(sep.Groups["Separator"].Value, ".")); } catch (Exception ex) { string msg = string.Format("Error occured while parsing value of {0} ({1}).\n{2}", debugAttribute, m.Groups["FullVersion"].Value, ex); throw (new Exception(msg, ex)); } StandardVersionIncrementer versionIncrementer = new StandardVersionIncrementer(); versionIncrementer.BuildStartDate = solutionItem.IncrementSettings.IsUniversalTime ? _buildStartDate.ToUniversalTime() : _buildStartDate; versionIncrementer.ProjectStartDate = solutionItem.IncrementSettings.StartDate; Version newVersion = versionIncrementer.CreateBuildVersion(solutionItem.IncrementSettings.VersioningStyle, currentVersion); // CreateBuildVersion(solutionItem, currentVersion); if (newVersion != currentVersion) { bool success = false; if (_connect.IsCommandLineBuild) { filecontent = filecontent.Remove(m.Groups["FullVersion"].Index, m.Groups["FullVersion"].Length); filecontent = filecontent.Insert(m.Groups["FullVersion"].Index, newVersion.ToString()); try { File.WriteAllText(assemblyFile, filecontent); success = true; } catch (Exception ex) { Logger.Write(ex.Message, LogLevel.Warning); success = false; } } else { bool doCloseWindow = !solutionItem.DTE.ItemOperations.IsFileOpen(assemblyFile, null); string replaceWith = string.Empty; if (!solutionItem.IncrementSettings.ReplaceNonNumerics && Regex.IsMatch(m.Groups["FullVersion"].Value, "[^\\d" + sep.Groups["Separator"].Value + "]+")) { //the version number is not only pure numbers...Thread 77828 from philjones88 string[] mergedVersion = m.Groups["FullVersion"].Value.Replace(sep.Groups["Separator"].Value, ".").Split('.'); if (Regex.IsMatch(mergedVersion[0], "[\\d]+")) { mergedVersion[0] = newVersion.Major.ToString(); } if (Regex.IsMatch(mergedVersion[1], "[\\d]+")) { mergedVersion[1] = newVersion.Minor.ToString(); } if (Regex.IsMatch(mergedVersion[2], "[\\d]+")) { mergedVersion[2] = newVersion.Build.ToString(); } if (Regex.IsMatch(mergedVersion[3], "[\\d]+")) { mergedVersion[3] = newVersion.Revision.ToString(); } replaceWith = m.Value.Replace(m.Groups["FullVersion"].Value, String.Format("{0}.{1}.{2}.{3}", mergedVersion).Replace(".", sep.Groups["Separator"].Value)); } else { replaceWith = m.Value.Replace(m.Groups["FullVersion"].Value, newVersion.ToString(4).Replace(".", sep.Groups["Separator"].Value)); } ProjectItem projectItem = _connect.ApplicationObject.Solution.FindProjectItem(assemblyFile); if (projectItem == null) { throw (new ApplicationException("Failed to find project item \"" + assemblyFile + "\".")); } Window window = projectItem.Open(Constants.vsViewKindTextView); if (window == null) { throw (new ApplicationException("Could not open project item.")); } Document doc = window.Document; if (doc == null) { throw (new ApplicationException("Located project item & window but no document.")); } success = doc.ReplaceText(m.Value, replaceWith, 0); if (doCloseWindow) { window.Close(vsSaveChanges.vsSaveChangesYes); } else { doc.Save(assemblyFile); } } #if OLDSTUFF filecontent = filecontent.Remove(m.Groups["FullVersion"].Index, m.Groups["FullVersion"].Length); filecontent = filecontent.Insert(m.Groups["FullVersion"].Index, newVersion.ToString()); success = WriteFileContent(filename, filecontent); #endif if (success) { string msg = solutionItem.Name + " " + debugAttribute + ": " + newVersion.ToString(); Logger.Write(msg, LogLevel.Info); } } } catch (Exception ex) { Logger.Write("Error occured while updating version.\n" + ex.ToString(), LogLevel.Error, assemblyFile, 1); } }
private void UpdateVersion(SolutionItem solutionItem, string regexPattern, string assemblyFile, string debugAttribute) { string text = File.ReadAllText(assemblyFile); try { RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace; Match match = Regex.Match(text, regexPattern, options); if (!match.Success) { Logger.Write(string.Concat(new string[] { "Failed to locate attribute \"", debugAttribute, "\" in file \"", assemblyFile, "\"." }), LogLevel.Error, assemblyFile, 1); } else { Match match2 = Regex.Match(match.Groups["FullVersion"].Value, "(?<Separator>[\\s,.]+)", options); if (!match2.Success) { Logger.Write(string.Concat(new string[] { "Failed to fetch version separator on attribute \"", debugAttribute, "\" in file \"", assemblyFile, "\"." }), LogLevel.Error, assemblyFile, 2); } else { StringVersion stringVersion = null; try { stringVersion = new StringVersion(Regex.Replace(match.Groups["FullVersion"].Value, "[^\\d" + match2.Groups["Separator"].Value + "]+", "0").Replace(match2.Groups["Separator"].Value, ".")); } catch (Exception ex) { string text2 = string.Format("Error occured while parsing value of {0} ({1}).\n{2}", debugAttribute, match.Groups["FullVersion"].Value, ex); throw new Exception(text2, ex); } StringVersion stringVersion2 = solutionItem.IncrementSettings.VersioningStyle.Increment(stringVersion, solutionItem.IncrementSettings.IsUniversalTime ? this._buildStartDate.ToUniversalTime() : this._buildStartDate, solutionItem.IncrementSettings.StartDate, solutionItem); if (stringVersion2 != stringVersion) { bool flag = false; if (this._connect.IsCommandLineBuild) { text = text.Remove(match.Groups["FullVersion"].Index, match.Groups["FullVersion"].Length); text = text.Insert(match.Groups["FullVersion"].Index, stringVersion2.ToString()); try { File.WriteAllText(assemblyFile, text); flag = true; } catch (Exception ex) { Logger.Write(ex.Message, LogLevel.Warning); flag = false; } } else { bool flag2 = !solutionItem.DTE.ItemOperations.IsFileOpen(assemblyFile, null); string replaceText = string.Empty; if (!solutionItem.IncrementSettings.ReplaceNonNumerics && Regex.IsMatch(match.Groups["FullVersion"].Value, "[^\\d" + match2.Groups["Separator"].Value + "]+")) { string[] array = match.Groups["FullVersion"].Value.Replace(match2.Groups["Separator"].Value, ".").Split(new char[] { '.' }); if (Regex.IsMatch(array[0], "[\\d]+")) { array[0] = stringVersion2.Major; } if (Regex.IsMatch(array[1], "[\\d]+")) { array[1] = stringVersion2.Minor; } if (Regex.IsMatch(array[2], "[\\d]+")) { array[2] = stringVersion2.Build; } if (Regex.IsMatch(array[3], "[\\d]+")) { array[3] = stringVersion2.Revision; } replaceText = match.Value.Replace(match.Groups["FullVersion"].Value, string.Format("{0}.{1}.{2}.{3}", array).Replace(".", match2.Groups["Separator"].Value)); } else { replaceText = match.Value.Replace(match.Groups["FullVersion"].Value, stringVersion2.ToString(4).Replace(".", match2.Groups["Separator"].Value)); } ProjectItem projectItem = this._connect.ApplicationObject.Solution.FindProjectItem(assemblyFile); if (projectItem == null) { throw new ApplicationException("Failed to find project item \"" + assemblyFile + "\"."); } Window window = projectItem.Open("{7651A703-06E5-11D1-8EBD-00A0C90F26EA}"); if (window == null) { throw new ApplicationException("Could not open project item."); } Document document = window.Document; if (document == null) { throw new ApplicationException("Located project item & window but no document."); } flag = document.ReplaceText(match.Value, replaceText, 0); if (flag2) { window.Close(vsSaveChanges.vsSaveChangesYes); } else { document.Save(assemblyFile); } } string text2 = string.Concat(new object[] { solutionItem.Name, " ", debugAttribute, ": ", stringVersion2 }); if (flag) { text2 += " [SUCCESS]"; } else { text2 += " [FAILED]"; } Logger.Write(text2, LogLevel.Info); } } } } catch (Exception ex) { Logger.Write("Error occured while updating version.\n" + ex.ToString(), LogLevel.Error, assemblyFile, 1); } }
private async System.Threading.Tasks.Task UpdateProjectAsync(SolutionItem solutionItem) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); if (GlobalIncrementSettings.ApplySettings == GlobalIncrementSettings.ApplyGlobalSettings.Always || solutionItem.IncrementSettings.UseGlobalSettings) { solutionItem.ApplyGlobalSettings(); } if (_updatedItems.ContainsKey(solutionItem.UniqueName)) { return; } if (ActiveConfigurationMatch(solutionItem)) { if (solutionItem.IncrementSettings.AutoUpdateAssemblyVersion) { await UpdateAsync(solutionItem, Constants.ATTRIBUTE_ASSEMBLY_VERSION); } if (solutionItem.IncrementSettings.AutoUpdateFileVersion) { await UpdateAsync(solutionItem, Constants.ATTRIBUTE_ASSEMBLY_FILE_VERSION); } } try { if (solutionItem.BuildDependency != null) { var references = (object[])solutionItem.BuildDependency.RequiredProjects; foreach (var dep in references.Select(o => { ThreadHelper.ThrowIfNotOnUIThread(); return(SolutionItem.ConstructSolutionItem(_package, (Project)o, false)); }) .Where(dep => dep != null)) { try { await UpdateProjectAsync(dep); } catch (Exception ex) { Logger.Write( $"Exception occured while updating project dependency \"{dep.UniqueName}\" for \"{solutionItem.UniqueName}\".\n{ex.Message}", LogLevel.Error); } } } } catch (Exception ex) { Logger.Write($"Failed updating dependencies for \"{solutionItem.UniqueName}\".\n{ex.Message}", LogLevel.Error); } _updatedItems.Add(solutionItem.UniqueName, solutionItem); }
public static SolutionItem ConstructSolutionItem(Connect connect, Project project, bool recursive) { SolutionItem result = null; if (SolutionItem.IsValidSolutionItem(project)) { result = new SolutionItem(connect, project, recursive); } return result; }
private void UpdateVersion(SolutionItem solutionItem, string regexPattern, string assemblyFile, string debugAttribute) { string text = File.ReadAllText(assemblyFile); try { RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace; Match match = Regex.Match(text, regexPattern, options); if (!match.Success) { Logger.Write(string.Concat(new string[] { "Failed to locate attribute \"", debugAttribute, "\" in file \"", assemblyFile, "\"." }), LogLevel.Error, assemblyFile, 1); } else { Match match2 = Regex.Match(match.Groups["FullVersion"].Value, "(?<Separator>[\\s,.]+)", options); if (!match2.Success) { Logger.Write(string.Concat(new string[] { "Failed to fetch version separator on attribute \"", debugAttribute, "\" in file \"", assemblyFile, "\"." }), LogLevel.Error, assemblyFile, 2); } else { StringVersion stringVersion = null; try { stringVersion = new StringVersion(Regex.Replace(match.Groups["FullVersion"].Value, "[^\\d" + match2.Groups["Separator"].Value + "]+", "0").Replace(match2.Groups["Separator"].Value, ".")); } catch (Exception ex) { string text2 = string.Format("Error occured while parsing value of {0} ({1}).\n{2}", debugAttribute, match.Groups["FullVersion"].Value, ex); throw new Exception(text2, ex); } StringVersion stringVersion2 = solutionItem.IncrementSettings.VersioningStyle.Increment(stringVersion, solutionItem.IncrementSettings.IsUniversalTime ? this._buildStartDate.ToUniversalTime() : this._buildStartDate, solutionItem.IncrementSettings.StartDate, solutionItem); if (stringVersion2 != stringVersion) { bool flag = false; if (this._connect.IsCommandLineBuild) { text = text.Remove(match.Groups["FullVersion"].Index, match.Groups["FullVersion"].Length); text = text.Insert(match.Groups["FullVersion"].Index, stringVersion2.ToString()); try { File.WriteAllText(assemblyFile, text); flag = true; } catch (Exception ex) { Logger.Write(ex.Message, LogLevel.Warning); flag = false; } } else { bool flag2 = !solutionItem.DTE.ItemOperations.IsFileOpen(assemblyFile, null); string replaceText = string.Empty; if (!solutionItem.IncrementSettings.ReplaceNonNumerics && Regex.IsMatch(match.Groups["FullVersion"].Value, "[^\\d" + match2.Groups["Separator"].Value + "]+")) { string[] array = match.Groups["FullVersion"].Value.Replace(match2.Groups["Separator"].Value, ".").Split(new char[] { '.' }); if (Regex.IsMatch(array[0], "[\\d]+")) { array[0] = stringVersion2.Major; } if (Regex.IsMatch(array[1], "[\\d]+")) { array[1] = stringVersion2.Minor; } if (Regex.IsMatch(array[2], "[\\d]+")) { array[2] = stringVersion2.Build; } if (Regex.IsMatch(array[3], "[\\d]+")) { array[3] = stringVersion2.Revision; } replaceText = match.Value.Replace(match.Groups["FullVersion"].Value, string.Format("{0}.{1}.{2}.{3}", array).Replace(".", match2.Groups["Separator"].Value)); } else { replaceText = match.Value.Replace(match.Groups["FullVersion"].Value, stringVersion2.ToString(4).Replace(".", match2.Groups["Separator"].Value)); } ProjectItem projectItem = this._connect.ApplicationObject.Solution.FindProjectItem(assemblyFile); if (projectItem == null) { throw new ApplicationException("Failed to find project item \"" + assemblyFile + "\"."); } Window window = projectItem.Open("{7651A703-06E5-11D1-8EBD-00A0C90F26EA}"); if (window == null) { throw new ApplicationException("Could not open project item."); } Document document = window.Document; if (document == null) { throw new ApplicationException("Located project item & window but no document."); } flag = document.ReplaceText(match.Value, replaceText, 0); if (flag2) { window.Close(vsSaveChanges.vsSaveChangesYes); } else { document.Save(assemblyFile); } } string text2 = string.Concat(new object[] { solutionItem.Name, " ", debugAttribute, ": ", stringVersion2 }); if (flag) { text2 += " [SUCCESS]"; } else { text2 += " [FAILED]"; } Logger.Write(text2, LogLevel.Info); } } } } catch (Exception ex) { Logger.Write("Error occured while updating version.\n" + ex.ToString(), LogLevel.Error, assemblyFile, 1); } }
private bool ActiveConfigurationMatch(SolutionItem solutionItem) { bool result; try { if (solutionItem.ItemType == SolutionItemType.Folder) { result = false; return result; } string b; if (solutionItem.ItemType == SolutionItemType.Solution) { b = solutionItem.Solution.SolutionBuild.ActiveConfiguration.Name; } else { b = solutionItem.Project.ConfigurationManager.ActiveConfiguration.ConfigurationName; } if (solutionItem.IncrementSettings.ConfigurationName == "Any" || solutionItem.IncrementSettings.ConfigurationName == b) { result = true; return result; } } catch (Exception ex) { if (!solutionItem.UniqueName.EndsWith("contentproj")) { Logger.Write(string.Concat(new string[] { "Couldn't get the active configuration name for \"", solutionItem.UniqueName, "\": \"", ex.Message, "\"\nSkipping ..." }), LogLevel.Info); } } result = false; return result; }
private void BuildTree(TreeNode currentNode, SolutionItem currentItem) { foreach (SolutionItem current in currentItem.SubItems) { TreeNode treeNode = currentNode.Nodes.Add(current.Name); if (current.ItemType == SolutionItemType.Folder) { treeNode.ImageIndex = this._iconListManager.AddFolderIcon(FolderType.Closed); treeNode.SelectedImageIndex = this._iconListManager.AddFolderIcon(FolderType.Open); } else { treeNode.SelectedImageIndex = (treeNode.ImageIndex = this._iconListManager.AddFileIcon(current.Filename)); } treeNode.Tag = current; this.BuildTree(treeNode, current); } if (currentItem.ItemType == SolutionItemType.Folder && currentNode.Nodes.Count == 0) { this.solutionTreeView.Nodes.Remove(currentNode); } }
public static SolutionItem ConstructSolutionItem(Connect connect, Project project) { return(SolutionItem.ConstructSolutionItem(connect, project, true)); }
private void ExecuteIncrement() { if (!GlobalAddinSettings.Default.IsEnabled) { Logger.Write("BuildVersionIncrement disabled.", LogLevel.Info); } else { try { if (this._currentBuildAction == vsBuildAction.vsBuildActionBuild || this._currentBuildAction == vsBuildAction.vsBuildActionRebuildAll) { if (this._currentBuildScope == vsBuildScope.vsBuildScopeSolution) { Solution solution = this._connect.ApplicationObject.Solution; SolutionItem solutionItem = new SolutionItem(this._connect, solution, true); this.UpdateRecursive(solutionItem); } else { Array array = (Array)this._connect.ApplicationObject.ActiveSolutionProjects; foreach (Project project in array) { SolutionItem solutionItem = SolutionItem.ConstructSolutionItem(this._connect, project, false); if (solutionItem != null && this.IsSolutionItemModified(solutionItem)) { this.UpdateProject(solutionItem); } } } Logger.Write(string.Format("{0}-build process : Completed", (this._currentBuildState == vsBuildState.vsBuildStateInProgress) ? "Pre" : "Post"), LogLevel.Info); } } catch (Exception ex) { Logger.Write("Error occured while executing build version increment.\n" + ex.ToString(), LogLevel.Error); } } }
private bool IsSolutionItemModified(SolutionItem solutionItem) { string key = string.Format("{0}:{1}", solutionItem.ItemType, solutionItem.Name); bool result; if (BuildVersionIncrementor._solutionItemCache.ContainsKey(key)) { bool flag = BuildVersionIncrementor._solutionItemCache[key]; result = flag; } else { if (!solutionItem.IncrementSettings.DetectChanges) { Logger.Write(string.Format("Detect changes disabled. Mark item '{0}' as modified.", solutionItem.Name), LogLevel.Debug); BuildVersionIncrementor._solutionItemCache.Add(key, true); result = true; } else { this.PrepareSolutionItem(solutionItem); switch (solutionItem.ItemType) { case SolutionItemType.Folder: case SolutionItemType.Solution: { bool flag = false; foreach (SolutionItem current in solutionItem.SubItems) { if (current.ItemType == SolutionItemType.Project) { flag = this.IsProjectModified(current.Project, current.ProjectType); BuildVersionIncrementor._solutionItemCache.Add(string.Format("{0}:{1}", current.ItemType, current.Name), flag); } else { if (current.ItemType == SolutionItemType.Folder) { flag = this.IsSolutionItemModified(current); } } if (flag) { break; } } Logger.Write(string.Format("Solution/Folder '{0}' is not modified", solutionItem.Name), LogLevel.Debug); BuildVersionIncrementor._solutionItemCache.Add(key, flag); result = flag; break; } case SolutionItemType.Project: { bool flag = this.IsProjectModified(solutionItem.Project, solutionItem.ProjectType); BuildVersionIncrementor._solutionItemCache.Add(string.Format("{0}:{1}", solutionItem.ItemType, solutionItem.Name), flag); result = flag; break; } default: Logger.Write(string.Format("Solution item '{0}' is not supported. Run standard behavior (is modified).", solutionItem.ItemType), LogLevel.Warning); BuildVersionIncrementor._solutionItemCache.Add(key, true); result = true; break; } } } return(result); }
private string GetAssemblyInfoFilename(SolutionItem solutionItem) { string text = "AssemblyInfo"; string extension = Path.GetExtension(solutionItem.Filename); solutionItem.ProjectType = LanguageType.None; string text2 = extension; string result; if (text2 != null) { if (!(text2 == ".vbproj")) { if (!(text2 == ".vcproj") && !(text2 == ".vcxproj")) { if (!(text2 == ".csproj")) { if (!(text2 == ".sln")) { goto IL_12F; } if (string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { Logger.Write("Can't update build version for a solution without specifying an assembly info file.", LogLevel.Error, solutionItem.Filename, 1); result = null; return result; } solutionItem.ProjectType = this.GetLanguageType(solutionItem.IncrementSettings.AssemblyInfoFilename); if (solutionItem.ProjectType == LanguageType.None) { Logger.Write("Can't infer solution's assembly info file language. Please add extension to filename.", LogLevel.Error, solutionItem.Filename, 1); } } else { text += ".cs"; solutionItem.ProjectType = LanguageType.CSharp; } } else { text += ".cpp"; solutionItem.ProjectType = LanguageType.CPPManaged; } } else { text += ".vb"; solutionItem.ProjectType = LanguageType.VisualBasic; } if (!string.IsNullOrEmpty(solutionItem.IncrementSettings.AssemblyInfoFilename)) { string directoryName = Path.GetDirectoryName(solutionItem.Filename); result = Common.MakeAbsolutePath(directoryName, solutionItem.IncrementSettings.AssemblyInfoFilename); return result; } ProjectItem projectItem = solutionItem.FindProjectItem(text); if (projectItem == null) { if (extension == ".vcproj" || extension == ".vcxproj") { text = solutionItem.Name + ".rc"; projectItem = solutionItem.FindProjectItem(text); solutionItem.ProjectType = LanguageType.CPPUnmanaged; } if (projectItem == null) { Logger.Write("Could not locate \"" + text + "\" in project.", LogLevel.Warning); result = null; return result; } } string text3 = projectItem.get_FileNames(0); if (string.IsNullOrEmpty(text3)) { Logger.Write("Located \"" + text + "\" project item but failed to get filename.", LogLevel.Error); result = null; return result; } Logger.Write("Found \"" + text3 + "\"", LogLevel.Debug); result = text3; return result; } IL_12F: Logger.Write("Unknown project file type: \"" + extension + "\"", LogLevel.Error, solutionItem.Filename, 1); result = null; return result; }
private bool IsSolutionItemModified(SolutionItem solutionItem) { string key = string.Format("{0}:{1}", solutionItem.ItemType, solutionItem.Name); bool result; if (BuildVersionIncrementor._solutionItemCache.ContainsKey(key)) { bool flag = BuildVersionIncrementor._solutionItemCache[key]; result = flag; } else { if (!solutionItem.IncrementSettings.DetectChanges) { Logger.Write(string.Format("Detect changes disabled. Mark item '{0}' as modified.", solutionItem.Name), LogLevel.Debug); BuildVersionIncrementor._solutionItemCache.Add(key, true); result = true; } else { this.PrepareSolutionItem(solutionItem); switch (solutionItem.ItemType) { case SolutionItemType.Folder: case SolutionItemType.Solution: { bool flag = false; foreach (SolutionItem current in solutionItem.SubItems) { if (current.ItemType == SolutionItemType.Project) { flag = this.IsProjectModified(current.Project, current.ProjectType); BuildVersionIncrementor._solutionItemCache.Add(string.Format("{0}:{1}", current.ItemType, current.Name), flag); } else { if (current.ItemType == SolutionItemType.Folder) { flag = this.IsSolutionItemModified(current); } } if (flag) { break; } } Logger.Write(string.Format("Solution/Folder '{0}' is not modified", solutionItem.Name), LogLevel.Debug); BuildVersionIncrementor._solutionItemCache.Add(key, flag); result = flag; break; } case SolutionItemType.Project: { bool flag = this.IsProjectModified(solutionItem.Project, solutionItem.ProjectType); BuildVersionIncrementor._solutionItemCache.Add(string.Format("{0}:{1}", solutionItem.ItemType, solutionItem.Name), flag); result = flag; break; } default: Logger.Write(string.Format("Solution item '{0}' is not supported. Run standard behavior (is modified).", solutionItem.ItemType), LogLevel.Warning); BuildVersionIncrementor._solutionItemCache.Add(key, true); result = true; break; } } } return result; }
private void PrepareSolutionItem(SolutionItem solutionItem) { if (solutionItem.ProjectType == LanguageType.None) { string extension = Path.GetExtension(solutionItem.Filename); string text = extension; if (text != null) { if (!(text == ".vbproj")) { if (!(text == ".vcproj") && !(text == ".vcxproj")) { if (text == ".csproj") { solutionItem.ProjectType = LanguageType.CSharp; } } else { solutionItem.ProjectType = LanguageType.CPPManaged; } } else { solutionItem.ProjectType = LanguageType.VisualBasic; } } ProjectItem projectItem = solutionItem.FindProjectItem("AssemblyInfo.cpp"); if (projectItem == null) { if (extension == ".vcproj" || extension == ".vcxproj") { solutionItem.ProjectType = LanguageType.CPPUnmanaged; } } } }
/// <summary> /// Initializes a new instance of the <see cref="SolutionItemIncrementSettings"/> class. /// </summary> /// <param name="solutionItem">The solution item.</param> public SolutionItemIncrementSettings(SolutionItem solutionItem) { _solutionItem = solutionItem; }
private void Update(SolutionItem solutionItem, string attribute) { if (solutionItem.IncrementSettings.BuildAction == BuildActionType.Both || (solutionItem.IncrementSettings.BuildAction == BuildActionType.Build && this._currentBuildAction == vsBuildAction.vsBuildActionBuild) || (solutionItem.IncrementSettings.BuildAction == BuildActionType.ReBuild && this._currentBuildAction == vsBuildAction.vsBuildActionRebuildAll)) { if (solutionItem.IncrementSettings.IncrementBeforeBuild == (this._currentBuildState == vsBuildState.vsBuildStateInProgress)) { Logger.Write("Updating attribute " + attribute + " of project " + solutionItem.Name, LogLevel.Debug); string assemblyInfoFilename = this.GetAssemblyInfoFilename(solutionItem); if (assemblyInfoFilename != null && File.Exists(assemblyInfoFilename)) { switch (solutionItem.ProjectType) { case LanguageType.CSharp: case LanguageType.VisualBasic: case LanguageType.CPPManaged: this.UpdateVersion(solutionItem, "^[\\[<]assembly:\\s*" + attribute + "(Attribute)?\\s*\\(\\s*\"(?<FullVersion>\\S+\\.\\S+(\\.(?<Version>[^\"]+))?)\"\\s*\\)[\\]>]", assemblyInfoFilename, attribute); break; case LanguageType.CPPUnmanaged: if (attribute == "AssemblyVersion") { attribute = "ProductVersion"; } if (attribute == "AssemblyFileVersion") { attribute = "FileVersion"; } this.UpdateVersion(solutionItem, "^[\\s]*VALUE\\ \"" + attribute + "\",\\ \"(?<FullVersion>\\S+[.,\\s]+\\S+[.,\\s]+\\S+[.,\\s]+[^\\s\"]+)\"", assemblyInfoFilename, attribute); this.UpdateVersion(solutionItem, "^[\\s]*" + attribute.ToUpper() + "\\ (?<FullVersion>\\S+[.,]+\\S+[.,]+\\S+[.,]+\\S+)", assemblyInfoFilename, attribute.ToUpper()); break; } } } } }
private bool IsSolutionItemModified(SolutionItem solutionItem) { var key = $"{solutionItem.ItemType}:{solutionItem.Name}"; if (_solutionItemCache.ContainsKey(key)) { var result = _solutionItemCache[key]; return(result); } if (!solutionItem.IncrementSettings.DetectChanges) { Logger.Write($"Detect changes disabled. Mark item '{solutionItem.Name}' as modified.", LogLevel.Debug); _solutionItemCache.Add(key, true); return(true); } PrepareSolutionItem(solutionItem); switch (solutionItem.ItemType) { case SolutionItemType.Project: { var result = IsProjectModified(solutionItem.Project); _solutionItemCache.Add($"{solutionItem.ItemType}:{solutionItem.Name}", result); return(result); } case SolutionItemType.Folder: case SolutionItemType.Solution: { var result = false; foreach (var subItem in solutionItem.SubItems) { // ReSharper disable once SwitchStatementMissingSomeCases switch (subItem.ItemType) { case SolutionItemType.Project: result = IsProjectModified(subItem.Project); _solutionItemCache.Add($"{subItem.ItemType}:{subItem.Name}", result); break; case SolutionItemType.Folder: result = IsSolutionItemModified(subItem); break; } if (result) { break; } } Logger.Write($"Solution/Folder '{solutionItem.Name}' is not modified", LogLevel.Debug); _solutionItemCache.Add(key, result); return(result); } case SolutionItemType.None: break; default: throw new ArgumentOutOfRangeException(); } Logger.Write( $"Solution item '{solutionItem.ItemType}' is not supported. Run standard behavior (is modified).", LogLevel.Warn); _solutionItemCache.Add(key, true); return(true); }
private void UpdateProject(SolutionItem solutionItem) { if (GlobalIncrementSettings.ApplySettings == GlobalIncrementSettings.ApplyGlobalSettings.Always || solutionItem.IncrementSettings.UseGlobalSettings) { solutionItem.ApplyGlobalSettings(); } if (!this._updatedItems.ContainsKey(solutionItem.UniqueName)) { if (this.ActiveConfigurationMatch(solutionItem)) { if (solutionItem.IncrementSettings.AutoUpdateAssemblyVersion) { this.Update(solutionItem, "AssemblyVersion"); } if (solutionItem.IncrementSettings.AutoUpdateFileVersion) { this.Update(solutionItem, "AssemblyFileVersion"); } } try { if (solutionItem.BuildDependency != null) { object[] array = (object[])solutionItem.BuildDependency.RequiredProjects; object[] array2 = array; for (int i = 0; i < array2.Length; i++) { object obj = array2[i]; SolutionItem solutionItem2 = SolutionItem.ConstructSolutionItem(this._connect, (Project)obj, false); if (solutionItem2 != null) { try { this.UpdateProject(solutionItem2); } catch (Exception ex) { Logger.Write(string.Concat(new string[] { "Exception occured while updating project dependency \"", solutionItem2.UniqueName, "\" for \"", solutionItem.UniqueName, "\".\n", ex.Message }), LogLevel.Error); } } } } } catch (Exception ex) { Logger.Write("Failed updating dependencies for \"" + solutionItem.UniqueName + "\".\n" + ex.Message, LogLevel.Error); } this._updatedItems.Add(solutionItem.UniqueName, solutionItem); } }
private void UpdateVersion(SolutionItem solutionItem, string regexPattern, string assemblyFile, string debugAttribute) { var filecontent = File.ReadAllText(assemblyFile); try { const RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase; var m = Regex.Match(filecontent, regexPattern, options); if (!m.Success) { Logger.Write($"Failed to locate attribute \"{debugAttribute}\" in file \"{assemblyFile}\".", LogLevel.Error); return; } var sep = Regex.Match(m.Groups["FullVersion"].Value, "(?<Separator>[\\s,.]+)", options); if (!sep.Success) { Logger.Write( $"Failed to fetch version separator on attribute \"{debugAttribute}\" in file \"{assemblyFile}\".", LogLevel.Error); return; } StringVersion currentVersion; string msg; try { currentVersion = new StringVersion( Regex.Replace(m.Groups["FullVersion"].Value, $"[^\\d{sep.Groups["Separator"].Value}]+", "0") .Replace(sep.Groups["Separator"].Value, ".")); } catch (Exception ex) { msg = $"Error occured while parsing value of {debugAttribute} ({m.Groups["FullVersion"].Value}).\n{ex}"; throw (new Exception(msg, ex)); } var newVersion = solutionItem.IncrementSettings.VersioningStyle.Increment(currentVersion, solutionItem .IncrementSettings .IsUniversalTime ? _buildStartDate .ToUniversalTime() : _buildStartDate, solutionItem .IncrementSettings .StartDate, solutionItem); if (newVersion == currentVersion) { return; } bool success; if (_package.IsCommandLine) { filecontent = filecontent.Remove(m.Groups["FullVersion"].Index, m.Groups["FullVersion"].Length); filecontent = filecontent.Insert(m.Groups["FullVersion"].Index, newVersion.ToString()); try { File.WriteAllText(assemblyFile, filecontent); success = true; } catch (Exception ex) { Logger.Write(ex.Message, LogLevel.Warn); success = false; } } else { var doCloseWindow = !solutionItem.DTE.ItemOperations.IsFileOpen(assemblyFile, null); string replaceWith; if (!solutionItem.IncrementSettings.ReplaceNonNumerics && Regex.IsMatch(m.Groups["FullVersion"].Value, $"[^\\d{sep.Groups["Separator"].Value}]+")) { var mergedVersion = m.Groups["FullVersion"].Value.Replace(sep.Groups["Separator"].Value, ".").Split('.'); if (Regex.IsMatch(mergedVersion[0], "[\\d]+")) { mergedVersion[0] = newVersion.Major; } if (Regex.IsMatch(mergedVersion[1], "[\\d]+")) { mergedVersion[1] = newVersion.Minor; } if (Regex.IsMatch(mergedVersion[2], "[\\d]+")) { mergedVersion[2] = newVersion.Build; } if (Regex.IsMatch(mergedVersion[3], "[\\d]+")) { mergedVersion[3] = newVersion.Revision; } // ReSharper disable once CoVariantArrayConversion replaceWith = m.Value.Replace(m.Groups["FullVersion"].Value, string.Format("{0}.{1}.{2}.{3}", mergedVersion) .Replace(".", sep.Groups["Separator"].Value)); } else { replaceWith = m.Value.Replace(m.Groups["FullVersion"].Value, newVersion.ToString(4) .Replace(".", sep.Groups["Separator"].Value)); } var projectItem = DTE.Solution.FindProjectItem(assemblyFile); if (projectItem == null) { throw (new ApplicationException($"Failed to find project item \"{assemblyFile}\".")); } //var doc = projectItem.Document; var window = projectItem.Open(EnvDTE.Constants.vsViewKindTextView); if (window == null) { throw (new ApplicationException("Could not open project item.")); } var doc = window.Document; if (doc == null) { throw (new ApplicationException("Located project item but no document.")); } success = doc.ReplaceText(m.Value, replaceWith); if (doCloseWindow) { window.Close(vsSaveChanges.vsSaveChangesYes); } else { doc.Save(assemblyFile); } } msg = $"{solutionItem.Name} {debugAttribute}: {newVersion}"; if (success) { msg += " [SUCCESS]"; } else { msg += " [FAILED]"; } Logger.Write(msg); } catch (Exception ex) { Logger.Write($"Error occured while updating version.\n{ex}", LogLevel.Error); } }
private void UpdateRecursive(SolutionItem solutionItem) { try { if (!this.IsSolutionItemModified(solutionItem)) { return; } if (solutionItem.IncrementSettings.UseGlobalSettings) { solutionItem.ApplyGlobalSettings(); } if (this.ActiveConfigurationMatch(solutionItem)) { if (solutionItem.IncrementSettings.AutoUpdateAssemblyVersion) { this.Update(solutionItem, "AssemblyVersion"); } if (solutionItem.IncrementSettings.AutoUpdateFileVersion) { this.Update(solutionItem, "AssemblyFileVersion"); } } } catch (Exception ex) { Logger.Write(ex.ToString(), LogLevel.Error); } foreach (SolutionItem current in solutionItem.SubItems) { this.UpdateRecursive(current); } }
internal StringVersion Increment(StringVersion currentVersion, DateTime buildStartDate, DateTime projectStartDate, SolutionItem solutionItem) { IncrementContext incrementContext = new IncrementContext(currentVersion, buildStartDate, projectStartDate, solutionItem.Filename); BaseIncrementor[] array = new BaseIncrementor[] { this.Major, this.Minor, this.Build, this.Revision }; for (int i = 0; i < 4; i++) { BaseIncrementor baseIncrementor = array[i]; if (baseIncrementor != null) { VersionComponent versionComponent = (VersionComponent)i; baseIncrementor.Increment(incrementContext, versionComponent); if (!incrementContext.Continue) { break; } } } return incrementContext.NewVersion; }
/// <summary> /// Checks whatever solution item is modified or not /// </summary> /// <param name="solutionItem">Solution item which need to be checked</param> /// <returns>true when solution item is modified and false otherwise</returns> private bool IsSolutionItemModified(SolutionItem solutionItem) { string key = String.Format("{0}:{1}", solutionItem.ItemType, solutionItem.Name); if (_solutionItemCache.ContainsKey(key)) { bool result = _solutionItemCache[key]; return(result); } // If not detect changes was set // we need to mark current item as modified if (!solutionItem.IncrementSettings.DetectChanges) { Logger.Write(String.Format("Detect changes disabled. Mark item '{0}' as modified.", solutionItem.Name), LogLevel.Debug); _solutionItemCache.Add(key, true); return(true); } PrepareSolutionItem(solutionItem); switch (solutionItem.ItemType) { case SolutionItemType.Project: { bool result = IsProjectModified(solutionItem.Project, solutionItem.ProjectType); _solutionItemCache.Add(String.Format("{0}:{1}", solutionItem.ItemType, solutionItem.Name), result); return(result); } case SolutionItemType.Folder: case SolutionItemType.Solution: { bool result = false; foreach (SolutionItem subItem in solutionItem.SubItems) { if (subItem.ItemType == SolutionItemType.Project) { result = IsProjectModified(subItem.Project, subItem.ProjectType); _solutionItemCache.Add(String.Format("{0}:{1}", subItem.ItemType, subItem.Name), result); } else if (subItem.ItemType == SolutionItemType.Folder) { result = IsSolutionItemModified(subItem); } if (result) { break; } } Logger.Write(String.Format("Solution/Folder '{0}' is not modified", solutionItem.Name), LogLevel.Debug); _solutionItemCache.Add(key, result); return(result); } } // Unknown items are for us modified so this will launch std // behavior of BVI Logger.Write(String.Format("Solution item '{0}' is not supported. Run standard behavior (is modified).", solutionItem.ItemType), LogLevel.Warning); _solutionItemCache.Add(key, true); return(true); }