本文整理汇总了C#中AssemblyInfo.GenerateFile方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyInfo.GenerateFile方法的具体用法?C# AssemblyInfo.GenerateFile怎么用?C# AssemblyInfo.GenerateFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssemblyInfo
的用法示例。
在下文中一共展示了AssemblyInfo.GenerateFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
/// <summary>
/// Runs the task.
/// </summary>
/// <remarks>
/// This autoincrements assembly verions.
/// </remarks>
/// <returns><c>true</c> if the task completed successfully;
/// <c>false</c> otherwise.</returns>
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;
}