Skip to content

Commit

Permalink
Fix version calculation when using ServicingVersion for dependencies …
Browse files Browse the repository at this point in the history
…and current package
  • Loading branch information
safern committed Nov 17, 2021
1 parent c60a9eb commit 28b425b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
16 changes: 6 additions & 10 deletions eng/packaging.targets
Expand Up @@ -39,16 +39,6 @@
<UseIntellisenseDocumentationFile Condition="'$(UseIntellisenseDocumentationFile)' == '' and Exists('$(LibIntellisenseDocumentationFilePath)')">true</UseIntellisenseDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition="'$(ServicingVersion)' != ''">
<!-- Always update the package version in servicing. -->
<VersionPrefix>$(MajorVersion).$(MinorVersion).$(ServicingVersion)</VersionPrefix>
<_IsWindowsDesktopApp Condition="$(WindowsDesktopCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsWindowsDesktopApp>
<_IsAspNetCoreApp Condition="$(AspNetCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsAspNetCoreApp>
<_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true</_AssemblyInTargetingPack>
<!-- Assembly version do not get updated in non-netfx ref pack assemblies. -->
<AssemblyVersion Condition="'$(_AssemblyInTargetingPack)' != 'true'">$(MajorVersion).$(MinorVersion).0.$(ServicingVersion)</AssemblyVersion>
</PropertyGroup>

<ItemGroup Condition="'$(EnablePackageValidation)' == 'true'">
<PackageReference Include="Microsoft.DotNet.Compatibility" Version="$(MicrosoftDotNetCompatibilityVersion)" PrivateAssets="all" IsImplicitlyDefined="true" />
</ItemGroup>
Expand Down Expand Up @@ -272,4 +262,10 @@
<Error Condition="'$(AssemblyVersion)' != '$(LastReleasedStableAssemblyVersion)'" Text="AssemblyVersion should match last released assembly version $(LastReleasedStableAssemblyVersion)" />
</Target>

<Target Name="ValidateServicingVersionIsPropertlySet"
Condition="'$(PreReleaseVersionLabel)' == 'servicing'"
AfterTargets="GenerateNuspec">
<Error Condition="'$(ServicingVersion)' == '0'" Text="ServicingVersion is set to 0 and it should be an increment of the patch version from the last released package." />
</Target>

</Project>
17 changes: 17 additions & 0 deletions src/libraries/BeforeCommon.targets
@@ -0,0 +1,17 @@
<Project>

<!-- We need to set these properties before the arcade Version.BeforeCommonTargets.targets are imported -->
<PropertyGroup Condition="'$(PreReleaseVersionLabel)' == 'servicing' and '$(IsPackable)' == 'true'">
<!-- If no servicing version is set we need to default to 0 in order for dependency versions to
be calculated propertly, if we don't set it to 0, we would get the dependency version using the
product Patch Version -->
<ServicingVersion Condition="'$(ServicingVersion)' == ''">0</ServicingVersion>
<!-- Always update the patch version in servicing so that arcade sets the correct package version. -->
<PatchVersion>$(ServicingVersion)</PatchVersion>
<_IsWindowsDesktopApp Condition="$(WindowsDesktopCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsWindowsDesktopApp>
<_IsAspNetCoreApp Condition="$(AspNetCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsAspNetCoreApp>
<_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true</_AssemblyInTargetingPack>
<!-- Assembly version do not get updated in non-netfx ref pack assemblies. -->
<AssemblyVersion Condition="'$(_AssemblyInTargetingPack)' != 'true'">$(MajorVersion).$(MinorVersion).0.$(ServicingVersion)</AssemblyVersion>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions src/libraries/Directory.Build.props
Expand Up @@ -10,6 +10,12 @@

<!-- Set OutDirName to change BaseOutputPath and BaseIntermediateOutputPath to include the ref subfolder. -->
<OutDirName Condition="'$(IsReferenceAssembly)' == 'true'">$(MSBuildProjectName)$([System.IO.Path]::DirectorySeparatorChar)ref</OutDirName>

<!-- Set before common targets, we need to set these properties before importing arcade in order for arcade to import them
at the right order. -->
<CustomBeforeMicrosoftCommonTargets>$(MSBuildThisFileDirectory)\BeforeCommon.targets</CustomBeforeMicrosoftCommonTargets>
<!-- Since we don't have any before common targets specific to cross build, just set the same. -->
<CustomBeforeMicrosoftCommonCrossTargetingTargets>$(CustomBeforeMicrosoftCommonTargets)</CustomBeforeMicrosoftCommonCrossTargetingTargets>
</PropertyGroup>

<Import Project="..\..\Directory.Build.props" />
Expand Down

0 comments on commit 28b425b

Please sign in to comment.