Don't overwrite pinned assembly versions in servicing (#84079)
authorViktor Hofer <viktor.hofer@microsoft.com>
Thu, 6 Apr 2023 14:30:38 +0000 (16:30 +0200)
committerGitHub <noreply@github.com>
Thu, 6 Apr 2023 14:30:38 +0000 (07:30 -0700)
* Don't overwrite pinned assembly versions in servicing

There are eight packable projects that pin their assembly version for .NET
Framework compatibility. The incremental package servicing
infrastructure didn't check if the assembly version is pinned and always
changed it.

As an example, System.Speech pins its assembly version to 4.0.0.0 but
that version gets overwritten during servicing. I.e. for .NET 7 the
version would then change to "7.0.0.$(ServicingVersion)" which is
incorrect.

Please find the full list of impacted assemblies below:
- System.ComponentModel.Composition
- System.DirectoryServices
- System.DirectoryServices.AccountManagement
- System.DirectoryServices.Protocols
- System.Management
- System.Reflection.Context
- System.Runtime.Caching
- System.Speech

* Only pin AssemblyVersion in netstandard2.0 assemblies

These assemblies pin their AssemblyVersion to be compatible with
.NETFramework where the same assembly is inbox.

The only TargetFramework we build that is compatible with .NETFramework
is netstandard2.0, so only pin the assembly on that framework.

* Override AssemblyVersion in Directory.Build.targets

Previously assemblies would set AssemblyVersion in Directory.Build.props
which was too early, because later packaging.targets could not distinguish
between a value that was explicitly set and the default value of the repo.

Instead override the value after the Servicing value is set, in
Directory.Build.targets

* Update comments

* Remove ValidateAssemblyVersionsInRefPack target

The only thing this target did was a redundant check that AssemblyVersion was
set for projects in the Targeting Pack.  That check was failing for
the NETStandard build of System.DirectoryServices.

This target was providing no value, instead we need to fix https://github.com/dotnet/runtime/issues/42961
which will be a proper check of our servicing version rules.

* Address feedback

---------

Co-authored-by: Eric StJohn <ericstj@microsoft.com>
19 files changed:
eng/packaging.targets
src/libraries/System.ComponentModel.Composition/Directory.Build.props
src/libraries/System.ComponentModel.Composition/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.Data.DataSetExtensions/Directory.Build.props
src/libraries/System.DirectoryServices.AccountManagement/Directory.Build.props
src/libraries/System.DirectoryServices.AccountManagement/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.DirectoryServices.Protocols/Directory.Build.props
src/libraries/System.DirectoryServices.Protocols/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.DirectoryServices/Directory.Build.props
src/libraries/System.DirectoryServices/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.Management/Directory.Build.props
src/libraries/System.Management/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.Reflection.Context/Directory.Build.props
src/libraries/System.Reflection.Context/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.Reflection.Context/ref/System.Reflection.Context.csproj
src/libraries/System.Runtime.Caching/Directory.Build.props
src/libraries/System.Runtime.Caching/Directory.Build.targets [new file with mode: 0644]
src/libraries/System.Speech/Directory.Build.props
src/libraries/System.Speech/Directory.Build.targets [new file with mode: 0644]

index a4ed0ec..264fc68 100644 (file)
@@ -48,7 +48,7 @@
     <_IsWindowsDesktopApp Condition="$(WindowsDesktopCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsWindowsDesktopApp>
     <_IsAspNetCoreApp Condition="$(AspNetCoreAppLibrary.Contains('$(AssemblyName);'))">true</_IsAspNetCoreApp>
     <_AssemblyInTargetingPack Condition="('$(IsNETCoreAppSrc)' == 'true' or '$(IsNetCoreAppRef)' == 'true' or '$(_IsAspNetCoreApp)' == 'true' or '$(_IsWindowsDesktopApp)' == 'true') and '$(TargetFrameworkIdentifier)' != '.NETFramework'">true</_AssemblyInTargetingPack>
-    <!-- Assembly version do not get updated in non-netfx ref pack assemblies. -->
+    <!-- The assembly version gets updated when the assembly isn't part of a targeting pack. -->
     <AssemblyVersion Condition="'$(_AssemblyInTargetingPack)' != 'true'">$(MajorVersion).$(MinorVersion).0.$(ServicingVersion)</AssemblyVersion>
   </PropertyGroup>
 
     </ItemGroup>
   </Target>
 
-  <Target Name="ValidateAssemblyVersionsInRefPack"
-          Condition="'$(SkipValidateAssemblyVersion)' != 'true' and '$(_AssemblyInTargetingPack)' == 'true' and '$(PreReleaseVersionLabel)' == 'servicing'"
-          AfterTargets="CoreCompile" >
-    <Error Condition="'$(AssemblyVersion)' != '$(LastReleasedStableAssemblyVersion)'" Text="AssemblyVersion should match last released assembly version $(LastReleasedStableAssemblyVersion)" />
-  </Target>
-
   <Target Name="ValidateServicingVersionIsProperlySet"
           Condition="'$(PreReleaseVersionLabel)' == 'servicing' and
                      '$(PackageUseIncrementalServicingVersion)' == 'true' and
