Skip to content

Commit c53d44f

Browse files
committed
Refactor shims and use P2Ps in netstandard.csproj
Simplify the shims msbuild files now that ApiCompat.proj isn't part of the shims directory. Change netstandard.csproj from a generated project to a "normal" one and make it reference its dependencies via ProjectReferences.
1 parent 9cc9d35 commit c53d44f

48 files changed

Lines changed: 549 additions & 514 deletions

Some content is hidden

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

Directory.Build.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,5 +305,6 @@
305305
<PropertyGroup>
306306
<CustomBeforeNoTargets>$(RepositoryEngineeringDir)NoTargetsSdk.BeforeTargets.targets</CustomBeforeNoTargets>
307307
<CustomAfterTraversalProps>$(RepositoryEngineeringDir)TraversalSdk.AfterProps.props</CustomAfterTraversalProps>
308+
<CustomAfterTraversalTargets>$(RepositoryEngineeringDir)TraversalSdk.AfterTargets.targets</CustomAfterTraversalTargets>
308309
</PropertyGroup>
309310
</Project>

docs/coding-guidelines/project-guidelines.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@ In order to work in the dotnet/runtime repo you must first run build.cmd/sh from
66
- Restore tools
77
- Restore external dependencies
88
- CoreCLR - Copy to `bin\runtime\$(BuildTargetFramework)-$(TargetOS)-$(Configuration)-$(TargetArchitecture)`
9-
- Build targeting pack
10-
- Build src\libraries\ref.proj which builds all references assembly projects. For reference assembly project information see [ref](#ref)
11-
- Build product
12-
- Build src\libraries\src.proj which builds all the source library projects. For source library project information see [src](#src).
9+
- Build shared framework projects
10+
- Build src\libraries\sfx*.proj which builds all shared framework projects.
11+
- Build out of band projects
12+
- Build src\libraries\oob*.proj which builds all the out-of-band (OOB) projects.
13+
14+
For reference assembly project information see [ref](#ref)
15+
For source library project information see [src](#src)
1316

1417
# Build Pivots
1518
Below is a list of all the various options we pivot the project builds on:
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<!-- NoTargets SDK needs a TFM set. Use the latest .NETCoreApp TFM that is supported by the SDK.
5-
Only set a default if the project isn't multi-targeting. -->
6-
<TargetFramework Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">$(NetCoreAppToolCurrent)</TargetFramework>
4+
<!-- NoTargets SDK needs a TFM set. Set a default if the project doesn't multi target. -->
5+
<TargetFramework Condition="'$(TargetFramework)' == '' and '$(TargetFrameworks)' == ''">$(NetCoreAppCurrent)</TargetFramework>
76
</PropertyGroup>
87

98
</Project>

eng/Subsets.props

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268

269269
<ItemGroup Condition="$(_subset.Contains('+clr.packages+')) and '$(PgoInstrument)' != 'true'">
270270
<ProjectToBuild Include="$(CoreClrProjectRoot).nuget\coreclr-packages.proj" Pack="true" Category="clr" />
271-
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\dotnet-pgo\dotnet-pgo-pack.proj" Pack="true" BuildInParallel="false" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(RuntimeFlavor)' != 'Mono'"/>
271+
<ProjectToBuild Include="$(CoreClrProjectRoot)tools\dotnet-pgo\dotnet-pgo-pack.proj" Pack="true" Category="clr" Condition="'$(DotNetBuildFromSource)' != 'true' and '$(RuntimeFlavor)' != 'Mono'"/>
272272
</ItemGroup>
273273

274274
<ItemGroup Condition="$(_subset.Contains('+clr.nativeaotlibs+')) and '$(NativeAotSupported)' == 'true'">
@@ -302,7 +302,7 @@
302302

303303
<!-- Host sets -->
304304
<ItemGroup Condition="$(_subset.Contains('+host.native+'))">
305-
<CorehostProjectToBuild Include="$(SharedNativeRoot)corehost\corehost.proj" SignPhase="Binaries" BuildInParallel="false" />
305+
<CorehostProjectToBuild Include="$(SharedNativeRoot)corehost\corehost.proj" SignPhase="Binaries" />
306306
<ProjectToBuild Include="@(CorehostProjectToBuild)" Pack="true" Category="host" />
307307
</ItemGroup>
308308

@@ -312,7 +312,7 @@
312312
</ItemGroup>
313313

314314
<ItemGroup Condition="$(_subset.Contains('+host.pkg+')) and '$(PgoInstrument)' != 'true'">
315-
<PkgprojProjectToBuild Include="$(InstallerProjectRoot)pkg\projects\host-packages.proj" SignPhase="MsiFiles" BuildInParallel="false" />
315+
<PkgprojProjectToBuild Include="$(InstallerProjectRoot)pkg\projects\host-packages.proj" SignPhase="MsiFiles" />
316316
<ProjectToBuild Include="@(PkgprojProjectToBuild)" Pack="true" Category="host" />
317317
</ItemGroup>
318318

@@ -321,12 +321,14 @@
321321
<ProjectToBuild Include="$(SharedNativeRoot)libs\build-native.proj" Category="libs" />
322322
</ItemGroup>
323323

324-
<ItemGroup Condition="$(_subset.Contains('+libs.ref+'))">
325-
<ProjectToBuild Include="$(LibrariesProjectRoot)ref.proj" Category="libs" />
326-
</ItemGroup>
327-
328-
<ItemGroup Condition="$(_subset.Contains('+libs.src+'))">
329-
<ProjectToBuild Include="$(LibrariesProjectRoot)src.proj" Category="libs" />
324+
<!-- TODO: Change subsets from libs.ref+libs.src to libs.sfx+libs.oob in the next infra rollout. -->
325+
<ItemGroup Condition="$(_subset.Contains('+libs.ref+')) or $(_subset.Contains('+libs.src+'))">
326+
<ProjectToBuild Include="$(LibrariesProjectRoot)sfx.proj"
327+
Category="libs"
328+
Condition="'$(BuildTargetFramework)' == '$(NetCoreAppCurrent)' or
329+
'$(BuildTargetFramework)' == '' or
330+
'$(BuildAllConfigurations)' == 'true'" />
331+
<ProjectToBuild Include="$(LibrariesProjectRoot)oob.proj" Category="libs" />
330332
</ItemGroup>
331333

332334
<ItemGroup Condition="$(_subset.Contains('+mono.wasmruntime+'))">
@@ -389,12 +391,12 @@
389391
</ItemGroup>
390392

391393
<ItemGroup Condition="$(_subset.Contains('+publish+'))">
392-
<ProjectToBuild Include="$(InstallerProjectRoot)prepare-artifacts.proj" Pack="true" BuildInParallel="false" Category="publish" />
394+
<ProjectToBuild Include="$(InstallerProjectRoot)prepare-artifacts.proj" Pack="true" Category="publish" />
393395
</ItemGroup>
394396

395397
<!-- Utility -->
396398
<ItemGroup Condition="$(_subset.Contains('+regeneratedownloadtable+'))">
397-
<ProjectToBuild Include="$(RepositoryEngineeringDir)regenerate-download-table.proj" Pack="true" BuildInParallel="false" />
399+
<ProjectToBuild Include="$(RepositoryEngineeringDir)regenerate-download-table.proj" Pack="true" />
398400
</ItemGroup>
399401

400402
<!-- Set default configurations. -->

eng/TraversalSdk.AfterProps.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project>
22

33
<PropertyGroup>
4-
<!-- Build for NetCoreAppCurrent by default if no BuildTargetFramework is supplied or if not all configurations are built. -->
5-
<TraversalGlobalProperties Condition="'$(BuildAllConfigurations)' != 'true'">BuildTargetFramework=$([MSBuild]::ValueOrDefault('$(BuildTargetFramework)', '$(NetCoreAppCurrent)'))</TraversalGlobalProperties>
4+
<!-- For consistency default to NetCoreAppCurrent instead of net45, which is the default. -->
5+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
66
</PropertyGroup>
77

88
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<Project>
2+
3+
<!-- Uses the Microsoft.DotNet.Build.Tasks.TargetFramework package to filter out target frameworks from ProjectReferences. -->
4+
<PropertyGroup Condition="'$(FilterTraversalProjectReferences)' == 'true'">
5+
<BuildDependsOn>$(BuildDependsOn);ResolveP2PReferences</BuildDependsOn>
6+
<CleanDependsOn>$(CleanDependsOn);ResolveP2PReferences</CleanDependsOn>
7+
<RebuildDependsOn>$(RebuildDependsOn);ResolveP2PReferences</RebuildDependsOn>
8+
<TestDependsOn>$(TestDependsOn);ResolveP2PReferences</TestDependsOn>
9+
<VSTestDependsOn>$(VSTestDependsOn);ResolveP2PReferences</VSTestDependsOn>
10+
<PackDependsOn>$(PackDependsOn);ResolveP2PReferences</PackDependsOn>
11+
<PublishDependsOn>$(PublishDependsOn);ResolveP2PReferences</PublishDependsOn>
12+
</PropertyGroup>
13+
14+
<ItemGroup Condition="'$(FilterTraversalProjectReferences)' == 'true'">
15+
<ProjectReference Update="@(ProjectReference)" SkipGetTargetFrameworkProperties="false" />
16+
</ItemGroup>
17+
18+
<!--
19+
Traversal projects do not build an assembly so dependent projects shouldn't get a path to the target. Override the GetTargetPath to do nothing.
20+
-->
21+
<Target Name="GetTargetPath" />
22+
23+
</Project>

eng/generators.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<EnabledGenerators Include="DllImportGenerator"
1515
Condition="'$(EnableDllImportGenerator)' == ''
1616
and '$(IsFrameworkSupportFacade)' != 'true'
17-
and '$(IsSourceProject)' == 'true'
17+
and '$(IsRuntimeAssembly)' == 'true'
1818
and '$(MSBuildProjectExtension)' == '.csproj'
1919
and (
2020
('@(Reference)' != ''
@@ -26,7 +26,7 @@
2626
<EnabledGenerators Include="DllImportGenerator"
2727
Condition="'$(EnableDllImportGenerator)' == ''
2828
and '$(IsFrameworkSupportFacade)' != 'true'
29-
and '$(IsSourceProject)' == 'true'
29+
and '$(IsRuntimeAssembly)' == 'true'
3030
and '$(MSBuildProjectExtension)' == '.csproj'
3131
and ('$(TargetFrameworkIdentifier)' == '.NETStandard' or '$(TargetFrameworkIdentifier)' == '.NETFramework' or ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionLessThan($(TargetFrameworkVersion), '$(NetCoreAppCurrentVersion)'))))" />
3232
</ItemGroup>

eng/illink.targets

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,19 @@
217217
</PropertyGroup>
218218
</Target>
219219

220+
<Target Name="PrepareForAssembliesTrim"
221+
DependsOnTargets="SetCommonILLinkArgs">
222+
223+
<!-- When running from Desktop MSBuild, DOTNET_HOST_PATH is not set.
224+
In this case, explicitly specify the path to the dotnet host. -->
225+
<PropertyGroup Condition=" '$(DOTNET_HOST_PATH)' == '' ">
226+
<!-- This is defined when building in Visual Studio. -->
227+
<_DotNetHostDirectory>$(NetCoreRoot)</_DotNetHostDirectory>
228+
<_DotNetHostFileName>$([System.IO.Path]::GetFileName('$(DotNetTool)'))</_DotNetHostFileName>
229+
</PropertyGroup>
230+
231+
</Target>
232+
220233
<!-- ILLinkTrimAssembly
221234
Examines the "input assembly" for IL that is unreachable from public API and trims that,
222235
rewriting the assembly to an "output assembly"

eng/referenceAssemblies.props

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
<Project>
2-
<PropertyGroup Condition="'$(BuildAllProjects)' == 'true' and
3-
!$(BuildTargetFramework.StartsWith('netstandard')) and
4-
!$(BuildTargetFramework.StartsWith('net4'))">
5-
<AdditionalBuildTargetFrameworks>$(AdditionalBuildTargetFrameworks);netstandard2.0;netstandard2.1</AdditionalBuildTargetFrameworks>
62

3+
<PropertyGroup>
74
<!-- Reference assemblies are special and don't initialize fields or have empty finalizers, etc. -->
85
<RunAnalyzers>false</RunAnalyzers>
9-
</PropertyGroup>
106

11-
<PropertyGroup>
127
<!-- disable warnings about unused fields -->
138
<NoWarn>$(NoWarn);CS0169;CS0649;CS8618</NoWarn>
149

@@ -28,4 +23,5 @@
2823
<AssemblyInfoLines Include="[assembly:System.Runtime.CompilerServices.ReferenceAssembly]" />
2924
<AssemblyInfoLines Include="[assembly:System.Reflection.AssemblyFlags((System.Reflection.AssemblyNameFlags)0x70)]" />
3025
</ItemGroup>
26+
3127
</Project>

eng/references.targets

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
</PropertyGroup>
99

1010
<!-- If a CoreLib ProjectReference is present, make all P2P assets non transitive. -->
11-
<ItemGroup Condition="'@(ProjectReference)' != '' and
12-
@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">
13-
<ProjectReference Update="@(ProjectReference)"
11+
<ItemGroup Condition="'$(IsSourceProject)' == 'true' and
12+
'@(ProjectReference)' != '' and
13+
@(ProjectReference->AnyHaveMetadataValue('Identity', '$(CoreLibProject)'))">
14+
<ProjectReference Update="@(ProjectReference->WithMetadataValue('PrivateAssets', ''))"
1415
PrivateAssets="all" />
1516
</ItemGroup>
1617

@@ -55,8 +56,21 @@
5556
</TargetPathWithTargetPlatformMoniker>
5657
</ItemDefinitionGroup>
5758

58-
<Target Name="ValidateReferenceAssemblyProjectReferences" Condition="'$(IsReferenceAssembly)' == 'true'" AfterTargets="ResolveReferences">
59+
<Target Name="ValidateReferenceAssemblyProjectReferences"
60+
Condition="'$(IsReferenceAssembly)' == 'true' and
61+
'$(SkipValidateReferenceAssemblyProjectReferences)' != 'true'"
62+
AfterTargets="ResolveReferences">
5963
<Error Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' AND '%(ReferencePath.IsReferenceAssembly)' != 'true' AND '%(ReferencePath.ReferenceAssembly)' == ''"
6064
Text="Reference assemblies must only reference other reference assemblies and '%(ReferencePath.ProjectReferenceOriginalItemSpec)' is not a reference assembly project and does not set 'ProduceReferenceAssembly'." />
6165
</Target>
66+
67+
<!-- An opt-in target to trim out private assemblies from the ref assembly ReferencePath. -->
68+
<Target Name="TrimOutPrivateAssembliesFromReferencePath"
69+
Condition="'$(CompileUsingReferenceAssemblies)' == 'true'"
70+
AfterTargets="FindReferenceAssembliesForReferences">
71+
<ItemGroup>
72+
<ReferencePathWithRefAssemblies Remove="@(ReferencePathWithRefAssemblies)"
73+
Condition="$(NetCoreAppLibraryNoReference.Contains('%(Filename);'))" />
74+
</ItemGroup>
75+
</Target>
6276
</Project>

0 commit comments

Comments
 (0)