|
1 | 1 | <!-- |
2 | | -
|
3 | 2 | The targets in this file are used to implement custom <Reference> resolution. |
4 | 3 | For more details, see /docs/ReferenceResolution.md. |
5 | 4 |
|
|
76 | 75 | <_AllowedExplicitPackageReference Include="FSharp.Core" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" /> |
77 | 76 | <_ExplicitPackageReference Include="@(PackageReference)" Exclude="@(_ImplicitPackageReference);@(_AllowedExplicitPackageReference)" /> |
78 | 77 |
|
79 | | - <_UnusedProjectReferenceProvider Include="@(ProjectReferenceProvider)" Exclude="@(Reference)" /> |
80 | | - |
81 | 78 | <_CompilationOnlyReference Condition="'$(TargetFramework)' == 'netstandard2.0'" |
82 | 79 | Include="@(Reference->WithMetadataValue('NuGetPackageId','NETStandard.Library'))" /> |
83 | 80 |
|
|
91 | 88 | @(Reference->WithMetadataValue('IsSharedSource', 'true')); |
92 | 89 | @(Reference->WithMetadataValue('PrivateAssets', 'All'))" /> |
93 | 90 | <_OriginalReferences Include="@(Reference)" /> |
| 91 | + </ItemGroup> |
94 | 92 |
|
95 | | - <!-- |
96 | | - Turn Reference items into a ProjectReference when UseProjectReferences is true. |
97 | | - Order matters. This comes before package resolution because projects should be used when possible instead of packages. |
| 93 | + <!-- |
| 94 | + Turn Reference items into a ProjectReference when UseProjectReferences is true. Order matters; this |
| 95 | + comes before package resolution because projects should be used when possible instead of packages. |
98 | 96 | --> |
99 | | - <_ProjectReferenceByAssemblyName Condition="'$(UseProjectReferences)' == 'true'" |
100 | | - Include="@(ProjectReferenceProvider)" |
101 | | - Exclude="@(_UnusedProjectReferenceProvider)" /> |
102 | | - |
103 | | - <ProjectReference Include="@(_ProjectReferenceByAssemblyName->'%(ProjectPath)')" /> |
104 | | - <Reference Remove="@(_ProjectReferenceByAssemblyName)" /> |
| 97 | + <ItemGroup Condition=" '$(EnableCustomReferenceResolution)' == 'true' AND '$(UseProjectReferences)' == 'true' "> |
| 98 | + <!-- Copy then Update / Copy to intersect the ProjectReferenceProvider and Reference item groups. --> |
| 99 | + <_AllProjectReference Include="@(ProjectReferenceProvider)" /> |
| 100 | + |
| 101 | + <!-- Use only Reference items when project is a reference provider. Simplifies project moves and shortens files. --> |
| 102 | + <_AllProjectReference Update="@(ProjectReference->'%(Filename)')" DirectUse="1" /> |
| 103 | + |
| 104 | + <_AllProjectReference Update="@(Reference)" Use="1"> |
| 105 | + <!-- |
| 106 | + Metadata list is long because (a) Update defaults to copying no metadata and (b) ProjectReference metadata |
| 107 | + may include (real) Reference metadata and MSBuild task parameters. Even so, the list below is not exhaustive. |
| 108 | + --> |
| 109 | + <Aliases>%(Reference.Aliases)</Aliases> |
| 110 | + <BuildInParallel>%(Reference.BuildInParallel)</BuildInParallel> |
| 111 | + <DoNotHarvest>%(Reference.DoNotHarvest)</DoNotHarvest> |
| 112 | + <ExcludeAssets>%(Reference.ExcludeAssets)</ExcludeAssets> |
| 113 | + <IncludeAssets>%(Reference.IncludeAssets)</IncludeAssets> |
| 114 | + <IsNativeImage>%(Reference.IsNativeImage)</IsNativeImage> |
| 115 | + <LinkBase>%(Reference.LinkBase)</LinkBase> |
| 116 | + <Name>%(Reference.Name)</Name> |
| 117 | + <OutputItemType>%(Reference.OutputItemType)</OutputItemType> |
| 118 | + <Package>%(Reference.Package)</Package> |
| 119 | + <Private>%(Reference.Private)</Private> |
| 120 | + <PrivateAssets>%(Reference.PrivateAssets)</PrivateAssets> |
| 121 | + <Project>%(Reference.Project)</Project> |
| 122 | + <Properties>%(Reference.Properties)</Properties> |
| 123 | + <Publish>%(Reference.Publish)</Publish> |
| 124 | + <ReferenceOutputAssembly>%(Reference.ReferenceOutputAssembly)</ReferenceOutputAssembly> |
| 125 | + <SetPlatform>%(Reference.SetPlatform)</SetPlatform> |
| 126 | + <SkipGetTargetFrameworkProperties>%(Reference.SkipGetTargetFrameworkProperties)</SkipGetTargetFrameworkProperties> |
| 127 | + <Targets>%(Reference.Targets)</Targets> |
| 128 | + <UndefineProperties>%(Reference.UndefineProperties)</UndefineProperties> |
| 129 | + <Watch>%(Reference.Watch)</Watch> |
| 130 | + </_AllProjectReference> |
| 131 | + |
| 132 | + <ProjectReference Include="@(_AllProjectReference->WithMetadataValue('Use', '1')->'%(ProjectPath)')" Use="" /> |
| 133 | + <Reference Remove="@(_AllProjectReference->WithMetadataValue('Use', '1'))" /> |
105 | 134 | </ItemGroup> |
106 | 135 |
|
107 | 136 | <!-- |
108 | | - This target resolves remaining Referene items to Packages, if possible. If not, they are left as Reference items fo the SDK to resolve. |
109 | | - This target helps ensure projects within the shared framework do no unintentionally add new references, |
110 | | - and that assemblies outside the shared framework reference the framework as a whole instead of using |
111 | | - individual assemblies. |
| 137 | + This target helps ensure projects within the shared framework do no unintentionally add new references, and that |
| 138 | + assemblies outside the shared framework reference the framework as a whole instead of using individual assemblies. |
| 139 | + In addition, enforce use of Reference items for projects reference providers. |
112 | 140 | --> |
113 | 141 | <Target Name="_CheckForReferenceBoundaries" BeforeTargets="CollectPackageReferences;ResolveReferences"> |
114 | 142 | <Error |
|
118 | 146 | <Error |
119 | 147 | Condition="@(_InvalidReferenceToNonSharedFxAssembly->Count()) != 0 AND '$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'" |
120 | 148 | Text="Cannot reference "%(_InvalidReferenceToNonSharedFxAssembly.Identity)". This dependency is not in the shared framework. See docs/SharedFramework.md for instructions on how to modify what is in the shared framework." /> |
| 149 | + |
| 150 | + <Error |
| 151 | + Condition=" '$(EnableCustomReferenceResolution)' == 'true' AND @(_AllProjectReference->WithMetadataValue('DirectUse', '1')->Count()) != 0 " |
| 152 | + Text="Cannot reference "%(_AllProjectReference.Identity)" with a ProjectReference item; use a Reference item." /> |
121 | 153 | </Target> |
122 | 154 |
|
123 | 155 | <Target Name="_WarnAboutRedundantRef" AfterTargets="ResolveFrameworkReferences;ProcessFrameworkReferences"> |
|
127 | 159 | </Target> |
128 | 160 |
|
129 | 161 | <!-- |
130 | | - This target resolves remaining Reference items to Packages, if possible. If not, they are left as Reference items fo the SDK to resolve. |
131 | | - This executes on NuGet restore and during DesignTimeBuild. It should not run in the outer, cross-targeting build. |
| 162 | + This target resolves remaining Reference items to Packages, if possible. If not, they are left as Reference |
| 163 | + items for the SDK to resolve. This executes on NuGet restore and during DesignTimeBuild. It should not run in |
| 164 | + outer, cross-targeting build. |
132 | 165 | --> |
133 | 166 | <Target Name="ResolveCustomReferences" |
134 | 167 | BeforeTargets="CheckForImplicitPackageReferenceOverrides;CollectPackageReferences;ResolvePackageAssets" |
135 | 168 | Condition=" '$(TargetFramework)' != '' AND '$(EnableCustomReferenceResolution)' == 'true' "> |
136 | 169 | <ItemGroup> |
137 | | - <!-- Ensure only content asset are consumed from .Sources packages --> |
| 170 | + <!-- Ensure only content assets are consumed from .Sources packages. --> |
138 | 171 | <Reference> |
139 | 172 | <IncludeAssets Condition="'%(IsSharedSource)' == 'true'">ContentFiles;Build</IncludeAssets> |
140 | 173 | <PrivateAssets Condition="'%(IsSharedSource)' == 'true'">All</PrivateAssets> |
|
285 | 318 | Text="Only implementation projects should set IsAspNetCoreApp=true." /> |
286 | 319 | <Error Condition=" '$(IsAspNetCoreApp)' != 'true' AND $(HasReferenceAssembly) " |
287 | 320 | Text="Only projects in the shared framework i.e. IsAspNetCoreApp==true should produce a reference assembly." /> |
| 321 | + <Warning Condition=" '$(IsProjectReferenceProvider)' == 'true' AND '$(AssemblyName)' != '$(MSBuildProjectName)' " |
| 322 | + Text="Project name "$(MSBuildProjectName)" is confusing; assembly is named "$(AssemblyName)"." /> |
288 | 323 |
|
289 | 324 | <ItemGroup Condition=" '$(IsProjectReferenceProvider)' == 'true' "> |
290 | 325 | <ProvidesReference Include="$(AssemblyName)"> |
|
0 commit comments