public override bool Execute() { try { EncodedFile encodedFile = new EncodedFile(this.path); string content = encodedFile.Read(); content = content.Replace(this.find, this.replace); encodedFile.Write(content); return(true); } catch (Exception ex) { Log.LogError(ex.Message); } return(false); }
private void UpdateAssemblyInfoFilesCPlusPlus(string[] files, Version version, Version fileVersion) { foreach (string file in files) { EncodedFile encodedFile = new EncodedFile(file); string content = encodedFile.Read(); string versionString = "[assembly: AssemblyVersionAttribute(\"" + version.ToString() + "\")]"; Regex regex = new Regex("\\[assembly:\\s*AssemblyVersionAttribute.+?\\]", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, versionString); string fileVersionString = "[assembly: AssemblyFileVersionAttribute(\"" + fileVersion.ToString() + "\")]"; regex = new Regex("\\[assembly:\\s*AssemblyFileVersionAttribute.+?\\]", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, fileVersionString); if (!string.IsNullOrEmpty(this.CompanyName)) { string replace = "[assembly: AssemblyCompanyAttribute(\"" + this.CompanyName + "\")]"; string search = "\\[assembly:\\s*AssemblyCompanyAttribute.+?\\]"; regex = new Regex(search, RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, replace); } if (!string.IsNullOrEmpty(this.Copyright)) { string replace = "[assembly: AssemblyCopyrightAttribute(\"" + this.Copyright + "\")]"; string search = "\\[assembly:\\s*AssemblyCopyrightAttribute.+?\\]"; regex = new Regex(search, RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, replace); } if (!string.IsNullOrEmpty(this.ProductName)) { string replace = "[assembly: AssemblyProductAttribute(\"" + this.ProductName + "\")]"; string search = "\\[assembly:\\s*AssemblyProductAttribute.+?\\]"; regex = new Regex(search, RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, replace); } encodedFile.Write(content); LogWrite(file); } }
private void UpdateAssemblyInfoFileCSharp(ITaskItem file, Version version, Version fileVersion) { EncodedFile encodedFile = new EncodedFile(file.ItemSpec); string content = encodedFile.Read(); string versionString = "[assembly: AssemblyVersion(\"" + version.ToString() + "\")]"; Regex regex = new Regex("\\[assembly:\\s*AssemblyVersion.+?\\]", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, versionString); string fileVersionString = "[assembly: AssemblyFileVersion(\"" + fileVersion.ToString() + "\")]"; regex = new Regex("\\[assembly:\\s*AssemblyFileVersion.+?\\]", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, fileVersionString); if (!string.IsNullOrEmpty(this.CompanyName)) { string replace = "[assembly: AssemblyCompany(\"" + this.CompanyName + "\")]"; string search = "\\[assembly:\\s*AssemblyCompany.+?\\]"; regex = new Regex(search, RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, replace); } if (!string.IsNullOrEmpty(this.Copyright)) { string replace = "[assembly: AssemblyCopyright(\"" + this.Copyright + "\")]"; string search = "\\[assembly:\\s*AssemblyCopyright.+?\\]"; regex = new Regex(search, RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, replace); } if (!string.IsNullOrEmpty(this.ProductName)) { string replace = "[assembly: AssemblyProduct(\"" + this.ProductName + "\")]"; string search = "\\[assembly:\\s*AssemblyProduct.+?\\]"; regex = new Regex(search, RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, replace); } encodedFile.Write(content); LogWrite(file.ItemSpec); }
private void UpdateVisualBasicProjectFiles(string path, Version version) { string[] files = Directory.GetFiles(path, "*.vbp"); foreach (string file in files) { EncodedFile encodedFile = new EncodedFile(file); string content = encodedFile.Read(); //MajorVer=4 //MinorVer=0 //RevisionVer=1 Regex regex = new Regex("MajorVer=\\d+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "MajorVer=" + version.Major.ToString()); regex = new Regex("MinorVer=\\d+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "MinorVer=" + version.Minor.ToString()); regex = new Regex("RevisionVer=\\d+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "RevisionVer=" + version.Revision.ToString()); //if ( !string.IsNullOrEmpty( this.CompanyName ) ) //{ // regex = new Regex( "VersionCompanyName=\\d+", RegexOptions.Multiline | RegexOptions.IgnoreCase ); // content = regex.Replace( content, "VersionCompanyName=\"" + this.CompanyName + "\"" ); //} //if ( !string.IsNullOrEmpty( this.Copyright ) ) //{ // regex = new Regex( "VersionLegalCopyright=\\d+", RegexOptions.Multiline | RegexOptions.IgnoreCase ); // content = regex.Replace( content, "VersionLegalCopyright=\"" + this.Copyright + "\"" ); //} //if ( !string.IsNullOrEmpty( this.ProductName ) ) //{ // regex = new Regex( "VersionProductName=.+?\\>\"", RegexOptions.Multiline | RegexOptions.IgnoreCase ); // content = regex.Replace( content, "VersionProductName=\"" + this.ProductName + "\""); //} encodedFile.Write(content); LogWrite(file); } }
private void UpdateVersionInfoFiles(string path, Version version) { // *.vbp;AssemblyInfo.cs;VersionInfo.h; string[] files = Directory.GetFiles(path, "Version?Info.h"); foreach (string file in files) { EncodedFile encodedFile = new EncodedFile(file); string content = encodedFile.Read(); string versionString = version.Major.ToString() + "." + version.Minor.ToString() + "." + version.Build.ToString() + "." + version.Revision.ToString(); Regex regex = new Regex("#define\\s+FILE_MAJOR.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define FILE_MAJOR " + version.Major.ToString()); regex = new Regex("#define\\s+FILE_MINOR.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define FILE_MINOR " + version.Minor.ToString()); regex = new Regex("#define\\s+FILE_BUILD.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define FILE_BUILD " + version.Build.ToString()); regex = new Regex("#define\\s+FILE_PRIVATE.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define FILE_PRIVATE " + version.Revision.ToString()); regex = new Regex("#define\\s+FILE_VER_STRING.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define FILE_VER_STRING \"" + versionString + "\""); regex = new Regex("#define\\s+PRODUCT_MAJOR.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define PRODUCT_MAJOR " + version.Major.ToString()); regex = new Regex("#define\\s+PRODUCT_MINOR.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define PRODUCT_MINOR " + version.Minor.ToString()); regex = new Regex("#define\\s+PRODUCT_BUILD.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define PRODUCT_BUILD " + version.Build.ToString()); regex = new Regex("#define\\s+PRODUCT_PRIVATE.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define PRODUCT_PRIVATE " + version.Revision.ToString()); regex = new Regex("#define\\s+PRODUCT_VER_STRING.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define PRODUCT_VER_STRING \"" + versionString + "\""); if (!string.IsNullOrEmpty(this.CompanyName)) { regex = new Regex("#define\\s+COMPANYNAME.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define COMPANYNAME \"" + this.CompanyName + "\""); } if (!string.IsNullOrEmpty(this.Copyright)) { regex = new Regex("#define\\s+COPYRIGHT.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define COPYRIGHT \"" + this.Copyright + "\""); } if (!string.IsNullOrEmpty(this.ProductName)) { regex = new Regex("#define\\s+PRODUCTNAME.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define PRODUCTNAME \"" + this.ProductName + "\""); } regex = new Regex("#define\\s+VINFO_HI_FILEVERSION.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_HI_FILEVERSION " + version.Major.ToString()); regex = new Regex("#define\\s+VINFO_LO_FILEVERSION.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_LO_FILEVERSION " + version.Minor.ToString()); regex = new Regex("#define\\s+VINFO_HI_FILEBUILD.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_HI_FILEBUILD " + version.Build.ToString()); regex = new Regex("#define\\s+VINFO_LO_FILEBUILD.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_LO_FILEBUILD " + version.Revision.ToString()); //regex = new Regex("#define\\s+FILE_VER_STRING.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); //content = regex.Replace(content, "#define FILE_VER_STRING \"" + versionString + "\""); regex = new Regex("#define\\s+VINFO_HI_PRODUCTVERSION.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_HI_PRODUCTVERSION " + version.Major.ToString()); regex = new Regex("#define\\s+VINFO_LO_PRODUCTVERSION.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_LO_PRODUCTVERSION " + version.Minor.ToString()); regex = new Regex("#define\\s+VINFO_HI_PRODUCTBUILD.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_HI_PRODUCTBUILD " + version.Build.ToString()); regex = new Regex("#define\\s+VINFO_LO_PRODUCTBUILD.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_LO_PRODUCTBUILD " + version.Revision.ToString()); //regex = new Regex("#define\\s+PRODUCT_VER_STRING.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); //content = regex.Replace(content, "#define PRODUCT_VER_STRING \"" + versionString + "\""); if (!string.IsNullOrEmpty(this.CompanyName)) { regex = new Regex("#define\\s+VINFO_STRING_COMPANYNAME.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_STRING_COMPANYNAME \"" + this.CompanyName + "\""); } if (!string.IsNullOrEmpty(this.Copyright)) { regex = new Regex("#define\\s+VINFO_STRING_COPYRIGHT.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_STRING_COPYRIGHT \"" + this.Copyright + "\""); } if (!string.IsNullOrEmpty(this.ProductName)) { regex = new Regex("#define\\s+VINFO_STRING_PRODUCTNAME.+", RegexOptions.Multiline | RegexOptions.IgnoreCase); content = regex.Replace(content, "#define VINFO_STRING_PRODUCTNAME \"" + this.ProductName + "\""); } encodedFile.Write(content); LogWrite(file); } }