Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/ProjectReferences.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<ProjectReferenceProvider Include="Microsoft.Extensions.Logging.Analyzers" ProjectPath="$(RepoRoot)src\Logging\Logging.Analyzers\src\Microsoft.Extensions.Logging.Analyzers.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Logging.Testing" ProjectPath="$(RepoRoot)src\Logging\Logging.Testing\src\Microsoft.Extensions.Logging.Testing.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Analyzer.Testing" ProjectPath="$(RepoRoot)src\TestingUtils\Microsoft.AspNetCore.Analyzer.Testing\src\Microsoft.AspNetCore.Analyzer.Testing.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Testing" ProjectPath="$(RepoRoot)src\TestingUtils\Microsoft.AspNetCore.Testing\src\Microsoft.AspNetCore.Testing.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.Abstractions" ProjectPath="$(RepoRoot)src\Caching\Abstractions\src\Microsoft.Extensions.Caching.Abstractions.csproj" RefProjectPath="$(RepoRoot)src\Caching\Abstractions\ref\Microsoft.Extensions.Caching.Abstractions.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.Memory" ProjectPath="$(RepoRoot)src\Caching\Memory\src\Microsoft.Extensions.Caching.Memory.csproj" RefProjectPath="$(RepoRoot)src\Caching\Memory\ref\Microsoft.Extensions.Caching.Memory.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Caching.SqlServer" ProjectPath="$(RepoRoot)src\Caching\SqlServer\src\Microsoft.Extensions.Caching.SqlServer.csproj" RefProjectPath="$(RepoRoot)src\Caching\SqlServer\ref\Microsoft.Extensions.Caching.SqlServer.csproj" />
Expand Down Expand Up @@ -57,6 +56,7 @@
<ProjectReferenceProvider Include="Microsoft.Extensions.Options.DataAnnotations" ProjectPath="$(RepoRoot)src\Options\DataAnnotations\src\Microsoft.Extensions.Options.DataAnnotations.csproj" RefProjectPath="$(RepoRoot)src\Options\DataAnnotations\ref\Microsoft.Extensions.Options.DataAnnotations.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Options" ProjectPath="$(RepoRoot)src\Options\Options\src\Microsoft.Extensions.Options.csproj" RefProjectPath="$(RepoRoot)src\Options\Options\ref\Microsoft.Extensions.Options.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.Primitives" ProjectPath="$(RepoRoot)src\Primitives\src\Microsoft.Extensions.Primitives.csproj" RefProjectPath="$(RepoRoot)src\Primitives\ref\Microsoft.Extensions.Primitives.csproj" />
<ProjectReferenceProvider Include="Microsoft.AspNetCore.Testing" ProjectPath="$(RepoRoot)src\TestingUtils\Microsoft.AspNetCore.Testing\src\Microsoft.AspNetCore.Testing.csproj" RefProjectPath="$(RepoRoot)src\TestingUtils\Microsoft.AspNetCore.Testing\ref\Microsoft.AspNetCore.Testing.csproj" />
<ProjectReferenceProvider Include="Microsoft.Extensions.WebEncoders" ProjectPath="$(RepoRoot)src\WebEncoders\src\Microsoft.Extensions.WebEncoders.csproj" RefProjectPath="$(RepoRoot)src\WebEncoders\ref\Microsoft.Extensions.WebEncoders.csproj" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion eng/targets/ReferenceAssembly.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

</Target>

<Target Name="_GenerateProjectSourceInner" Returns="@(ProjectListContent)" DependsOnTargets="Build" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework'">
<Target Name="_GenerateProjectSourceInner" Returns="@(ProjectListContent)" DependsOnTargets="Build" Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework' OR '$(GenerateFrameworkReferenceAssembly)' == 'true'">
<PropertyGroup>
<_RefSourceOutputPath>$([System.IO.Directory]::GetParent('$(MSBuildProjectDirectory)'))/ref/</_RefSourceOutputPath>
<_RefSourceFileName>$(AssemblyName).$(TargetFramework).cs</_RefSourceFileName>
Expand Down
114 changes: 92 additions & 22 deletions eng/targets/ResolveReferences.targets
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,18 @@
Projects should only use the project references instead of baseline package references when:
* preparing a new major or minor release (i.e. a non-servicing builds)
* when a project is a test or sample project

