Changed code so that the version Number is only changed when something in the source is changed.
This commit is contained in:
parent
b1f231ac47
commit
052153fbd8
@ -12,32 +12,88 @@ namespace AdjustBuildRevision
|
|||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
// args[0] - FileName
|
// args[0] - FileName
|
||||||
FileInfo fi = new FileInfo(args[0]);
|
try
|
||||||
if (fi.Exists)
|
|
||||||
{
|
{
|
||||||
StreamReader sr = fi.OpenText();
|
FileInfo fi = new FileInfo(args[0]);
|
||||||
string content = sr.ReadToEnd();
|
DateTime dtLatest = GetLatestDateTime(fi.Directory.Parent,fi.LastWriteTime);
|
||||||
sr.Close();
|
if (fi.Exists)
|
||||||
StreamWriter sw = fi.CreateText();
|
|
||||||
string[] seps = { "\r\n" };
|
|
||||||
string[] lines = content.Split(seps, StringSplitOptions.None);
|
|
||||||
foreach (string line in lines)
|
|
||||||
{
|
{
|
||||||
string outline = line;
|
StreamReader sr = fi.OpenText();
|
||||||
if (line.Contains("AssemblyVersion") || line.Contains("AssemblyFileVersion"))
|
string content = sr.ReadToEnd();
|
||||||
|
sr.Close();
|
||||||
|
string[] seps = { "\r\n" };
|
||||||
|
string[] lines = content.Split(seps, StringSplitOptions.None);
|
||||||
|
bool changed = false;
|
||||||
|
for (int i = 0; i < lines.Length;i++ )
|
||||||
{
|
{
|
||||||
Console.WriteLine("Before: '{0}'", line);
|
string line = lines[i];
|
||||||
outline = Regex.Replace(line,@"([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("yyMM.dHH")+"\")");
|
string outline = line;
|
||||||
Console.WriteLine("After: '{0}'", outline);
|
if (line.Contains("AssemblyVersion") || line.Contains("AssemblyFileVersion"))
|
||||||
|
{
|
||||||
|
outline = Regex.Replace(line, @"([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)""\)", DateTime.Now.ToString("1.1.yyMM.dHH") + "\")");
|
||||||
|
if (outline != line)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Before: '{0}'", line);
|
||||||
|
Console.WriteLine("After: '{0}'", outline);
|
||||||
|
lines[i] = outline;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("No change: '{0}'", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
if (!fi.IsReadOnly) fi.IsReadOnly = false;
|
||||||
|
StreamWriter sw = fi.CreateText();
|
||||||
|
foreach (string line in lines)
|
||||||
|
sw.WriteLine(line);
|
||||||
|
sw.Close();
|
||||||
}
|
}
|
||||||
sw.WriteLine(outline);
|
|
||||||
}
|
}
|
||||||
sw.Close();
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("File " + fi.FullName + " does not exist");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("File " + fi.FullName + " does not exist");
|
MessageBox.Show(ex.Message, ex.GetType().FullName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//private static DateTime GetLatestDateTime(string path)
|
||||||
|
//{
|
||||||
|
// return GetLatestDateTime(new DirectoryInfo(path));
|
||||||
|
//}
|
||||||
|
private static DateTime GetLatestDateTime(DirectoryInfo di, DateTime dtCheck)
|
||||||
|
{
|
||||||
|
DateTime dtMax = dtCheck;
|
||||||
|
FileInfo[] myFiles = di.GetFiles();
|
||||||
|
foreach(FileInfo myFile in myFiles)
|
||||||
|
{
|
||||||
|
DateTime dt = myFile.LastWriteTime;
|
||||||
|
//if (dt > dtCheck)
|
||||||
|
//{
|
||||||
|
//Console.WriteLine("\"File\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}",myFile.FullName,dt.ToString("1.1.yyMM.dHH"),dt,dtCheck);
|
||||||
|
if(dtMax < dt) dtMax = dt;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
DirectoryInfo[] myFolders = di.GetDirectories();
|
||||||
|
foreach (DirectoryInfo diChild in myFolders)
|
||||||
|
{
|
||||||
|
DateTime dtChild = GetLatestDateTime(diChild,dtCheck);
|
||||||
|
//if (dtChild > dtCheck)
|
||||||
|
//{
|
||||||
|
//Console.WriteLine("\"SubFolder\"\t\"{0}\"\t\"{1}\"\t{2}\t{3}", diChild.FullName, dtChild.ToString("1.1.yyMM.dHH"),dtChild,dtCheck);
|
||||||
|
if(dtChild > dtMax) dtMax = dtChild;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
//if(dtMax > dtCheck)
|
||||||
|
// Console.WriteLine("\"Folder\"\t\"{0}\"\t\"{1}\"", di.FullName, dtMax.ToString("1.1.yyMM.dHH"));
|
||||||
|
return dtMax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user