|
1 | 1 | <Project> |
| 2 | + <!-- |
| 3 | + ##### Contract project settings ##### |
| 4 | + - Allows referencing contract projects for passing matching reference assemblies to tooling like ApiCompat. |
| 5 | + - Allows building against contract assemblies when referencing source projects. |
| 6 | + --> |
| 7 | + |
| 8 | + <PropertyGroup> |
| 9 | + <ContractProject Condition="'$(ContractProject)' == ''">$(LibrariesProjectRoot)$(MSBuildProjectName)\ref\$(MSBuildProjectName).csproj</ContractProject> |
| 10 | + <HasMatchingContract Condition="'$(HasMatchingContract)' == '' and Exists('$(ContractProject)')">true</HasMatchingContract> |
| 11 | + <!-- Don't build against reference assemblies when projects are packable and the tfm is not the latest .NETCoreApp as |
| 12 | + such reference assemblies don't ship to customers and only exist for tooling scenarios. --> |
| 13 | + <AnnotateTargetPathWithContract Condition="'$(AnnotateTargetPathWithContract)' == '' and |
| 14 | + '$(HasMatchingContract)' == 'true' and |
| 15 | + ( |
| 16 | + '$(IsPackable)' != 'true' or |
| 17 | + ( |
| 18 | + '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and |
| 19 | + '$(TargetFrameworkVersion)' == 'v$(NetCoreAppCurrentVersion)' |
| 20 | + ) |
| 21 | + )">true</AnnotateTargetPathWithContract> |
| 22 | + </PropertyGroup> |
| 23 | + |
| 24 | + <ItemGroup Condition="'$(HasMatchingContract)' == 'true' and '$(ContractProject)' != ''"> |
| 25 | + <ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="ResolvedMatchingContract" /> |
| 26 | + <!-- We aren't referencing the contract, but make sure it's considered as an input to Compile so that if it changes we rebuild and rerun API compat --> |
| 27 | + <ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="CustomAdditionalCompileInputs" /> |
| 28 | + </ItemGroup> |
| 29 | + |
| 30 | + <!-- Allow P2Ps that target a source project to build against the corresponding ref project. --> |
| 31 | + <Target Name="AnnotateTargetPathWithTargetPlatformMonikerWithReferenceAssembly" |
| 32 | + Condition="'$(AnnotateTargetPathWithContract)' == 'true'" |
| 33 | + DependsOnTargets="ResolveProjectReferences" |
| 34 | + AfterTargets="GetTargetPathWithTargetPlatformMoniker"> |
| 35 | + <ItemGroup> |
| 36 | + <TargetPathWithTargetPlatformMoniker ReferenceAssembly="@(ResolvedMatchingContract)" /> |
| 37 | + </ItemGroup> |
| 38 | + </Target> |
| 39 | + |
| 40 | + <!-- ##### APICompat settings ##### --> |
| 41 | + |
2 | 42 | <PropertyGroup> |
3 | 43 | <ApiCompatContractItemName>ResolvedMatchingContract</ApiCompatContractItemName> |
4 | 44 | <ApiCompatStrictMode Condition="'$(ApiCompatStrictMode)' == ''">true</ApiCompatStrictMode> |
| 45 | + |
| 46 | + <!-- Optional rules --> |
| 47 | + <ApiCompatEnableRuleAttributesMustMatch>true</ApiCompatEnableRuleAttributesMustMatch> |
| 48 | + <ApiCompatEnableRuleCannotChangeParameterName>true</ApiCompatEnableRuleCannotChangeParameterName> |
| 49 | + |
5 | 50 | <_ApiCompatCaptureGroupPattern>.+%5C$([System.IO.Path]::DirectorySeparatorChar)(.+)%5C$([System.IO.Path]::DirectorySeparatorChar)(.+)</_ApiCompatCaptureGroupPattern> |
6 | 51 | <_ApiCompatRuntimePrefixPattern>(.+)/(net%5Cd.%5Cd)-(.+)/(.+)</_ApiCompatRuntimePrefixPattern> |
7 | 52 | <_ApiCompatLibReplacementString>lib/$1/$2</_ApiCompatLibReplacementString> |
8 | 53 | <!-- CoreLib source projects have different output paths. --> |
9 | 54 | <_ApiCompatLibReplacementString Condition="'$(MSBuildProjectName)' == 'System.Private.CoreLib'">lib/$(NetCoreAppCurrent)/$2</_ApiCompatLibReplacementString> |
| 55 | + </PropertyGroup> |
10 | 56 |
|
11 | | - <GenAPIExcludeAttributesList>$(RepositoryEngineeringDir)DefaultGenApiDocIds.txt</GenAPIExcludeAttributesList> |
12 | | - <GenAPIHeaderFile>$(RepositoryEngineeringDir)LicenseHeader.txt</GenAPIHeaderFile> |
13 | | - <GenAPITargetPath>$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).cs'))</GenAPITargetPath> |
14 | | - <GenAPILangVersion Condition="'$(LangVersion)' != ''">$(LangVersion)</GenAPILangVersion> |
15 | | - <ProjectForGenAPIDocIdGeneration Condition="'$(IsSourceProject)' == 'true' and '$(ProjectForGenAPIDocIdGeneration)' == ''">$(CoreLibProject)</ProjectForGenAPIDocIdGeneration> |
| 57 | + <PropertyGroup Condition="'$(IsCrossTargetingBuild)' != 'true'"> |
| 58 | + <!-- Disable API compat if the project doesn't have a reference assembly. --> |
| 59 | + <ApiCompatValidateAssemblies Condition="'$(HasMatchingContract)' != 'true'">false</ApiCompatValidateAssemblies> |
| 60 | + <!-- TODO: Move into Microsoft.DotNet.GenFacadesNotSupported.targets. --> |
| 61 | + <!-- Not supported sources are created from the ref assembly, we currently don't produce finalizers in dummy assemblies, so we disable ApiCompat to not fail. --> |
| 62 | + <ApiCompatValidateAssemblies Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">false</ApiCompatValidateAssemblies> |
16 | 63 | </PropertyGroup> |
17 | 64 |
|
| 65 | + <ItemGroup> |
| 66 | + <ApiCompatExcludeAttributesFile Include="$(RepositoryEngineeringDir)DefaultGenApiDocIds.txt" /> |
| 67 | + <ApiCompatExcludeAttributesFile Include="$(RepositoryEngineeringDir)ApiCompatExcludeAttributes.txt" /> |
| 68 | + </ItemGroup> |
| 69 | + |
18 | 70 | <ItemGroup> |
19 | 71 | <!-- Transform the API Compat assemblies passed in to log-able strings. --> |
20 | 72 | <ApiCompatLeftAssembliesTransformationPattern Include="$(_ApiCompatCaptureGroupPattern)" ReplacementString="ref/$1/$2" /> |
|
30 | 82 | Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', '$(NetCoreAppCurrent)'))" /> |
31 | 83 | </ItemGroup> |
32 | 84 |
|
33 | | - <PropertyGroup Condition="'$(IsSourceProject)' == 'true'"> |
34 | | - <ContractProject Condition="'$(ContractProject)' == ''">$(LibrariesProjectRoot)$(MSBuildProjectName)\ref\$(MSBuildProjectName).csproj</ContractProject> |
35 | | - <HasMatchingContract Condition="'$(HasMatchingContract)' == '' and Exists('$(ContractProject)')">true</HasMatchingContract> |
36 | | - </PropertyGroup> |
37 | | - |
38 | | - <PropertyGroup Condition="'$(IsSourceProject)' == 'true' and '$(IsCrossTargetingBuild)' != 'true'"> |
39 | | - <!-- Disable API compat if the project doesn't have reference assembly --> |
40 | | - <ApiCompatValidateAssemblies Condition="'$(HasMatchingContract)' != 'true'">false</ApiCompatValidateAssemblies> |
41 | | - <!-- TODO: Move into Microsoft.DotNet.GenFacadesNotSupported.targets. --> |
42 | | - <!-- Not supported sources are created from the ref assembly, we currently don't produce finalizers in dummy assemblies, so we disable ApiCompat to not fail. --> |
43 | | - <ApiCompatValidateAssemblies Condition="'$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">false</ApiCompatValidateAssemblies> |
44 | | - </PropertyGroup> |
45 | | - |
46 | 85 | <!-- Use the apicompat task package instead of the in-built SDK functionality to consume newer features. --> |
47 | 86 | <ItemGroup Condition="'$(EnablePackageValidation)' == 'true' or |
48 | 87 | '$(ApiCompatValidateAssemblies)' == 'true'"> |
49 | 88 | <PackageReference Include="Microsoft.DotNet.ApiCompat.Task" Version="$(MicrosoftDotNetApiCompatTaskVersion)" PrivateAssets="all" IsImplicitlyDefined="true" /> |
50 | 89 | </ItemGroup> |
51 | 90 |
|
52 | | - <ItemGroup Condition="'$(HasMatchingContract)' == 'true' and '$(ContractProject)' != '' and '@(ResolvedMatchingContract)' == ''"> |
53 | | - <ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="ResolvedMatchingContract" /> |
54 | | - <!-- We aren't referencing the contract, but make sure it's considered as an input to Compile so that if it changes we rebuild and rerun API compat --> |
55 | | - <ProjectReference Include="$(ContractProject)" ReferenceOutputAssembly="false" OutputItemType="CustomAdditionalCompileInputs" /> |
56 | | - </ItemGroup> |
57 | | - <!-- intentionally empty since we no longer need a target --> |
58 | | - <Target Name="ResolveMatchingContract" /> |
| 91 | + <!-- ##### GenAPI settings ##### --> |
59 | 92 |
|
60 | | - <!-- Allow P2Ps that target a source project to build against the corresponding ref project. --> |
61 | | - <Target Name="AnnotateTargetPathWithTargetPlatformMonikerWithReferenceAssembly" |
62 | | - Condition="'$(HasMatchingContract)' == 'true'" |
63 | | - DependsOnTargets="ResolveProjectReferences" |
64 | | - AfterTargets="GetTargetPathWithTargetPlatformMoniker"> |
65 | | - <ItemGroup> |
66 | | - <!-- Allow to point to a different reference project than what GenFacades uses to generate the type forwards. --> |
67 | | - <TargetPathWithTargetPlatformMoniker ReferenceAssembly="@(ResolvedMatchingContractOverride)" /> |
68 | | - <TargetPathWithTargetPlatformMoniker ReferenceAssembly="@(ResolvedMatchingContract)" |
69 | | - Condition="'@(ResolvedMatchingContractOverride)' == ''" /> |
70 | | - </ItemGroup> |
71 | | - </Target> |
| 93 | + <PropertyGroup> |
| 94 | + <GenAPIExcludeAttributesList>$(RepositoryEngineeringDir)DefaultGenApiDocIds.txt</GenAPIExcludeAttributesList> |
| 95 | + <GenAPIHeaderFile>$(RepositoryEngineeringDir)LicenseHeader.txt</GenAPIHeaderFile> |
| 96 | + <GenAPITargetPath>$([MSBuild]::NormalizePath('$(MSBuildProjectDirectory)', '..', 'ref', '$(AssemblyName).cs'))</GenAPITargetPath> |
| 97 | + <GenAPILangVersion Condition="'$(LangVersion)' != ''">$(LangVersion)</GenAPILangVersion> |
| 98 | + <ProjectForGenAPIDocIdGeneration Condition="'$(ProjectForGenAPIDocIdGeneration)' == ''">$(CoreLibProject)</ProjectForGenAPIDocIdGeneration> |
| 99 | + </PropertyGroup> |
72 | 100 |
|
73 | | - <Target Name="HandleReferenceAssemblyAttributeForProjectReferences" |
74 | | - AfterTargets="ResolveProjectReferences" |
75 | | - BeforeTargets="FindReferenceAssembliesForReferences" |
76 | | - Condition="'@(ProjectReference)' != '' and '@(_ResolvedProjectReferencePaths)' != ''"> |
77 | | - <!-- If we have a ProjectReference to CoreLib, we need to compile against implementation assemblies. --> |
78 | | - <PropertyGroup Condition="@(_ResolvedProjectReferencePaths->AnyHaveMetadataValue('MSBuildSourceProjectFile', '$(CoreLibProject)'))"> |
79 | | - <CompileUsingReferenceAssemblies Condition="'$(CompileUsingReferenceAssemblies)' == ''">false</CompileUsingReferenceAssemblies> |
80 | | - </PropertyGroup> |
81 | | - <!-- Clear the ReferenceAssembly attribute on resolved P2Ps that set SkipUseReferenceAssembly to true. --> |
82 | | - <ItemGroup> |
83 | | - <_resolvedP2PFiltered Include="@(ProjectReference)" |
84 | | - ProjectReferenceItemSpec="$([System.IO.Path]::GetFullPath('%(ProjectReference.Identity)'))" |
85 | | - SkipUseReferenceAssembly="%(ProjectReference.SkipUseReferenceAssembly)" /> |
86 | | - <_ResolvedProjectReferencePaths Condition="'%(_resolvedP2PFiltered.ProjectReferenceItemSpec)' == '%(_resolvedP2PFiltered.MSBuildSourceProjectFile)' and |
87 | | - '%(_resolvedP2PFiltered.SkipUseReferenceAssembly)' == 'true'" |
88 | | - ReferenceAssembly="" /> |
89 | | - </ItemGroup> |
90 | | - </Target> |
| 101 | + <ItemGroup> |
| 102 | + <!-- GenAPI is currently only invoked on demand and not used as part of the build as it isn't source build compatible. --> |
| 103 | + <PackageReference Include="Microsoft.DotNet.GenAPI" |
| 104 | + Version="$(MicrosoftDotNetGenApiVersion)" |
| 105 | + PrivateAssets="all" |
| 106 | + IsImplicitlyDefined="true" |
| 107 | + Condition="'$(DotNetBuildFromSource)' != 'true'" /> |
| 108 | + </ItemGroup> |
91 | 109 |
|
92 | 110 | <!-- Generate a .txt file with all public types of the project referenced by ProjectForGenAPIDocIdGeneration (e.g. System.Private.CoreLib or System.Private.Uri implementation assembly). |
93 | 111 | This file is then later on passed to GenAPI as the list of types which should be "split out" with the conditional compilation logic. --> |
|
0 commit comments