Skip to content

Commit ba80929

Browse files
[release/6.0] Reduce net core app current package dependencies, increase direct update availability (#108797)
* Avoid package dependencies on libraries in the shared framework��We can avoid these dependencies since we can count on the library being part of the shared framework. Fewer dependencies means less packages downloaded, less for customers to service, less copied into the output directory when serviced.��Backport of 6e440de * Enable packages for every project that reduced dependencies * Add an option to enable servicing for transitive dependencies * Permit settting ServiceTransitiveDependencies in projects as well * Add additional packages required for up-stack servicing * Fix indenting Co-authored-by: Carlos Sánchez López <[email protected]> * Bump servicing version for packages that shipped last month --------- Co-authored-by: Carlos Sánchez López <[email protected]>
1 parent d73158c commit ba80929

File tree

59 files changed

+245
-80
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+245
-80
lines changed

docs/coding-guidelines/libraries-packaging.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ Source generators and analyzers can be included in the shared framework by speci
1818

1919
Removing a library from the shared framework is a breaking change and should be avoided.
2020

21+
### References to libraries in the shared framework that produce packages
22+
23+
It's beneficial to avoid project references to libraries that are in the shared framework because it makes the package graph smaller which reduces the number of packages that require servicing and the number of libraries that end up being copied into the application directory.
24+
25+
If a dependency is part of the shared framework a project/package reference is never required on the latest version (`NetCoreAppCurrent`). A reference is required for previous .NET versions even if the dependency is part of the shared framework if the project you are building targets .NETStandard and references the project there. You may completely avoid a package dependency on .NETStandard and .NET if it's not needed for .NETStandard (for example - if it is an implementation only dependency and you're building a PNSE assembly for .NETStandard).
26+
27+
Warning NETPKG0001 is emitted when you have an unnecessary reference to a library that is part of the shared framework. To avoid this warning, make sure your ProjectReference is conditioned so that it doesn't apply on `NetCoreAppCurrent`.
28+
2129
## Transport package
2230

2331
Transport packages are non-shipping packages that dotnet/runtime produces in order to share binaries with other repositories.

