Skip to content

Commit

Permalink
P2P instead of binplacing aspnetcore transport pkg (dotnet#57239)
Browse files Browse the repository at this point in the history
Use ProjectReferences to compose the aspnetcore tranport package.
Avoid binplacing and with that unnecessary copies which overall
simplifies the infrastructure and allows to add additional transport
packages without creating a binplace configuration for each.

This also makes sure that the dependencies are compatible with the
package's tfm.
  • Loading branch information
ViktorHofer authored Aug 12, 2021
1 parent b2d5d63 commit 21e340d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
4 changes: 2 additions & 2 deletions docs/coding-guidelines/libraries-packaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ Transport packages are non-shipping packages that dotnet/runtime produces in ord

This package represents the set of libraries which are produced in dotnet/runtime and ship in the ASP.NETCore shared framework. We produce a transport package so that we can easily share reference assemblies and implementation configurations that might not be present in NuGet packages that also ship.

To add a library to the ASP.NETCore shared framework, that library should set the `IsAspNetCoreApp` property for its `ref` and `src` project. This is typically done in the library's `Directory.Build.props`, for example https://github.com/dotnet/runtime/blob/98ac23212e6017c615e7e855e676fc43c8e44cb8/src/libraries/Microsoft.Extensions.Logging.Abstractions/Directory.Build.props#L4.
To add a library to the ASP.NETCore shared framework, that library should be listed in the `AspNetCoreAppLibrary` section in `NetCoreAppLibrary.props`.

Source generators and analyzers can be included in the ASP.NETCore shared framework by specifying `IsAspNetCoreAppAnalyzer`. These projects should specify `AnalyzerLanguage` as mentioned [below](#analyzers--source-generators).
Source generators and analyzers can be included in the ASP.NETCore shared framework by adding them to the `Microsoft.AspNetCore.Internal.Transport.proj` as an AnalyzerReference. These projects should specify `AnalyzerLanguage` as mentioned [below](#analyzers--source-generators).

Libraries included in this transport package should ensure all direct and transitive assembly references are also included in either the ASP.NETCore shared framework or the .NETCore shared framework. This is not validated in dotnet/runtime at the moment: https://github.com/dotnet/runtime/issues/52562

Expand Down
29 changes: 28 additions & 1 deletion eng/packaging.targets
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackDependsOn>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(PackDependsOn)</PackDependsOn>
<BeforePack>AddNETStandardCompatErrorFileForPackaging;IncludeAnalyzersInPackage;$(BeforePack)</BeforePack>
<SymbolPackageOutputPath>$(PackageOutputPath)</SymbolPackageOutputPath>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddRuntimeSpecificFilesToPackage</TargetsForTfmSpecificContentInPackage>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);AddRuntimeSpecificFilesToPackage;IncludePrivateProjectReferencesWithPackAttributeInPackage</TargetsForTfmSpecificContentInPackage>
<TargetsForTfmSpecificDebugSymbolsInPackage>$(TargetsForTfmSpecificDebugSymbolsInPackage);AddRuntimeSpecificSymbolToPackage</TargetsForTfmSpecificDebugSymbolsInPackage>
<IncludeBuildOutput Condition="'$(TargetsAnyOS)' != 'true' or '$(ExcludeFromPackage)' == 'true'">false</IncludeBuildOutput>
<!-- Don't include target platform specific dependencies, since we use the target platform to represent RIDs instead -->
Expand Down Expand Up @@ -202,4 +202,31 @@
</ItemGroup>
</Target>

<Target Name="IncludePrivateProjectReferencesWithPackAttributeInPackage"
Condition="'@(ProjectReference->WithMetadataValue('PrivateAssets', 'all')->WithMetadataValue('Pack', 'true'))' != ''"
DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<_projectReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'all')->WithMetadataValue('Pack', 'true'))" />
<TfmSpecificPackageFile Include="@(_projectReferenceCopyLocalPaths)"
PackagePath="$([MSBuild]::ValueOrDefault('%(ReferenceCopyLocalPaths.PackagePath)', '$(BuildOutputTargetFolder)/$(TargetFramework)'))" />
<TfmSpecificDebugSymbolsFile Include="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))"
TargetPath="/%(TfmSpecificPackageFile.PackagePath)/%(Filename)%(Extension)"
TargetFramework="$(TargetFramework)"
Condition="'$(IncludeSymbols)' == 'true'" />
<!-- Remove symbols from the non symbol package. -->
<TfmSpecificPackageFile Remove="@(TfmSpecificPackageFile->WithMetadataValue('Extension', '.pdb'))" />
</ItemGroup>

<ItemGroup>
<_referenceAssemblyPaths Include="@(_projectReferenceCopyLocalPaths->WithMetadataValue('Extension', '.dll')->WithMetadataValue('IncludeReferenceAssemblyInPackage', 'true')->Metadata('ReferenceAssembly'))" />
<TfmSpecificPackageFile Include="@(_referenceAssemblyPaths)"
PackagePath="ref/$(TargetFramework)" />
<_referenceSymbolPaths Include="$([System.IO.Path]::ChangeExtension('%(_referenceAssemblyPaths.Identity)', '.pdb'))" />
<TfmSpecificDebugSymbolsFile Include="@(_referenceSymbolPaths->Exists())"
TargetPath="/ref/$(TargetFramework)/%(Filename)%(Extension)"
TargetFramework="$(TargetFramework)"
Condition="'$(IncludeSymbols)' == 'true'" />
</ItemGroup>
</Target>