We don't use project references between components in servicing builds between compontents to preserve the baseline as much as possible.
-->
<UseProjectReferences Condition=" '$(UseProjectReferences)' == '' AND '$(IsServicingBuild)' != 'true' ">true</UseProjectReferences>
<UseProjectReferences Condition=" '$(UseProjectReferences)' == '' AND '$(IsImplementationProject)' != 'true' ">true</UseProjectReferences>
<UseProjectReferences Condition=" '$(UseProjectReferences)' == '' ">false</UseProjectReferences>

<!-- Specifies if reference assembly projects should be resolved for Reference items -->
<ReferenceReferenceAssemblies Condition=" '$(ReferenceReferenceAssemblies)' == '' AND '$(IsReferenceAssemblyProject)' == 'true'">true</ReferenceReferenceAssemblies>
<ReferenceReferenceAssemblies Condition=" '$(ReferenceReferenceAssemblies)' == '' AND ('$(IsReferenceAssemblyProject)' == 'true' OR '$(IsImplementationAssemblyProject)' == 'true')">true</ReferenceReferenceAssemblies>
<ReferenceReferenceAssemblies Condition=" '$(ReferenceReferenceAssemblies)' == '' ">false</ReferenceReferenceAssemblies>

<!-- Specifies if implementation assembly projects should be resolved for Reference items -->
<ReferenceImplementationAssemblies Condition=" '$(ReferenceImplementationAssemblies)' == '' AND '$(IsReferenceAssemblyProject)' != 'true'">true</ReferenceImplementationAssemblies>
<ReferenceImplementationAssemblies Condition=" '$(ReferenceImplementationAssemblies)' == '' AND '$(IsReferenceAssemblyProject)' != 'true' AND '$(IsImplementationAssemblyProject)' != 'true'">true</ReferenceImplementationAssemblies>
<ReferenceImplementationAssemblies Condition=" '$(ReferenceImplementationAssemblies)' == '' ">false</ReferenceImplementationAssemblies>
</PropertyGroup>

Expand All @@ -74,16 +73,23 @@
<IsSharedSource Condition="'%(IsSharedSource)' == '' AND $([System.String]::new('%(Identity)').EndsWith('.Sources'))">true</IsSharedSource>
</Reference>

<!-- Packages which are implicitly defined by the .NET Core SDK. -->
<_ImplicitPackageReference Include="@(PackageReference->WithMetadataValue('IsImplicitlyDefined', 'true'))" />
<_ExplicitPackageReference Include="@(PackageReference)" Exclude="@(_ImplicitPackageReference)" />
<_OriginalReferences Include="@(Reference)" />

<UnusedProjectReferenceProvider Include="@(ProjectReferenceProvider)" Exclude="@(Reference)" />
<!-- Capture a list of references which were set explicitly in the project. -->
<_AllowedExplicitPackageReference Include="@(PackageReference->WithMetadataValue('AllowExplicitReference', 'true'))" />
<!-- These references are specifed as PackageReference explicitly in projects. These are generally not allowed and this itemgroup will be used to generate an error. -->
<_ExplicitPackageReference Include="@(PackageReference)" Exclude="@(_ImplicitPackageReference);@(_AllowedExplicitPackageReference)" />
<!-- Capture a list of reference providers which are not referenced. This is used to compute _ProjectReferenceByAssemblyName later. -->
<_UnusedProjectReferenceProvider Include="@(ProjectReferenceProvider)" Exclude="@(Reference)" />

<!-- Order matters. Projects should be used when possible instead of packages. -->
<_OriginalReferences Include="@(Reference)" />
<!--
Turn Reference items into a ProjectReference when UseProjectReferences is true.
Order matters. This comes before package resolution because projects should be used when possible instead of packages.
-->
<_ProjectReferenceByAssemblyName Condition="'$(UseProjectReferences)' == 'true'"
Include="@(ProjectReferenceProvider)"
Exclude="@(UnusedProjectReferenceProvider)" />
Exclude="@(_UnusedProjectReferenceProvider)" />

<!-- Use ref assembly project paths for ref assembly projects -->
<ProjectReference Condition="'$(ReferenceImplementationAssemblies)' == 'true'" Include="@(_ProjectReferenceByAssemblyName->'%(ProjectPath)')" >
Expand All @@ -97,15 +103,39 @@
<Reference Remove="@(_ProjectReferenceByAssemblyName)" />
</ItemGroup>