docs/project/library-servicing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Additionally, if the library is listed among the project references of [Microsof
1717

1818
When you make a change to a library & ship it during the servicing release, the `ServicingVersion` must be bumped. This property is found in the library's source project. It's also possible that the property is not in that file, in which case you'll need to add it to the library's source project and set it to 1. If the property is already present in your library's source project, just increment the servicing version by 1.
1919

20+
## Optionally ensure all up-stack packages are also produced
21+
22+
If you wish to ensure that every package that references a serviced package is also serviced itself, you can enable validation by setting `ServiceTransitiveDependencies` to true. This can be done in an individual project, or globally. When doing this then building the repo, eg: `build libs -allConfigurations` you'll see errors from any project that didn't enable servicing. Reasons for forcing packages which depend on your package to service are security servicing or removing dependencies.
23+
2024
## Test your changes
2125

2226
All that's left is to ensure that your changes have worked as expected. To do so, execute the following steps:

eng/packaging.targets

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@
183183
</ItemGroup>
184184
</Target>
185185

186+
<Target Name="WarnOnProjectReferenceToFrameworkAssemblies"
187+
BeforeTargets="IncludeTransitiveProjectReferences"
188+
Condition="'$(TargetFramework)' == '$(NetCoreAppCurrent)' and
189+
'@(ProjectReference)' != ''">
190+
<!-- Find project references that overlap with NetCoreApp, are direct (NuGetPackageId is not set), actually referenced (ReferenceOutputAssembly), and not hidden with PrivateAssets
191+
ProjectReferences can opt out of this checking by setting AllowFrameworkPackageReference, though they should not. -->
192+
<Warning Text="Project reference '%(ProjectReference.Identity)' is a reference to a framework assembly and is not required in $(NetCoreAppCurrent) (NetCoreAppCurrent)."
193+
Code="NETPKG0001"
194+
Condition="$(NetCoreAppLibrary.Contains('%(ProjectReference.Filename);')) and
195+
'%(ProjectReference.ReferenceOutputAssembly)' != 'false' and
196+
'%(ProjectReference.NuGetPackageId)' == '' and
197+
'%(ProjectReference.PrivateAssets)' != 'all' and
198+
'%(ProjectReference.AllowFrameworkPackageReference)' != 'true'" />
199+
</Target>
200+
186201
<Target Name="GenerateMultiTargetRoslynComponentTargetsFile"
187202
Inputs="$(MSBuildProjectFullPath);_MultiTargetRoslynComponentTargetsTemplate"
188203
Outputs="$(MultiTargetRoslynComponentTargetsFileIntermediatePath)">
@@ -285,10 +300,46 @@
285300
<Error Condition="'$(AssemblyVersion)' != '$(LastReleasedStableAssemblyVersion)'" Text="AssemblyVersion should match last released assembly version $(LastReleasedStableAssemblyVersion)" />
286301
</Target>
287302

288-
<Target Name="ValidateServicingVersionIsPropertlySet"
289-
Condition="'$(PreReleaseVersionLabel)' == 'servicing' and '$(DotNetBuildFromSource)' != 'true'"
290-
AfterTargets="GenerateNuspec">
291-
<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." />
303+
<ItemDefinitionGroup>
304+
<TargetPathWithTargetPlatformMoniker>
305+
<!-- When ServiceTransitiveDependencies is set, flow the packaging state -->
306+
<GeneratePackageOnBuild Condition="'$(ServiceTransitiveDependencies)' == 'true'">$(GeneratePackageOnBuild)</GeneratePackageOnBuild>
307+
</TargetPathWithTargetPlatformMoniker>
308+
</ItemDefinitionGroup>
309+
310+
<!-- Flows the list of ProjectReferences that are enabled for packaging when building a multi-targeting project -->
311+
<Target Name="_AddTransitiveServicedPackagesToOutput"
312+
AfterTargets="GetTargetPathWithTargetPlatformMoniker"
313+
Condition="'$(IsInnerBuild)' == 'true'">
314+
<PropertyGroup>
315+
<_TransitiveServicedPackages
316+
Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and
317+
'%(ReferencePath.GeneratePackageOnBuild)' == 'true'"
318+
>@(ReferencePath->'%(OriginalProjectReferenceItemSpec)')</_TransitiveServicedPackages>
319+
</PropertyGroup>
320+
<ItemGroup>
321+
<TargetPathWithTargetPlatformMoniker TransitiveServicedPackages="$(_TransitiveServicedPackages)" />
322+
</ItemGroup>
323+
</Target>
324+
325+
<!-- Validate that ServicingVersion is set and packing is enabled. Runs once in the outer build (or only build if no outer build exists). -->
326+
<Target Name="ValidateServicingProperties"
327+
Condition="'$(PreReleaseVersionLabel)' == 'servicing' and
328+
'$(DotNetBuildFromSource)' != 'true' and
329+
'$(IsInnerBuild)' != 'true'"
330+
AfterTargets="Build">
331+
<ItemGroup>
332+
<TransitiveServicedPackages Include="%(InnerOutput.TransitiveServicedPackages)" Condition="'$(IsCrossTargetingBuild)' == 'true'" />
333+
<TransitiveServicedPackages Include="'%(ReferencePath.OriginalProjectReferenceItemSpec)"
334+
Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and
335+
'%(ReferencePath.GeneratePackageOnBuild)' == 'true'" />
336+
</ItemGroup>
337+
<Error Condition="'$(ServicingVersion)' == '0' and '$(GeneratePackageOnBuild)' == 'true'"
338+
Text="ServicingVersion is set to 0 and it should be an increment of the patch version from the last released package." />
339+
340+
<Error Condition="'$(GeneratePackageOnBuild)' != 'true' and
341+
'@(TransitiveServicedPackages)' != ''"
342+
Text="This project did not set GeneratePackageOnBuild, but dependencies '@(TransitiveServicedPackages)' did. Please ship this project by setting GeneratePackageOnBuild to true and incrementing ServicingVersion." />
292343
</Target>
293344

294345
</Project>

src/libraries/Microsoft.Extensions.Caching.Abstractions/src/Microsoft.Extensions.Caching.Abstractions.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
Commonly Used Types:
99
Microsoft.Extensions.Caching.Distributed.IDistributedCache
1010
Microsoft.Extensions.Caching.Memory.IMemoryCache</PackageDescription>
11+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
12+
<ServicingVersion>1</ServicingVersion>
1113
</PropertyGroup>
1214

1315
<ItemGroup>

src/libraries/Microsoft.Extensions.Caching.Memory/src/Microsoft.Extensions.Caching.Memory.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<PackageDescription>In-memory cache implementation of Microsoft.Extensions.Caching.Memory.IMemoryCache.</PackageDescription>
77
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8-
<ServicingVersion>2</ServicingVersion>
8+
<ServicingVersion>3</ServicingVersion>
99
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1010
</PropertyGroup>
1111

src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/Microsoft.Extensions.Configuration.Abstractions.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Microsoft.Extensions.Configuration.IConfigurationBuilder
1111
Microsoft.Extensions.Configuration.IConfigurationProvider
1212
Microsoft.Extensions.Configuration.IConfigurationRoot
1313
Microsoft.Extensions.Configuration.IConfigurationSection</PackageDescription>
14+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
15+
<ServicingVersion>1</ServicingVersion>
1416
</PropertyGroup>
1517

1618
<ItemGroup>

src/libraries/Microsoft.Extensions.Configuration.Binder/src/Microsoft.Extensions.Configuration.Binder.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<PackageDescription>Functionality to bind an object to data in configuration providers for Microsoft.Extensions.Configuration.</PackageDescription>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<ServicingVersion>1</ServicingVersion>
79
</PropertyGroup>
810

911
<ItemGroup>

src/libraries/Microsoft.Extensions.Configuration.CommandLine/src/Microsoft.Extensions.Configuration.CommandLine.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<PackageDescription>Command line configuration provider implementation for Microsoft.Extensions.Configuration.</PackageDescription>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<ServicingVersion>1</ServicingVersion>
79
</PropertyGroup>
810

911
<ItemGroup>

src/libraries/Microsoft.Extensions.Configuration.EnvironmentVariables/src/Microsoft.Extensions.Configuration.EnvironmentVariables.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<PackageDescription>Environment variables configuration provider implementation for Microsoft.Extensions.Configuration.</PackageDescription>
7-
<ServicingVersion>1</ServicingVersion>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<ServicingVersion>2</ServicingVersion>
89
</PropertyGroup>
910

1011
<ItemGroup>

src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/Microsoft.Extensions.Configuration.FileExtensions.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
55
<EnableDefaultItems>true</EnableDefaultItems>
66
<PackageDescription>Extension methods for configuring file-based configuration providers for Microsoft.Extensions.Configuration.</PackageDescription>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
8+
<ServicingVersion>1</ServicingVersion>
79
</PropertyGroup>
810

911
<ItemGroup>

0 commit comments

Comments
 (0)