Skip to content

Commit f2fa057

Browse files
authored
Build the shim assemblies as part of libs.sfx (#89005)
* Build the shim assemblies as part of libs.sfx The shims build was intentionally kept out of the libs.sfx subset as some shims reference out-of-band assemblies that also need to be built. Since that change was made, the shim assemblies now don't reference all out-of-band assemblies by default anymore and instead use fine grained dependencies. Because of that, the number of out-of-band projects referenced and built as part of the shims build is much smaller (~10 projects). This fixes issues with ouf-of-band source generators not being able to target the live targeting pack. These source generators need the shims (more precisely the netstandard.dll shims) as some of the referenced Microsoft.CodeAnalysis packages don't provide a .NETCoreApp assembly. * Add fake assemblies for out-of-band type forward destinations * Fix issues with nested classes and wrong type destinations * Disable binplacing * Make stubs private * Disable symbols for stubs * Add build protection to validate API compatibility of shims
1 parent 0fce03e commit f2fa057

File tree

51 files changed

+1345
-172
lines changed

Some content is hidden

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

51 files changed

+1345
-172
lines changed

src/libraries/Directory.Build.targets

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@
111111
<Import Project="$(RepositoryEngineeringDir)targetingpacks.targets" />
112112

113113
<PropertyGroup>
114-
<!-- Libraries non test projects shouldn't reference compat shims. -->
114+
<!-- Libraries ref and source projects which don't bring in dependencies from outside the repository shouldn't reference compat shims. -->
115115
<SkipTargetingPackShimReferences Condition="'$(UseLocalTargetingRuntimePack)' == 'true' and
116116
'$(IsTestProject)' != 'true' and
117-
'$(IsTestSupportProject)' != 'true'">true</SkipTargetingPackShimReferences>
117+
'$(IsTestSupportProject)' != 'true' and
118+
'$(IsGeneratorProject)' != 'true'">true</SkipTargetingPackShimReferences>
118119
</PropertyGroup>
119120

120121
<Import Project="$(RepositoryEngineeringDir)codeOptimization.targets" />
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
23
<PropertyGroup>
34
<TargetFrameworks>$(NetCoreAppCurrent);$(NetCoreAppPrevious);$(NetCoreAppMinimum)</TargetFrameworks>
5+
<SkipValidateReferenceAssemblyProjectReferences>true</SkipValidateReferenceAssemblyProjectReferences>
46
</PropertyGroup>
57

68
<ItemGroup>
@@ -9,7 +11,8 @@
911
</ItemGroup>
1012

1113
<ItemGroup>
12-
<!-- Avoid a PackageReference to System.Drawing.Common this reference is only needed for TypeForwards -->
13-
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonVersion)" PrivateAssets="All" />
14+
<!-- Avoid a product dependency to System.Drawing.Common, this reference is only needed for TypeForwards -->
15+
<ProjectReference Include="$(LibrariesProjectRoot)shims\stubs\System.Drawing.Common.csproj" PrivateAssets="all" />
1416
</ItemGroup>
17+
1518
</Project>

src/libraries/System.Windows.Extensions/src/System.Windows.Extensions.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2+
23
<PropertyGroup>
34
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)</TargetFrameworks>
45
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -93,7 +94,8 @@ System.Security.Cryptography.X509Certificates.X509SelectionFlag</PackageDescript
9394
</ItemGroup>
9495

9596
<ItemGroup>
96-
<!-- Avoid a PackageReference to System.Drawing.Common this reference is only needed for TypeForwards -->
97-
<PackageReference Include="System.Drawing.Common" Version="$(SystemDrawingCommonVersion)" PrivateAssets="All" />
97+
<!-- Avoid a product dependency to System.Drawing.Common, this reference is only needed for TypeForwards -->
98+
<ProjectReference Include="$(LibrariesProjectRoot)shims\stubs\System.Drawing.Common.csproj" PrivateAssets="all" />
9899
</ItemGroup>
100+
99101
</Project>

