/// <summary> /// Updates the version tag inside the given file. /// </summary> /// <param name="fileName">The file containing the version tag.</param> /// <returns>The updated version build number.</returns> public static string VersionUpdate(string fileName) { string version = null; try { if (File.Exists(fileName)) { string contents = File.ReadAllText(fileName); if (!string.IsNullOrWhiteSpace(contents)) { VersionFileType fileType = GetFileType(fileName); switch (fileType) { case VersionFileType.AssemblyInfo: contents = AssemblyInfoUpdate( contents, out version); break; case VersionFileType.CsProj: contents = CsProjUpdate( contents, out version); break; default: break; } File.WriteAllText(fileName, contents); } } } catch (Exception exception) when (exception is ArgumentException || exception is ArgumentNullException || exception is ArgumentOutOfRangeException || exception is DirectoryNotFoundException || exception is FileNotFoundException || exception is FormatException || exception is IOException || exception is NotSupportedException || exception is OverflowException || exception is PathTooLongException || exception is System.Security.SecurityException || exception is UnauthorizedAccessException) { } return(version); }
public void Read(BinaryReader reader) { this.signature = reader.ReadUInt32(); this.structVersion = reader.ReadUInt32(); this.fileVersion = UInt64ToVersion(reader.ReadUInt64()); this.productVersion = UInt64ToVersion(reader.ReadUInt64()); this.fileFlagsMask = (VersionBuildTypes)reader.ReadInt32(); this.fileFlags = (VersionBuildTypes)reader.ReadInt32(); this.fileOS = (VersionFileOS)reader.ReadInt32(); this.fileType = (VersionFileType)reader.ReadInt32(); this.fileSubtype = (VersionFileSubtype)reader.ReadInt32(); this.timestamp = UInt64ToDateTime(reader.ReadUInt64()); }
/// <summary> /// Converts a <see cref="VersionFileType" /> to string /// </summary> /// <returns>The string.</returns> /// <param name="type"> /// <see cref="VersionFileType" /> /// </param> public static string TypeToString(VersionFileType type) { switch (type) { case VersionFileType.VFT_APP: return("Application"); case VersionFileType.VFT_DLL: return("Dynamic-link library"); case VersionFileType.VFT_DRV: return("Device driver"); case VersionFileType.VFT_FONT: return("Font"); case VersionFileType.VFT_STATIC_LIB: return("Static-link library"); case VersionFileType.VFT_UNKNOWN: return("Unknown"); case VersionFileType.VFT_VXD: return("Virtual device"); default: return($"Unknown type code {(uint)type}"); } }
private static VersionFileType GetFileType(string fileName) { VersionFileType fileType = VersionFileType.Generic; string extension = Path.GetExtension(fileName); switch (extension) { case ".cs": fileType = VersionFileType.AssemblyInfo; break; case ".csproj": fileType = VersionFileType.CsProj; break; default: break; } return(fileType); }
public void Read(BinaryReader reader) { this.signature = reader.ReadUInt32(); this.structVersion = reader.ReadUInt32(); this.fileVersion = UInt64ToVersion(reader.ReadUInt64()); this.productVersion = UInt64ToVersion(reader.ReadUInt64()); this.fileFlagsMask = (VersionBuildTypes) reader.ReadInt32(); this.fileFlags = (VersionBuildTypes) reader.ReadInt32(); this.fileOS = (VersionFileOS) reader.ReadInt32(); this.fileType = (VersionFileType) reader.ReadInt32(); this.fileSubtype = (VersionFileSubtype) reader.ReadInt32(); this.timestamp = UInt64ToDateTime(reader.ReadUInt64()); }