</Project>
4 changes: 0 additions & 4 deletions src/libraries/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@
<NetCoreAppCurrentRefPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'ref', '$(NetCoreAppCurrent)'))</NetCoreAppCurrentRefPath>
<NetCoreAppCurrentRuntimePath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'runtime', '$(NetCoreAppCurrent)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)'))</NetCoreAppCurrentRuntimePath>

<ASPNETCoreAppPackageRootPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'pkg', 'aspnetcoreapp'))</ASPNETCoreAppPackageRootPath>
<ASPNETCoreAppPackageRefPath>$([MSBuild]::NormalizeDirectory('$(ASPNETCoreAppPackageRootPath)', 'ref'))</ASPNETCoreAppPackageRefPath>
<ASPNETCoreAppPackageRuntimePath>$([MSBuild]::NormalizeDirectory('$(ASPNETCoreAppPackageRootPath)', 'lib'))</ASPNETCoreAppPackageRuntimePath>

<CommonPathRoot>$([MSBuild]::NormalizeDirectory('$(LibrariesProjectRoot)', 'Common'))</CommonPathRoot>
<CommonPath>$([MSBuild]::NormalizeDirectory('$(CommonPathRoot)', 'src'))</CommonPath>
<CommonTestPath>$([MSBuild]::NormalizeDirectory('$(CommonPathRoot)', 'tests'))</CommonTestPath>
Expand Down
7 changes: 0 additions & 7 deletions src/libraries/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,6 @@
'$(BinPlaceRuntime)' == 'true' and
'$(ILLinkTrimAssembly)' == ''">ILLinkTrimAssembly=true</SetProperties>
</BinPlaceTargetFrameworks>
<BinPlaceTargetFrameworks Include="$(NetCoreAppCurrent)"
Condition="'$(IsAspNetCoreApp)' == 'true'">
<RuntimePath>$(ASPNETCoreAppPackageRuntimePath)</RuntimePath>
<RefPath>$(ASPNETCoreAppPackageRefPath)</RefPath>
</BinPlaceTargetFrameworks>
<BinPlaceDir Include="$(ASPNETCoreAppPackageRootPath)\analyzers\dotnet\$(AnalyzerLanguage)"
Condition="'$(IsAspNetCoreAppAnalyzer)' == 'true'" />
<BinPlaceDir Include="$(MicrosoftNetCoreAppRefPackDir)analyzers\dotnet\$(AnalyzerLanguage)"
Condition="'$(IsNETCoreAppAnalyzer)' == 'true'" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,20 @@
<!-- Reference the outputs to have them available as build outputs. -->
<NoTargetsDoNotReferenceOutputAssemblies>false</NoTargetsDoNotReferenceOutputAssemblies>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>true</IncludeBuildOutput>
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<!-- This is non-shipping package. -->
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
<PackageDescription>Internal transport package to provide aspnetcore with the assemblies that make up the Microsoft.ASPNetCore.App shared framework.</PackageDescription>
<!-- NU5131: Reference elements are missing from the nuspec: https://github.com/NuGet/Home/issues/8684.
NU5128: Don't list dependencies as this is a mega and not meta package. -->
<NoWarn>$(NoWarn);NU5131;NU5128</NoWarn>
<!-- Reference elements are missing from the nuspec: https://github.com/NuGet/Home/issues/8684. -->
<NoWarn>$(NoWarn);NU5131</NoWarn>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="@(AspNetCoreAppLibrary->'$(LibrariesProjectRoot)%(Identity)\src\%(Identity).csproj')" />
</ItemGroup>

<ItemGroup>
<_analyzer Include="$(ASPNETCoreAppPackageRootPath)\analyzers\**\*.*" />
<_libDoc Include="$(ASPNETCoreAppPackageRuntimePath)\*.xml" />

<Content Include="@(_analyzer)"
Pack="true"
PackagePath="analyzers" />
<Content Include="$(ASPNETCoreAppPackageRefPath)\*.*;
@(_libDoc)"
Pack="true"
PackagePath="ref\$(NetCoreAppCurrent)" />
<Content Include="$(ASPNETCoreAppPackageRuntimePath)\*.*"
Exclude="@(_libDoc)"
Pack="true"
PackagePath="lib\$(NetCoreAppCurrent)" />
<!-- Requires Private=true to calculate ReferenceCopyLocalPaths items. -->
<ProjectReference Include="@(AspNetCoreAppLibrary->'$(LibrariesProjectRoot)%(Identity)\src\%(Identity).csproj')" PrivateAssets="all" Pack="true" Private="true" IncludeReferenceAssemblyInPackage="true" />
<!-- TODO: Find a better way to include source generators without hardcoding them. -->
<AnalyzerReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.Logging.Abstractions\gen\Microsoft.Extensions.Logging.Generators.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
<UsingToolXliff>true</UsingToolXliff>
<CLSCompliant>false</CLSCompliant>
<IsPackable>false</IsPackable>
<IsAspNetCoreAppAnalyzer>true</IsAspNetCoreAppAnalyzer>
<AnalyzerLanguage>cs</AnalyzerLanguage>
</PropertyGroup>

Expand Down

0 comments on commit 21e340d

Please sign in to comment.