src/libraries/apicompat/ApiCompat.proj

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
<!-- For API comparison, ApiCompat needs the inbox assemblies (including shims) and to resolve type forwards, the out-of-band assemblies. -->
3434
<ItemGroup>
3535
<ProjectReference Include="..\sfx-src.proj" OutputItemType="SharedFrameworkAssembly" />
36-
<ProjectReference Include="..\shims.proj" OutputItemType="SharedFrameworkAssembly" />
3736
<ProjectReference Include="..\oob-src.proj" OutputItemType="OOBAssembly" />
3837
</ItemGroup>
3938

@@ -42,18 +41,52 @@
4241
<PackageDownload Include="NETStandard.Library.Ref" Version="[$(NETStandardLibraryRefVersion)]" />
4342
<PackageDownload Include="NETStandard.Library" Version="[$(NetStandardLibraryVersion)]" />
4443
<PackageReference Include="Microsoft.DotNet.ApiCompat.Task" Version="$(MicrosoftDotNetApiCompatTaskVersion)" IsImplicitlyDefined="true" />
44+
45+
<!-- Restore and reference assemblies not built in runtime anymore, required for resolving type forward on both comparison sides. -->
46+
<ApiCompatTypeForwardDestinationPackage Include="System.Data.SqlClient" PackageVersion="$(SystemDataSqlClientVersion)" TargetFramework="netcoreapp2.1" />
47+
<ApiCompatTypeForwardDestinationPackage Include="System.Drawing.Common" PackageVersion="$(SystemDrawingCommonVersion)" TargetFramework="net7.0" />
48+
49+
<!-- Restore and reference assemblies required for resolving type forwards on the baseline (left) side. -->
50+
<ApiCompatLeftTypeForwardDestinationPackage Include="@(ApiCompatTypeForwardDestinationPackage)" />
51+
<ApiCompatLeftTypeForwardDestinationPackage
52+
Include="
53+
Microsoft.Win32.SystemEvents;
54+
System.CodeDom;
55+
System.Configuration.ConfigurationManager;
56+
System.Data.Odbc;
57+
System.Data.OleDb;
58+
System.Diagnostics.EventLog;
59+
System.Diagnostics.PerformanceCounter;
60+
System.IO.Packaging;
61+
System.IO.Ports;
62+
System.Runtime.Serialization.Schema;
63+
System.Security.Cryptography.Pkcs;
64+
System.Security.Cryptography.ProtectedData;
65+
System.Security.Cryptography.Xml;
66+
System.Security.Permissions;
67+
System.ServiceModel.Syndication;
68+
System.ServiceProcess.ServiceController;
69+
System.Threading.AccessControl;
70+
System.Windows.Extensions"
71+
PackageVersion="$(ApiCompatNetCoreAppBaselineVersion)"
72+
TargetFramework="$(ApiCompatNetCoreAppBaselineTFM)" />
73+
<PackageDownload Include="@(ApiCompatLeftTypeForwardDestinationPackage)" Version="[%(PackageVersion)]" />
4574
</ItemGroup>
4675

4776
<Target Name="RunApiCompat"
4877
DependsOnTargets="FindReferenceAssembliesForReferences;CollectApiCompatInputs"
4978
AfterTargets="Build"
50-
Inputs="@(ReferencePathWithRefAssemblies);$(ApiCompatNetStandard20BaselineFile);$(ApiCompatNetStandard21BaselineFile);$(ApiCompatNetCoreAppLatestStableBaselineFile);@(ApiCompatExcludeAttributesFile)"
79+
Inputs="$(MSBuildThisFileFullPath);@(ReferencePathWithRefAssemblies);$(ApiCompatNetStandard20BaselineFile);$(ApiCompatNetStandard21BaselineFile);$(ApiCompatNetCoreAppLatestStableBaselineFile);@(ApiCompatExcludeAttributesFile)"
5180
Outputs="$(IntermediateOutputPath)$(TargetArchitecture)-marker.txt">
5281
<Message Text="ApiCompat -> Comparing $(NetCoreAppCurrent) reference assemblies against .NETStandard 2.x and .NETCoreApp $(ApiCompatNetCoreAppBaselineVersion)..." Importance="high" />
5382