<Target Name="ResolveCustomReferences" BeforeTargets="CollectPackageReferences;ResolveAssemblyReferencesDesignTime;ResolveAssemblyReferences" Condition=" '$(TargetFramework)' != '' AND '$(EnableCustomReferenceResolution)' == 'true'">
<!--
This target resolves remaining Reference items to Packages, if possible. If not, they are left as Reference items for the SDK to resolve.
This target helps ensure projects within the shared framework do no unintentionally add new references,
and that assemblies outside the shared framework reference the framework as a whole instead of using
individual assemblies.
-->
<Target Name="_CheckForReferenceBoundaries" BeforeTargets="CollectPackageReferences;ResolveReferences">

<Error Condition="@(_InvalidReferenceToSharedFxOnlyAssembly->Count()) != 0"
Text="Cannot reference &quot;%(_InvalidReferenceToSharedFxOnlyAssembly.Identity)&quot; directly because it is part of the shared framework and this project is not. Use &lt;FrameworkReference Include=&quot;Microsoft.AspNetCore.App&quot; /&gt; instead." />
</Target>

<Target Name="_WarnAboutRedundantRef" AfterTargets="ResolveFrameworkReferences;ProcessFrameworkReferences">
<Warning Condition="@(FrameworkReference->WithMetadataValue('Identity', 'Microsoft.AspNetCore.App')->Count()) &gt; 1"
Text="Redundant &lt;FrameworkReference&gt;. If you have an explicit item in the project file, you might be able to remove it. Some SDKs, like Microsoft.NET.Sdk.Web, add this implicitly." />
</Target>

<!--
This target resolves remaining Referene items to Packages, if possible. If not, they are left as Reference items fo the SDK to resolve.
This executes on NuGet restore and during DesignTimeBuild. It should not run in the outer, cross-targeting build.
-->
<Target Name="ResolveCustomReferences" BeforeTargets="CollectPackageReferences;ResolveAssemblyReferencesDesignTime;ResolveAssemblyReferences" Condition=" '$(TargetFramework)' != '' AND '$(EnableCustomReferenceResolution)' == 'true' ">
<ItemGroup>
<!-- Ensure only content asset and msbuild props/targets are consumed from .Sources packages -->
<!-- Ensure only content asset are consumed from .Sources packages -->
<Reference>
<IncludeAssets Condition="'%(IsSharedSource)' == 'true'">ContentFiles;Build</IncludeAssets>
<PrivateAssets Condition="'%(IsSharedSource)' == 'true'">All</PrivateAssets>
</Reference>

<UnusedBaselinePackageReference Include="@(BaselinePackageReference)" Exclude="@(Reference);@(_ProjectReferenceByAssemblyName)" />
<!-- Identify if any references were present in the last release of this package, but have been removed. -->
<UnusedBaselinePackageReference Include="@(BaselinePackageReference)" Exclude="@(Reference);@(_ProjectReferenceByAssemblyName);@(PackageReference)" />
<!-- Only allow suppressing baseline changes in non-servicing builds. -->
<UnusedBaselinePackageReference Remove="@(SuppressBaselineReference)" Condition="'$(IsServicingBuild)' != 'true'"/>

<!--
MSBuild does not provide a way to join on matching identities in a Condition,
Expand All @@ -121,6 +151,7 @@
<Reference Remove="@(_LatestPackageReferenceWithVersion)" />
<PackageReference Include="@(_LatestPackageReferenceWithVersion)" IsImplicitlyDefined="true" />

<!-- Resolve references from BaselinePackageReference for servicing builds. -->
<_BaselinePackageReferenceWithVersion Include="@(Reference)" Condition=" '$(IsServicingBuild)' == 'true' OR '$(UseLatestPackageReferences)' != 'true' ">
<Id>%(BaselinePackageReference.Identity)</Id>
<Version>%(BaselinePackageReference.Version)</Version>
Expand All @@ -132,7 +163,7 @@
<PackageReference Include="@(_BaselinePackageReferenceWithVersion)" IsImplicitlyDefined="true" />
<Reference Remove="@(_BaselinePackageReferenceWithVersion)" />

