BuildTasks.AutoIncrementVersionBuildTask.Execute C# (CSharp) 메소드

Execute() 공개 메소드

Runs the task.
This autoincrements assembly verions.
public Execute ( ) : bool
리턴 bool
		public override bool Execute()
		{
			List<AssemblyInfo> lstFilesToSave = new List<AssemblyInfo>();
			foreach (ITaskItem titAssemblyInfoFile in AssemblyInfoFiles)
			{
				string strInfoFilePath = titAssemblyInfoFile.ItemSpec;
				if (!File.Exists(strInfoFilePath))
				{
					Log.LogError("Assembly Version Auto Increment", null, null, strInfoFilePath, 0, 0, 0, 0, "Unable to find Assembly Info File.");
					return false;
				}

				AssemblyInfo asiInfo = new AssemblyInfo(strInfoFilePath);
				if (asiInfo.AssemblyVersion.Split('.').Length != 2)
				{
					Log.LogError("Assembly Version Auto Increment", null, null, strInfoFilePath, asiInfo.AssemblyVersionLine, asiInfo.AssemblyVersionColumn, asiInfo.AssemblyVersionLine, asiInfo.AssemblyVersionColumn + asiInfo.AssemblyVersion.Length, "AssemblyVersion is not in Major.Minor form (Build and Revision are not allowed).");
					return false;
				}

				DateTime dteEpoch = new DateTime(2000, 01, 01, 00, 00, 00, DateTimeKind.Utc);
				Int32 intDaysSinceEpoch = (Int32)DateTime.UtcNow.Subtract(dteEpoch).TotalDays;
				DateTime dteMidnight = DateTime.UtcNow;
				dteMidnight = new DateTime(dteMidnight.Year, dteMidnight.Month, dteMidnight.Day, 0, 0, 0, DateTimeKind.Utc);
				Int32 intBiSecondsSinceMidnight = (Int32)DateTime.UtcNow.Subtract(dteMidnight).TotalSeconds / 2;

				if (String.IsNullOrEmpty(asiInfo.AssemblyFileVersionFormat))
				{
					Log.LogError("Assembly Version Auto Increment", null, null, strInfoFilePath, 0, 0, 0, 0, "AssemblyFileVersionFormat not found.");
					return false;
				}

				//Log.LogMessage("Setting AsseblyVersion: {0}", asiInfo.AssemblyVersion);
				string strAssemblyFileVersionFormat = null;
				switch (asiInfo.AssemblyFileVersionFormat.Split('.').Length)
				{
					case 0:
					case 1:
					case 2:
						Log.LogError("Assembly Version Auto Increment", null, null, strInfoFilePath, 0, 0, 0, 0, "AssemblyFileVersionFormat must be 1.1.* or 1.1.1.*");
						return false;
					case 3:
						strAssemblyFileVersionFormat = "{0}.{1}.{2}";
						break;
					case 4:
						strAssemblyFileVersionFormat = "{0}.{2}";
						lstFilesToSave.Add(asiInfo);
						break;
				}
				asiInfo.AssemblyFileVersion = String.Format(strAssemblyFileVersionFormat, asiInfo.AssemblyVersion, intDaysSinceEpoch, intBiSecondsSinceMidnight);
				lstFilesToSave.Add(asiInfo);
				Log.LogMessage("Setting AsseblyFileVersion: {0}", asiInfo.AssemblyFileVersion);				
			}

			foreach (AssemblyInfo asiInfo in lstFilesToSave)
			{
				string strTempFile = Path.GetTempFileName();
				File.WriteAllText(strTempFile, asiInfo.GenerateFile());
				File.Copy(strTempFile, asiInfo.FilePath, true);
				File.Delete(strTempFile);
			}
			return true;
		}
	}
AutoIncrementVersionBuildTask