5483
<ItemGroup>
84+
<ApiCompatNetCoreAppLatestStableAssemblyReference Include="@(ApiCompatLeftTypeForwardDestinationPackage->'$(NuGetPackageRoot)$([System.String]::new('%(ApiCompatLeftTypeForwardDestinationPackage.Identity)').ToLowerInvariant())\%(ApiCompatLeftTypeForwardDestinationPackage.PackageVersion)\lib\%(ApiCompatLeftTypeForwardDestinationPackage.TargetFramework)\%(ApiCompatLeftTypeForwardDestinationPackage.Identity).dll')" />
85+
5586
<ApiCompatRightAssembly Include="@(ReferencePathWithRefAssemblies->WithMetadataValue('IsPrivateAssembly', 'false')->WithMetadataValue('OutputItemType', 'SharedFrameworkAssembly'))" />
56-
<ApiCompatRightAssemblyReference Include="@(ReferencePathWithRefAssemblies->WithMetadataValue('IsPrivateAssembly', 'false')->WithMetadataValue('OutputItemType', 'OOBAssembly'), ',')" />
87+
<ApiCompatRightAssemblyReferenceFromPackage Include="@(ApiCompatTypeForwardDestinationPackage->'$(NuGetPackageRoot)$([System.String]::new('%(ApiCompatTypeForwardDestinationPackage.Identity)').ToLowerInvariant())\%(ApiCompatTypeForwardDestinationPackage.PackageVersion)\lib\%(ApiCompatTypeForwardDestinationPackage.TargetFramework)\%(ApiCompatTypeForwardDestinationPackage.Identity).dll')" />
88+
<ApiCompatRightAssemblyReference Include="@(ReferencePathWithRefAssemblies->WithMetadataValue('IsPrivateAssembly', 'false')->WithMetadataValue('OutputItemType', 'OOBAssembly'));
89+
@(ApiCompatRightAssemblyReferenceFromPackage)" />
5790
</ItemGroup>
5891

5992
<!-- ApiCompat: NetCoreAppCurrent <-> .NETCoreApp ApiCompatNetCoreAppBaselineVersion -->
@@ -68,7 +101,8 @@
68101
ExcludeAttributesFiles="@(ApiCompatExcludeAttributesFile)"
69102
LeftAssembliesTransformationPattern="@(ApiCompatNetCoreAppLatestStableLeftAssembliesTransformationPattern)"
70103
RightAssembliesTransformationPattern="@(ApiCompatNetCoreAppCurrentRightAssembliesTransformationPattern)"
71-
RightAssembliesReferences="@(ApiCompatRightAssemblyReference)" />
104+
LeftAssembliesReferences="@(ApiCompatNetCoreAppLatestStableAssemblyReference, ',')"
105+
RightAssembliesReferences="@(ApiCompatRightAssemblyReference, ',')" />
72106

73107
<!-- ApiCompat: NetCoreAppCurrent <-> netstandard2.1 -->
74108
<Microsoft.DotNet.ApiCompat.Task.ValidateAssembliesTask
@@ -81,7 +115,7 @@
81115
ExcludeAttributesFiles="@(ApiCompatExcludeAttributesFile)"
82116
LeftAssembliesTransformationPattern="@(ApiCompatNetStandard21LeftAssembliesTransformationPattern)"
83117
RightAssembliesTransformationPattern="@(ApiCompatNetCoreAppCurrentRightAssembliesTransformationPattern)"
84-
RightAssembliesReferences="@(ApiCompatRightAssemblyReference)" />
118+
RightAssembliesReferences="@(ApiCompatRightAssemblyReference, ',')" />
85119

86120
<!-- ApiCompat: NetCoreAppCurrent <-> netstandard2.0 -->
87121
<Microsoft.DotNet.ApiCompat.Task.ValidateAssembliesTask
@@ -94,7 +128,7 @@
94128
ExcludeAttributesFiles="@(ApiCompatExcludeAttributesFile)"
95129
LeftAssembliesTransformationPattern="@(ApiCompatNetStandard20LeftAssembliesTransformationPattern)"
96130
RightAssembliesTransformationPattern="@(ApiCompatNetCoreAppCurrentRightAssembliesTransformationPattern)"
97-
RightAssembliesReferences="@(ApiCompatRightAssemblyReference)" />
131+
RightAssembliesReferences="@(ApiCompatRightAssemblyReference, ',')" />
98132