<!-- For PrivateAssets=All references, fallback to LatestPackageReferences. -->
<!-- For PrivateAssets=All references, like .Sources packages, fallback to LatestPackageReferences. -->
<_PrivatePackageReferenceWithVersion Include="@(Reference->WithMetadataValue('PrivateAssets', 'All'))">
<Id>%(LatestPackageReference.Identity)</Id>
<Version>%(LatestPackageReference.Version)</Version>
Expand All @@ -145,27 +176,33 @@
<Reference Remove="@(_PrivatePackageReferenceWithVersion)" />

<!-- Free up memory for unnecessary items -->
<_BaselinePackageReferenceWithVersion Remove="@(_BaselinePackageReferenceWithVersion)" />
<_LatestPackageReferenceWithVersion Remove="@(_LatestPackageReferenceWithVersion)" />
<_BaselinePackageReferenceWithVersion Remove="@(_BaselinePackageReferenceWithVersion)" />
<_PrivatePackageReferenceWithVersion Remove="@(_PrivatePackageReferenceWithVersion)" />
<_ImplicitPackageReference Remove="@(_ImplicitPackageReference)" />
</ItemGroup>

<Error Condition="@(_ExplicitPackageReference->Count()) != 0"
Text="PackageReference items are not allowed. Use &lt;Reference&gt; instead. " />
<Error Condition="'$(DisablePackageReferenceRestrictions)' != 'true' AND @(_ExplicitPackageReference->Count()) != 0"
Text="PackageReference items are not allowed. Use &lt;Reference&gt; instead to replace the reference to @(_ExplicitPackageReference, ', '). See docs/ReferenceResolution.md for more details." />

<ItemGroup>
<_ExplicitPackageReference Remove="@(_ExplicitPackageReference)" />
</ItemGroup>

<Warning Condition="@(UnusedBaselinePackageReference->Count()) != 0 AND ! $(NoWarn.Contains('PKG0001'))"
Code="PKG0001"
Text="Package references changed since the last release. This could be a breaking change. References removed:%0A - @(UnusedBaselinePackageReference, '%0A -')" />
<Warning Condition="'$(IsReferenceAssemblyProject)' != 'true' AND '$(IsServicingBuild)' != 'true' AND '%(UnusedBaselinePackageReference.Identity)' != ''"
Code="BUILD001"
Text="Reference to '%(UnusedBaselinePackageReference.Identity)' was removed since the last stable release of this package. This could be a breaking change. See docs/ReferenceResolution.md for instructions on how to update changes to references or suppress this warning if the error was intentional." />

<Error Condition="'$(IsReferenceAssemblyProject)' != 'true' AND '$(IsServicingBuild)' == 'true' AND @(UnusedBaselinePackageReference->Count()) != 0"
Code="BUILD002"
Text="Package references changed since the last release. This could be a breaking change and is not allowed in a servicing update. References removed:%0A - @(UnusedBaselinePackageReference, '%0A -')" />

<Error Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework' AND '%(Reference.Identity)' != '' AND ! Exists('%(Reference.Identity)')"
<Error Condition="'$(TargetFrameworkIdentifier)' != '.NETFramework' AND '%(Reference.Identity)' != '' AND ! Exists('%(Reference.Identity)') AND '$(DisablePackageReferenceRestrictions)' != 'true'"
Code="MSB3245"
Text="Could not resolve this reference. Could not locate the package or project for &quot;%(Reference.Identity)&quot;. If you are adding a new project or package, see instructions in docs/ReferenceResolution.md" />
Text="Could not resolve this reference. Could not locate the package or project for &quot;%(Reference.Identity)&quot;. Did you update baselines and dependencies lists? See docs/ReferenceResolution.md for more details." />
</Target>

<!-- These targets are used to generate the map of assembly name to project files. See also the /t:GenerateProjectList target in build/repo.targets. -->
<Target Name="GetReferencesProvided" Returns="@(ProvidesReference)">
<ItemGroup>
<_TargetFramework Remove="@(_TargetFramework)" />
Expand All @@ -182,13 +219,46 @@

<Target Name="_GetReferencesProvided" Returns="@(ProvidesReference)">
<PropertyGroup>
<ReferenceAssemblyProjectFileRelativePath>$([MSBuild]::MakeRelative($(RepoRoot), '$(MSBuildProjectDirectory)/../ref/$(MSBuildProjectFile)'))</ReferenceAssemblyProjectFileRelativePath>
<ReferenceAssemblyDirectory>$(MSBuildProjectDirectory)/../ref/</ReferenceAssemblyDirectory>
<ReferenceAssemblyProjectFileRelativePath>$([MSBuild]::MakeRelative($(RepoRoot), '$(ReferenceAssemblyDirectory)$(MSBuildProjectFile)'))</ReferenceAssemblyProjectFileRelativePath>
</PropertyGroup>