index 7b1204a..798ccfd 100644 (file)
@@ -1,7 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>ECMA</StrongNameKeyId>
   </PropertyGroup>
 </Project>
diff --git a/src/libraries/System.ComponentModel.Composition/Directory.Build.targets b/src/libraries/System.ComponentModel.Composition/Directory.Build.targets
new file mode 100644 (file)
index 0000000..fca3b1f
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly 
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index bfb6ea8..798ccfd 100644 (file)
@@ -1,8 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- AssemblyVersion is frozen to that which originally shipped in 2.1 -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>ECMA</StrongNameKeyId>
   </PropertyGroup>
 </Project>
index 4cf151d..de81d80 100644 (file)
@@ -1,10 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>ECMA</StrongNameKeyId>
     <SupportedOSPlatforms>windows</SupportedOSPlatforms>
   </PropertyGroup>
diff --git a/src/libraries/System.DirectoryServices.AccountManagement/Directory.Build.targets b/src/libraries/System.DirectoryServices.AccountManagement/Directory.Build.targets
new file mode 100644 (file)
index 0000000..fca3b1f
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly 
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index 525d9a0..831e808 100644 (file)
@@ -1,10 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
     <IncludePlatformAttributes>true</IncludePlatformAttributes>
     <UnsupportedOSPlatforms>browser;android;ios;tvos</UnsupportedOSPlatforms>
diff --git a/src/libraries/System.DirectoryServices.Protocols/Directory.Build.targets b/src/libraries/System.DirectoryServices.Protocols/Directory.Build.targets
new file mode 100644 (file)
index 0000000..1cdbd69
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index 0740890..709a22a 100644 (file)
@@ -1,13 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
-    <!-- Since this assembly version is pinned, we don't want to validate that it matches
-    the expected assembly version on the targeting pack. -->
-    <SkipValidateAssemblyVersion>true</SkipValidateAssemblyVersion>
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
     <SupportedOSPlatforms>windows</SupportedOSPlatforms>
   </PropertyGroup>
diff --git a/src/libraries/System.DirectoryServices/Directory.Build.targets b/src/libraries/System.DirectoryServices/Directory.Build.targets
new file mode 100644 (file)
index 0000000..fca3b1f
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly 
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index bfa544c..709a22a 100644 (file)
@@ -1,10 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
     <SupportedOSPlatforms>windows</SupportedOSPlatforms>
   </PropertyGroup>
diff --git a/src/libraries/System.Management/Directory.Build.targets b/src/libraries/System.Management/Directory.Build.targets
new file mode 100644 (file)
index 0000000..1cdbd69
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index ed15ad0..798ccfd 100644 (file)
@@ -1,7 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <AssemblyVersion>4.0.3.0</AssemblyVersion>
     <StrongNameKeyId>ECMA</StrongNameKeyId>
   </PropertyGroup>
 </Project>
diff --git a/src/libraries/System.Reflection.Context/Directory.Build.targets b/src/libraries/System.Reflection.Context/Directory.Build.targets
new file mode 100644 (file)
index 0000000..00afa2a
--- /dev/null
@@ -0,0 +1,9 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly 
+         remains <= the .NETFramework version.
+         4.0.3.0 breaks this causing https://github.com/dotnet/runtime/issues/84320  -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.3.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index 33a308c..bdca689 100644 (file)
@@ -1,9 +1,5 @@
 <Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum);netstandard2.1;netstandard2.0</TargetFrameworks>
   </PropertyGroup>
 
index 30af695..d68d22c 100644 (file)
@@ -1,10 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>Microsoft</StrongNameKeyId>
     <IncludePlatformAttributes>true</IncludePlatformAttributes>
   </PropertyGroup>
diff --git a/src/libraries/System.Runtime.Caching/Directory.Build.targets b/src/libraries/System.Runtime.Caching/Directory.Build.targets
new file mode 100644 (file)
index 0000000..1cdbd69
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>
index db2f816..d43c87c 100644 (file)
@@ -1,10 +1,6 @@
 <Project>
   <Import Project="..\Directory.Build.props" />
   <PropertyGroup>
-    <!-- this assembly is inbox in desktop, do not version it unless you
-         plan on shipping a new desktop version out of band. Instead add API
-         to a different assembly. -->
-    <AssemblyVersion>4.0.0.0</AssemblyVersion>
     <StrongNameKeyId>MicrosoftShared</StrongNameKeyId>
     <SupportedOSPlatforms>windows</SupportedOSPlatforms>
   </PropertyGroup>
diff --git a/src/libraries/System.Speech/Directory.Build.targets b/src/libraries/System.Speech/Directory.Build.targets
new file mode 100644 (file)
index 0000000..1cdbd69
--- /dev/null
@@ -0,0 +1,8 @@
+<Project>
+  <Import Project="..\Directory.Build.targets" />
+  <PropertyGroup>
+    <!-- This assembly is inbox in .NETFramework, ensure that the .NETStandard assembly
+         remains <= the .NETFramework version -->
+    <AssemblyVersion Condition="'$(TargetFramework)' == 'netstandard2.0'">4.0.0.0</AssemblyVersion>
+  </PropertyGroup>
+</Project>