99133
<!-- Create a marker file which serves as the target's output to enable incremental builds. -->
100134
<Touch Files="$(IntermediateOutputPath)$(TargetArchitecture)-marker.txt"

src/libraries/frameworklist.targets

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/libraries/oob.proj

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
</PropertyGroup>
88

99
<ItemGroup Condition="'$(BuildTargetFramework)' == '$(NetCoreAppCurrent)' or '$(BuildTargetFramework)' == ''">
10-
<ProjectReference Include="sfx-gen.proj" OutputItemType="SharedFrameworkAnalyzerAssembly" />
1110
<ProjectReference Include="sfx-src.proj" OutputItemType="SharedFrameworkAssembly" />
1211
<ProjectReference Include="oob-src.proj" OutputItemType="OOBAssembly" />
13-
<ProjectReference Include="shims.proj" OutputItemType="SharedFrameworkAssembly" />
1412

1513
<ProjectReference Include="apicompat\ApiCompat.proj"
1614
Condition="'$(DotNetBuildFromSource)' != 'true' and '$(ApiCompatValidateAssemblies)' != 'false'" />
@@ -23,15 +21,11 @@
2321
<!-- Support building reference projects only. -->
2422
<ItemGroup Condition="'$(RefOnly)' == 'true'">
2523
<ProjectReference Remove="@(ProjectReference)" />
26-
<ProjectReference Include="sfx-gen.proj" OutputItemType="SharedFrameworkAnalyzerAssembly" />
2724
<ProjectReference Include="sfx-ref.proj" OutputItemType="SharedFrameworkAssembly" />
2825
<ProjectReference Include="oob-ref.proj" />
29-
<ProjectReference Include="shims.proj" OutputItemType="SharedFrameworkAssembly" />
3026
</ItemGroup>
3127

3228
<ImportGroup Condition="'$(BuildTargetFramework)' == '$(NetCoreAppCurrent)' or '$(BuildTargetFramework)' == ''">
33-
<!-- Re-generate the targeting pack's framework list to include shims. -->
34-
<Import Project="frameworklist.targets" />
3529
<!-- Import the illink file which contains some of the logic required to illink the out-of-band assemblies. -->
3630
<Import Project="$(RepositoryEngineeringDir)illink.targets" />
3731
</ImportGroup>

src/libraries/sfx-ref.proj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@
1717
System.Private.CoreLib\ref\System.Private.CoreLib.csproj" />
1818
</ItemGroup>
1919

20+
<ItemGroup Condition="'$(RefOnly)' == 'true'">
21+
<ProjectReference Include="shims\*\src\*.csproj" />
22+
<ReferenceShimProject Include="shims\*\ref\*.csproj" />
23+
<ProjectReference Include="@(ReferenceShimProject)" />
24+
<!-- Omit projects which depend on source projects to be built. -->
25+
<ProjectReference Remove="@(ReferenceShimProject->'shims\%(Filename)\src\%(Filename)%(Extension)')" />
26+
</ItemGroup>
27+
2028
</Project>

src/libraries/sfx-src.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
Exclude="@(NetCoreAppLibrary->'%(Identity)\src\%(Identity).csproj');
1616
Microsoft.VisualBasic.Core\src\Microsoft.VisualBasic.Core.vbproj" />
1717
<ProjectReference Include="@(AnyProject);
18-
$(CoreLibProject)"
18+
$(CoreLibProject);
19+
shims\*\src\*.csproj"
1920
Exclude="@(NonNetCoreAppProject)" />
2021
</ItemGroup>
2122

src/libraries/sfx.proj

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
<Project Sdk="Microsoft.Build.NoTargets">
22

3+
<Sdk Name="Microsoft.DotNet.SharedFramework.Sdk" />
4+
35
<PropertyGroup>
46
<TargetFramework>$(NetCoreAppCurrent)-$(TargetOS)</TargetFramework>
57
<BuildInParallel>false</BuildInParallel>
8+
<IsPackable>false</IsPackable>
9+
<FrameworkListOutputPath>$(MicrosoftNetCoreAppRefPackDataDir)FrameworkList.xml</FrameworkListOutputPath>
610
</PropertyGroup>
711