<Error Condition="'$(SkipRefDirectoryCheck)' != 'true' AND '$(IsImplementationProject)' == 'true' AND '$(HasReferenceAssembly)' != 'true' AND Exists($(ReferenceAssemblyDirectory))" Text="Project shouldn't have reference assembly but folder exists $(ReferenceAssemblyDirectory)" />
<Error Condition=" '$(IsAspNetCoreApp)' == 'true' AND '$(IsImplementationProject)' == 'true' AND '$(HasReferenceAssembly)' != 'true'" Text="All assemblies which have set IsAspNetCoreApp=true should produce a reference assembly." />

<ItemGroup Condition=" '$(IsProjectReferenceProvider)' == 'true' ">
<ProvidesReference Include="$(AssemblyName)">
<IsAspNetCoreApp>$([MSBuild]::ValueOrDefault($(IsAspNetCoreApp),'false'))</IsAspNetCoreApp>
<IsShippingPackage>$([MSBuild]::ValueOrDefault($(IsShippingPackage),'false'))</IsShippingPackage>
<ProjectFileRelativePath>$([MSBuild]::MakeRelative($(RepoRoot), $(MSBuildProjectFullPath)))</ProjectFileRelativePath>
<ReferenceAssemblyProjectFileRelativePath Condition="'$(HasReferenceAssembly)' == 'true'">$(ReferenceAssemblyProjectFileRelativePath)</ReferenceAssemblyProjectFileRelativePath>
</ProvidesReference>
</ItemGroup>
</Target>

<!-- This is used by the eng/scripts/AddAllProjectRefsToSolution.ps1 script to traverse the ProjectRef graph -->
<PropertyGroup>
<_CustomCollectProjectReferenceDependsOn Condition="'$(TargetFramework)' != ''">ResolveProjectReferences</_CustomCollectProjectReferenceDependsOn>
</PropertyGroup>
<Target Name="_CustomCollectProjectReference" DependsOnTargets="$(_CustomCollectProjectReferenceDependsOn)" Returns="$(MSBuildProjectFullPath);@(_MSBuildProjectReferenceExistent)">
<ItemGroup>
<_TargetFrameworks Include="$(TargetFrameworks)" />
</ItemGroup>
<MSBuild Condition="'$(TargetFramework)' == ''"
Targets="_CustomCollectProjectReference"
BuildInParallel="true"
Projects="$(MSBuildProjectFullPath)"
Properties="TargetFramework=%(_TargetFrameworks.Identity)"
RebaseOutputs="True">
<Output TaskParameter="TargetOutputs" ItemName="_MSBuildProjectReferenceExistent" />
</MSBuild>
<MSBuild Condition="'$(TargetFramework)' != ''"
Targets="_CustomCollectProjectReference"
BuildInParallel="true"
SkipNonexistentTargets="true"
Projects="@(_MSBuildProjectReferenceExistent)"
RebaseOutputs="True">
<Output TaskParameter="TargetOutputs" ItemName="_MSBuildProjectReferenceExistent" />
</MSBuild>
</Target>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="$(SharedSourceRoot)ProviderAliasUtilities\*.cs" />

<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
</ItemGroup>
Expand Down
5 changes: 1 addition & 4 deletions src/Logging/Logging/src/Microsoft.Extensions.Logging.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
<IsShipping>true</IsShipping>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.Extensions.Logging.Configuration" />
</ItemGroup>

<ItemGroup>
<Compile Include="../../shared/*.cs" />
<Compile Include="$(SharedSourceRoot)ProviderAliasUtilities\*.cs" />

<Reference Include="Microsoft.Extensions.Configuration.Binder" />
<Reference Include="Microsoft.Extensions.DependencyInjection" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Microsoft.Extensions.Logging
{
internal class ProviderAliasUtilities
internal static class ProviderAliasUtilities
{
private const string AliasAttibuteTypeFullName = "Microsoft.Extensions.Logging.ProviderAliasAttribute";
private const string AliasAttibuteAliasProperty = "Alias";
Expand Down
Loading