/// <summary> /// Process the new style CSProj file /// </summary> /// <param name="project"></param> /// <returns></returns> private ProjectVersion ProcessNewStyleProject(Project project) { var version = string.Empty; var fileVersion = string.Empty; var packageVersion = string.Empty; ThreadHelper.ThrowIfNotOnUIThread(); foreach (Property aProp in project.Properties) { if (aProp.Name.ToLower().Equals("assemblyversion")) { version = aProp.Value as String; } else if (aProp.Name.ToLower().Equals("fileversion")) { fileVersion = aProp.Value as String; } else if (aProp.Name.ToLower().Equals("version")) { packageVersion = aProp.Value as String; } } //is this using the new style csproj if (version != String.Empty) { //MessageBox.Show(String.Format("{0} \n {1}", proj.Name, version)); var newVersion = new ProjectVersion(); newVersion.Name = project.Name; newVersion.Path = project.FileName; newVersion.RealProject = project; newVersion.IsNewStyleProject = true; newVersion.ProjectType = "SDK"; try { newVersion.AssemblyVersion = new Version(version); } catch { newVersion.AssemblyVersion = new Version("1.0"); } if (fileVersion != String.Empty) { try { newVersion.FileVersion = new Version(fileVersion); } catch { newVersion.FileVersion = newVersion.AssemblyVersion; } } return(newVersion); } return(null); }
/// <summary> /// Process the old style csproj file /// </summary> /// <param name="project"></param> /// <param name="projectItem"></param> /// <returns></returns> private ProjectVersion ProcessOldStyleProject(Project project, ProjectItem projectItem) { ThreadHelper.ThrowIfNotOnUIThread(); string version = String.Empty; string fileVersion = String.Empty; if (!projectItem.IsOpen) { projectItem.Open(); } var aDoc = projectItem.Document; TextDocument editDoc = (TextDocument)aDoc.Object("TextDocument"); var objEditPt = editDoc.StartPoint.CreateEditPoint(); objEditPt.StartOfDocument(); var endPpint = editDoc.EndPoint.CreateEditPoint(); endPpint.EndOfDocument(); string searchText = "AssemblyVersion(\""; string searchText2 = "AssemblyFileVersion(\""; var ednLine = endPpint.Line; while (objEditPt.Line <= ednLine) { var aLine = objEditPt.GetText(objEditPt.LineLength); if (!aLine.StartsWith("//") && !aLine.StartsWith("'")) { if (aLine.Contains(searchText)) { //now get the version number int locationStart = aLine.IndexOf(searchText); string remaining = aLine.Substring((locationStart + searchText.Length)); int locationEnd = remaining.IndexOf("\""); version = remaining.Substring(0, locationEnd); } if (aLine.Contains(searchText2)) { int locationStart = aLine.IndexOf(searchText2); string remaining = aLine.Substring((locationStart + searchText2.Length)); int locationEnd = remaining.IndexOf("\""); fileVersion = remaining.Substring(0, locationEnd); } } if (!String.IsNullOrWhiteSpace(version) && !String.IsNullOrWhiteSpace(fileVersion)) { break; } if (objEditPt.Line == ednLine) { break; } else { objEditPt.LineDown(); objEditPt.StartOfLine(); } } aDoc.Close(); aDoc = null; if (version != String.Empty) { var newVersion = new ProjectVersion(); newVersion.Name = project.Name; newVersion.Path = projectItem.FileNames[0]; newVersion.RealProject = project; newVersion.ProjectItem = projectItem; newVersion.ProjectType = "Standard"; try { newVersion.AssemblyVersion = new Version(version); } catch { newVersion.AssemblyVersion = new Version("1.0"); } if (fileVersion != String.Empty) { try { newVersion.FileVersion = new Version(fileVersion); } catch { newVersion.FileVersion = newVersion.AssemblyVersion; } } return(newVersion); } else { var newFailedProject = new FailedProject() { Name = project.Name, FailedAssemblyVersion = string.IsNullOrWhiteSpace(version), FailedAssemblyFileVersion = string.IsNullOrWhiteSpace(fileVersion), }; FailedProjects.Add(newFailedProject); } return(null); }