812
<ItemGroup>
@@ -11,16 +15,47 @@
1115
<ProjectReference Include="sfx-ref.proj">
1216
<OutputItemType Condition="'$(RefOnly)' == 'true'">SharedFrameworkAssembly</OutputItemType>
1317
</ProjectReference>
18+
<!-- The RefOnly condition exists to support building the reference source projects only. -->
19+
<ProjectReference Include="sfx-src.proj" OutputItemType="SharedFrameworkAssembly" Condition="'$(RefOnly)' != 'true'" />
1420
<ProjectReference Include="sfx-gen.proj" OutputItemType="SharedFrameworkAnalyzerAssembly" />
1521
</ItemGroup>
1622

17-
<!-- Support building only the reference assemblies. -->
18-
<ItemGroup Condition="'$(RefOnly)' != 'true'">
19-
<ProjectReference Include="sfx-src.proj" OutputItemType="SharedFrameworkAssembly" />
20-
</ItemGroup>
23+
<Target Name="GetGenerateFrameworkListFileInputs">
24+
<Error Text="Shared framework assemblies must be built before the framework list can be generated."
25+
Condition="'@(SharedFrameworkAssembly)' == '' or '@(SharedFrameworkAnalyzerAssembly)' == ''" />
26+
27+
<ItemGroup>
28+
<SharedFrameworkAssemblyWithReferenceAssembly Include="@(SharedFrameworkAssembly->WithMetadataValue('IsPrivateAssembly', 'false')->HasMetadata('ReferenceAssembly'))" />
29+
<SharedFrameworkAssemblyWithoutReferenceAssembly Include="@(SharedFrameworkAssembly->WithMetadataValue('IsPrivateAssembly', 'false'))"
30+
Exclude="@(SharedFrameworkAssemblyWithReferenceAssembly)" />
31+
32+
<FrameworkListInputFile Include="@(SharedFrameworkAssemblyWithReferenceAssembly->Metadata('ReferenceAssembly'));
33+
@(SharedFrameworkAssemblyWithoutReferenceAssembly)"
34+
TargetPath="ref/$(NetCoreAppCurrent)" />
35+
<FrameworkListInputFile Include="@(SharedFrameworkAnalyzerAssembly)"
36+
TargetPath="%(SharedFrameworkAnalyzerAssembly.GeneratorProjectBaseTargetPath)" />
37+
</ItemGroup>
38+
</Target>
2139

2240
<!-- Generate the targeting pack's framework list so that out-of-band projects can leverage it. -->
23-
<Import Project="frameworklist.targets" />
41+
<UsingTask TaskName="CreateFrameworkListFile" AssemblyFile="$(DotNetSharedFrameworkTaskFile)"/>
42+
<Target Name="GenerateFrameworkListFile"
43+
DependsOnTargets="GetGenerateFrameworkListFileInputs"
44+
AfterTargets="Build"
45+
Inputs="@(FrameworkListInputFile)"
46+
Outputs="$(FrameworkListOutputPath)">
47+
<ItemGroup>
48+
<FrameworkListRootAttribute Include="Name" Value="$(NetCoreAppCurrentBrandName)" />
49+
<FrameworkListRootAttribute Include="TargetFrameworkIdentifier" Value="$(NetCoreAppCurrentIdentifier)" />
50+
<FrameworkListRootAttribute Include="TargetFrameworkVersion" Value="$(NetCoreAppCurrentVersion)" />
51+
<FrameworkListRootAttribute Include="FrameworkName" Value="$(MicrosoftNetCoreAppFrameworkName)" />
52+
</ItemGroup>
53+
54+
<CreateFrameworkListFile Files="@(FrameworkListInputFile)"
55+
TargetFile="$(FrameworkListOutputPath)"
56+
TargetFilePrefixes="ref/;runtimes/;analyzers/"
57+
RootAttributes="@(FrameworkListRootAttribute)" />
58+
</Target>
2459

2560
<!-- Copy the intellisense file to the targeting pack directory. -->
2661
<Target Name="CopyDocumentationFiles"

src/libraries/shims.proj

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)