<Project>
	<PropertyGroup Label="Version settings">
		<!--
            Use the following values for the different release types:
          - "alpha"     - EF Core release independent, code quality unstable,         major changes
          - "beta"      - EF Core release independent, code quality stable,           can introduce breaking changes
          - "silver"    - EF Core release independent, code quality stable,           only minor changes are expected

          - "preview"   - EF Core release targeted,    code quality stable,           can introduce breaking changes
          - "rc"        - EF Core release targeted,    code quality production ready, only minor changes are expected

          - "rtm"       - EF Core release independent, code quality production ready, major release
          - "servicing" - EF Core release independent, code quality production ready, mainly bugfixes
          
            Bump-up to the next iteration immediately after a release, so that subsequent daily builds are named
            correctly.
        -->
		<VersionPrefix>10.0.0</VersionPrefix>
		<PreReleaseVersionLabel>beta</PreReleaseVersionLabel>
		<PreReleaseVersionIteration>1</PreReleaseVersionIteration>

		<!--
            The following properties will automatically be set by CI builds when appropriate:
            OfficialVersion
            ContinuousIntegrationTimestamp
            BuildSha
        -->
	</PropertyGroup>

	<!--
    If no official version has been explicitly set (or no version or version suffix), we generate a version suffix in the following formats:
            alpha.1.ci.20201004T181121Z+sha.0a1b2c3
            alpha.1.ci.20201004T181121Z.debug+sha.0a1b2c3
    -->
	<PropertyGroup>
		<UseVersionOverride Condition="'$(Version)' != ''">true</UseVersionOverride>
		<UseVersionSuffixOverride Condition="'$(VersionSuffix)' != ''">true</UseVersionSuffixOverride>
		<FinalOfficialVersion>$(OfficialVersion)</FinalOfficialVersion>
	</PropertyGroup>

	<PropertyGroup Label="Version Suffix Handling" Condition="'$(UseVersionOverride)' != 'true' And '$(UseVersionSuffixOverride)' != 'true'">
		<VersionSuffix Condition="'$(OfficialVersion)' == '' Or $(OfficialVersion.Contains('-'))">$(PreReleaseVersionLabel).$(PreReleaseVersionIteration)</VersionSuffix>
		<VersionSuffix Condition="'$(OfficialVersion)' == '' And '$(ContinuousIntegrationTimestamp)' != ''">$(VersionSuffix).ci.$(ContinuousIntegrationTimestamp)</VersionSuffix>
		<VersionSuffix Condition="'$(Configuration)' == 'Debug'">$(VersionSuffix).debug</VersionSuffix>
		<VersionSuffix Condition="'$(BuildSha)' != ''">$(VersionSuffix)+sha.$(BuildSha)</VersionSuffix>
		<VersionSuffix>$(VersionSuffix.TrimStart(`.`))</VersionSuffix>

		<FinalOfficialVersion Condition="'$(Configuration)' == 'Debug' And $(FinalOfficialVersion.Contains('-'))">$(FinalOfficialVersion).debug</FinalOfficialVersion>
		<FinalOfficialVersion Condition="'$(Configuration)' == 'Debug' And !$(FinalOfficialVersion.Contains('-'))">$(FinalOfficialVersion)-debug</FinalOfficialVersion>
	</PropertyGroup>

	<Target Name="EnsureVersionParameters" BeforeTargets="CoreBuild" Condition="'$(UseVersionOverride)' != 'true' And '$(UseVersionSuffixOverride)' != 'true'">
		<Message Condition="'$(OfficialVersion)' != ''" Importance="high" Text="OfficialVersion: $(OfficialVersion)" />
		<Message Condition="'$(OfficialVersion)' != ''" Importance="high" Text="FinalOfficialVersion: $(FinalOfficialVersion)" />
		<Message Condition="'$(OfficialVersion)' != ''" Importance="high" Text="VersionPrefix: $(VersionPrefix)" />
		<Message Condition="'$(OfficialVersion)' != ''" Importance="high" Text="VersionSuffix: $(VersionSuffix)" />
		<Message Condition="'$(OfficialVersion)' != ''" Importance="high" Text="Version: $(Version)" />

		<Error Condition="'$(VersionPrefix)' == ''" Text="The 'VersionPrefix' property needs to be set."/>
		<Error Condition="'$(PreReleaseVersionLabel)' == ''" Text="The 'PreReleaseVersionLabel' property needs to be set."/>
		<Error Condition="'$(PreReleaseVersionIteration)' == ''" Text="The 'PreReleaseVersionIteration' property needs to be set."/>
		<Error Condition="'$(OfficialVersion)' != '' And '$(FinalOfficialVersion)' != '$(VersionPrefix)' And '$(FinalOfficialVersion)' != '$(VersionPrefix)-$(VersionSuffix)'" Text="The 'OfficialVersion' property needs to be identical to the 'VersionPrefix' property or to a combination of the 'VersionPrefix' and the 'VersionSuffix' properties." />
	</Target>
</Project>
