loresoft/msbuildtasks

Suggestion for improvement --> Versioning number

erfajo opened this issue · 1 comments

I have just stumbled upon this project and find it very useful. I am going to use it as a NuGet package. Therefore, will I not change your code so it suits my purpose better. Instead, I hope you will consider my suggestion for more flexible build type and revision type numbering.

I bring up this suggestion since I want to hold a versioning where I control the major.minor.build part. And for revision will I use days for now. E.g. 200.3.0.6792

This is not possible now if I use your tools as it is meant to be used. For now, I have tweaked it as e.g. AssemblyVersion="$(Major).$(Minor).$(Revision).$(Build)". My problem is if I had used revision as automatic, then I would get the second. I have four projects in my solution, and therefore I will get four different revisions numbers on my assemblies. This is not doable.
However, I would like to use “minutes since start date” or “hours since start date” that would give me the needed flexibility. Therefore I have this suggestion for your Version.cs file

// could be any of your four enumerations, example is _buildTypeEnum
switch (_buildTypeEnum)
{
    case BuildTypeEnum.Automatic:
        _build = CalculateDaysSinceStartDate();
        break;
    case BuildTypeEnum.Increment:
        _build++;
        break;
    case BuildTypeEnum.Reset:
        _build = 0;
        break;
    case BuildTypeEnum.None:
    default:
        break;
}

// could be any of your four enumerations, needed is _buildTypeEnum and _revisionTypeEnum
switch (_buildTypeEnum)
{
    case BuildTypeEnum.AutoDay:
        _build = CalculateDaysSinceStartDate();
        break;
    case BuildTypeEnum.AutoHour:
        _build = CalculateHoursSinceStartDate();
        break;
    case BuildTypeEnum.AutoMinute:
        _build = CalculateMinutesSinceStartDate();
        break;
    case BuildTypeEnum.AutoSecond:
        _build = CalculateFractionalPartOfDay();  //CalculateSecondsSinceStartDate();
        break;
    case BuildTypeEnum.Increment:
        _build++;
        break;
    case BuildTypeEnum.Reset:
        _build = 0;
        break;
    case BuildTypeEnum.None:
    default:
        break;
}

switch (_revisionTypeEnum)
{
    case RevisionTypeEnum.AutoDay:
        _build = CalculateDaysSinceStartDate();
        break;
    case RevisionTypeEnum.AutoHour:
        _build = CalculateHoursSinceStartDate();
        break;
    case RevisionTypeEnum.AutoMinute:
        _build = CalculateMinutesSinceStartDate();
        break;
    case RevisionTypeEnum.AutoSecond:
        _build = CalculateFractionalPartOfDay();  //CalculateSecondsSinceStartDate();
        break;
    case RevisionTypeEnum.Increment:
        _build++;
        break;
    case RevisionTypeEnum.Reset:
        _build = 0;
        break;
    case RevisionTypeEnum.None:
    default:
        break;
}

private int CalculateDaysSinceStartDate()
{
    return DateTime.Today.Subtract(_startDate).Days;
}

private int CalculateHoursSinceStartDate()
{
    //break down a day into fractional seconds
    float factor = (float)(UInt16.MaxValue - 1) / (24);

    return (int)(DateTime.Now.TimeOfDay.TotalHours * factor);
}

private int CalculateMinutesSinceStartDate()
{
    //break down a day into fractional seconds
    float factor = (float)(UInt16.MaxValue - 1) / (24 * 60);

    return (int)(DateTime.Now.TimeOfDay.TotalMinutes * factor);
}

private int CalculateFractionalPartOfDay()  //CalculateSecondsSinceStartDate();
{
    //break down a day into fractional seconds
    float factor = (float)(UInt16.MaxValue - 1) / (24 * 60 * 60);

    return (int)(DateTime.Now.TimeOfDay.TotalSeconds * factor);
}

Since nothing has happened and I have given up anything is going to happen I am closing this issue...