Skip to content

Keep @(Reference) metadata when creating @(ProjectReference) items #21567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2020
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
4 changes: 2 additions & 2 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Microsoft.AspNetCore.Razor.Tools", "Microsoft.AspNetCore.Razor.Tools", "{B9704650-5360-416C-9393-FAF707766AA8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Tools", "src\Razor\Microsoft.AspNetCore.Razor.Tools\src\Microsoft.AspNetCore.Razor.Tools.csproj", "{4C84173F-5C1F-49A1-895A-C0CA11DE84B1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Tools", "src\Razor\Microsoft.AspNetCore.Razor.Tools\src\rzc.csproj", "{4C84173F-5C1F-49A1-895A-C0CA11DE84B1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Razor.Tools.Test", "src\Razor\Microsoft.AspNetCore.Razor.Tools\test\Microsoft.AspNetCore.Razor.Tools.Test.csproj", "{FE095F11-4CD2-406D-A2BB-1BE569603BF0}"
EndProject
Expand Down Expand Up @@ -1295,7 +1295,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.ApiDes
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GetDocumentInsider", "GetDocumentInsider", "{A1B75FC7-A777-4412-A635-D0C9ED8FE7A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetDocumentInsider", "src\Tools\GetDocumentInsider\src\GetDocumentInsider.csproj", "{DD63EA3C-929C-48FF-8E8A-8F3CC553E93B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GetDocumentInsider", "src\Tools\GetDocumentInsider\src\GetDocument.Insider.csproj", "{DD63EA3C-929C-48FF-8E8A-8F3CC553E93B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.ApiDescription.Client.Tests", "src\Tools\Extensions.ApiDescription.Client\test\Microsoft.Extensions.ApiDescription.Client.Tests.csproj", "{34E40892-48C1-4D3D-AB49-FAC3C4C00B42}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion eng/CodeGen.proj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
-->
<Project>
<ItemGroup>
@(_ProjectReferenceProvider->'<ProjectReferenceProvider Include="%(Identity)" ProjectPath="%24(RepoRoot)%(ProjectFileRelativePath)" />', '%0A ')
@(_ProjectReferenceProvider->'<ProjectReferenceProvider Include="%(Identity)" ProjectPath="%24(RepoRoot)%(ProjectFileRelativePath)" />', '%0A ')
</ItemGroup>
</Project>
]]></ProjectListContent>
Expand Down
310 changes: 155 additions & 155 deletions eng/ProjectReferences.props

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions eng/targets/CSharp.Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
several versions older than latest. We reference the project to ensure it's built before the other projects that use it. Since this
is a project reference, we must explicitly import the props file and also specify the output location of the SDK directory.
-->
<ProjectReference Include="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\Microsoft.NET.Sdk.Razor.csproj"
<Reference Include="Microsoft.NET.Sdk.Razor"
PrivateAssets="All"
IsImplicitlyDefined="true"
ReferenceOutputAssembly="false"
SkipGetTargetFrameworkProperties="true"
UndefineProperties="TargetFramework;TargetFrameworks" />
Expand Down
73 changes: 54 additions & 19 deletions eng/targets/ResolveReferences.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!--

The targets in this file are used to implement custom <Reference> resolution.
For more details, see /docs/ReferenceResolution.md.

Expand Down Expand Up @@ -76,8 +75,6 @@
<_AllowedExplicitPackageReference Include="FSharp.Core" Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />
<_ExplicitPackageReference Include="@(PackageReference)" Exclude="@(_ImplicitPackageReference);@(_AllowedExplicitPackageReference)" />

<_UnusedProjectReferenceProvider Include="@(ProjectReferenceProvider)" Exclude="@(Reference)" />

<_CompilationOnlyReference Condition="'$(TargetFramework)' == 'netstandard2.0'"
Include="@(Reference->WithMetadataValue('NuGetPackageId','NETStandard.Library'))" />

Expand All @@ -91,24 +88,55 @@
@(Reference->WithMetadataValue('IsSharedSource', 'true'));
@(Reference->WithMetadataValue('PrivateAssets', 'All'))" />
<_OriginalReferences Include="@(Reference)" />
</ItemGroup>

<!--
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.
<!--
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)" />

<ProjectReference Include="@(_ProjectReferenceByAssemblyName->'%(ProjectPath)')" />
<Reference Remove="@(_ProjectReferenceByAssemblyName)" />
<ItemGroup Condition=" '$(EnableCustomReferenceResolution)' == 'true' AND '$(UseProjectReferences)' == 'true' ">
<!-- Copy then Update / Copy to intersect the ProjectReferenceProvider and Reference item groups. -->
<_AllProjectReference Include="@(ProjectReferenceProvider)" />

<!-- Use only Reference items when project is a reference provider. Simplifies project moves and shortens files. -->
<_AllProjectReference Update="@(ProjectReference->'%(Filename)')" DirectUse="1" />

<_AllProjectReference Update="@(Reference)" Use="1">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a guarantee we'll never need to update this list of metadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are few guarantees in life😈 But, the current list goes pretty far beyond what we're likely to use in *.csproj and *.fsproj projects and should hold us in good stead until and unless new metadata is invented. I included everything I saw used in existing @(Reference) and @(ProjectReference) items in this repo as well as what seemed plausible from the documentation.

<!--
Metadata list is long because (a) Update defaults to copying no metadata and (b) ProjectReference metadata
may include (real) Reference metadata and MSBuild task parameters. Even so, the list below is not exhaustive.
-->
<Aliases>%(Reference.Aliases)</Aliases>
<BuildInParallel>%(Reference.BuildInParallel)</BuildInParallel>
<DoNotHarvest>%(Reference.DoNotHarvest)</DoNotHarvest>
<ExcludeAssets>%(Reference.ExcludeAssets)</ExcludeAssets>
<IncludeAssets>%(Reference.IncludeAssets)</IncludeAssets>
<IsNativeImage>%(Reference.IsNativeImage)</IsNativeImage>
<LinkBase>%(Reference.LinkBase)</LinkBase>
<Name>%(Reference.Name)</Name>
<OutputItemType>%(Reference.OutputItemType)</OutputItemType>
<Package>%(Reference.Package)</Package>
<Private>%(Reference.Private)</Private>
<PrivateAssets>%(Reference.PrivateAssets)</PrivateAssets>
<Project>%(Reference.Project)</Project>
<Properties>%(Reference.Properties)</Properties>
<Publish>%(Reference.Publish)</Publish>
<ReferenceOutputAssembly>%(Reference.ReferenceOutputAssembly)</ReferenceOutputAssembly>
<SetPlatform>%(Reference.SetPlatform)</SetPlatform>
<SkipGetTargetFrameworkProperties>%(Reference.SkipGetTargetFrameworkProperties)</SkipGetTargetFrameworkProperties>
<Targets>%(Reference.Targets)</Targets>
<UndefineProperties>%(Reference.UndefineProperties)</UndefineProperties>
<Watch>%(Reference.Watch)</Watch>
</_AllProjectReference>

<ProjectReference Include="@(_AllProjectReference->WithMetadataValue('Use', '1')->'%(ProjectPath)')" Use="" />
<Reference Remove="@(_AllProjectReference->WithMetadataValue('Use', '1'))" />
</ItemGroup>

<!--
This target resolves remaining Referene items to Packages, if possible. If not, they are left as Reference items fo 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.
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.
In addition, enforce use of Reference items for projects reference providers.
-->
<Target Name="_CheckForReferenceBoundaries" BeforeTargets="CollectPackageReferences;ResolveReferences">
<Error
Expand All @@ -118,6 +146,10 @@
<Error
Condition="@(_InvalidReferenceToNonSharedFxAssembly->Count()) != 0 AND '$(TargetFramework)' == '$(DefaultNetCoreTargetFramework)'"
Text="Cannot reference &quot;%(_InvalidReferenceToNonSharedFxAssembly.Identity)&quot;. This dependency is not in the shared framework. See docs/SharedFramework.md for instructions on how to modify what is in the shared framework." />

<Error
Condition=" '$(EnableCustomReferenceResolution)' == 'true' AND @(_AllProjectReference->WithMetadataValue('DirectUse', '1')->Count()) != 0 "
Text="Cannot reference &quot;%(_AllProjectReference.Identity)&quot; with a ProjectReference item; use a Reference item." />
</Target>

<Target Name="_WarnAboutRedundantRef" AfterTargets="ResolveFrameworkReferences;ProcessFrameworkReferences">
Expand All @@ -127,14 +159,15 @@
</Target>

<!--
This target resolves remaining Reference 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.
This target resolves remaining Reference items to Packages, if possible. If not, they are left as Reference
items for the SDK to resolve. This executes on NuGet restore and during DesignTimeBuild. It should not run in
outer, cross-targeting build.
-->
<Target Name="ResolveCustomReferences"
BeforeTargets="CheckForImplicitPackageReferenceOverrides;CollectPackageReferences;ResolvePackageAssets"
Condition=" '$(TargetFramework)' != '' AND '$(EnableCustomReferenceResolution)' == 'true' ">
<ItemGroup>
<!-- Ensure only content asset are consumed from .Sources packages -->
<!-- Ensure only content assets are consumed from .Sources packages. -->
<Reference>
<IncludeAssets Condition="'%(IsSharedSource)' == 'true'">ContentFiles;Build</IncludeAssets>
<PrivateAssets Condition="'%(IsSharedSource)' == 'true'">All</PrivateAssets>
Expand Down Expand Up @@ -285,6 +318,8 @@
Text="Only implementation projects should set IsAspNetCoreApp=true." />
<Error Condition=" '$(IsAspNetCoreApp)' != 'true' AND $(HasReferenceAssembly) "
Text="Only projects in the shared framework i.e. IsAspNetCoreApp==true should produce a reference assembly." />
<Warning Condition=" '$(IsProjectReferenceProvider)' == 'true' AND '$(AssemblyName)' != '$(MSBuildProjectName)' "
Text="Project name &quot;$(MSBuildProjectName)&quot; is confusing; assembly is named &quot;$(AssemblyName)&quot;." />

<ItemGroup Condition=" '$(IsProjectReferenceProvider)' == 'true' ">
<ProvidesReference Include="$(AssemblyName)">
Expand Down
4 changes: 2 additions & 2 deletions eng/tools/RepoTasks/DownloadFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private async System.Threading.Tasks.Task<bool> ExecuteAsync()

Log.LogMessage(MessageImportance.High, $"Attempting download '{source}' to '{target}'");

using (var httpClient = new HttpClient())
using (var httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(5) })
{
for (int retryNumber = 0; retryNumber < MaxRetries; retryNumber++)
{
Expand Down Expand Up @@ -146,4 +146,4 @@ private async System.Threading.Tasks.Task<bool> ExecuteAsync()
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" />
<Reference Include="Microsoft.AspNetCore.Components.Server" />
<Reference Include="Microsoft.AspNetCore.ResponseCompression" />
<Reference Include="Microsoft.AspNetCore" />

<Compile Include="$(SharedSourceRoot)CommandLineUtils\**\*.cs" />
<Reference Include="Microsoft.Extensions.Hosting" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,8 @@

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Razor\test\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj" />

<ProjectReference Include="..\src\Microsoft.NET.Sdk.BlazorWebAssembly.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
</ProjectReference>

<ProjectReference Include="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\Microsoft.NET.Sdk.Razor.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
</ProjectReference>
<Reference Include="Microsoft.NET.Sdk.BlazorWebAssembly" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
<Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
Include="..\tools\Microsoft.NET.Sdk.BlazorWebAssembly.Tools.csproj"
Targets="Publish"
ReferenceOutputAssembly="false"
IsImplicityDefined="false"
SkipGetTargetFrameworkProperties="true"
UndefineProperties="TargetFramework;TargetFrameworks;RuntimeIdentifier;PublishDir" />
</ItemGroup>
Expand Down
35 changes: 18 additions & 17 deletions src/DefaultBuilder/src/Microsoft.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Diagnostics" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.HostFiltering" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.Hosting" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.Routing" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.Server.IIS" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Configuration.Json" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Configuration.CommandLine" PrivateAssets="None" />
<Reference Include="Microsoft.AspNetCore.Diagnostics" />
<Reference Include="Microsoft.AspNetCore.HostFiltering" />
<Reference Include="Microsoft.AspNetCore.Hosting" />
<Reference Include="Microsoft.AspNetCore.Routing" />
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
<Reference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions" />
<Reference Include="Microsoft.Extensions.Configuration.Json" />
<Reference Include="Microsoft.Extensions.Configuration.CommandLine" />
<!-- Projects using this one should get UserSecrets build assets and those are private by default. -->
<Reference Include="Microsoft.Extensions.Configuration.UserSecrets" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.FileProviders.Composite" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Logging" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Logging.Configuration" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Logging.Console" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Logging.Debug" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.Logging.EventSource" PrivateAssets="None" />
<Reference Include="Microsoft.Extensions.FileProviders.Composite" />
<Reference Include="Microsoft.Extensions.Logging" />
<Reference Include="Microsoft.Extensions.Logging.Configuration" />
<Reference Include="Microsoft.Extensions.Logging.Console" />
<Reference Include="Microsoft.Extensions.Logging.Debug" />
<Reference Include="Microsoft.Extensions.Logging.EventSource" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
<ProjectReference Include="$(RepoRoot)src\Hosting\Server.IntegrationTesting\src\Microsoft.AspNetCore.Server.IntegrationTesting.csproj" />
<ProjectReference Include="../testassets/DotNetToolsInstaller/DotNetToolsInstaller.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="../Web.ProjectTemplates/Microsoft.DotNet.Web.ProjectTemplates.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\Microsoft.NET.Sdk.Razor.csproj"
ReferenceOutputAssembly="false"
SkipGetTargetFrameworkProperties="true" />
<Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>

<PropertyGroup>
Expand Down
6 changes: 2 additions & 4 deletions src/ProjectTemplates/test/ProjectTemplates.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<ItemGroup>
<HelixContent Include="$(OutputPath)$(TargetFramework)Assets\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
Expand All @@ -54,9 +54,7 @@
<ProjectReference Include="../Web.ItemTemplates/Microsoft.DotNet.Web.ItemTemplates.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="../Web.ProjectTemplates/Microsoft.DotNet.Web.ProjectTemplates.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="../Web.Spa.ProjectTemplates/Microsoft.DotNet.Web.Spa.ProjectTemplates.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(RepoRoot)src\Razor\Microsoft.NET.Sdk.Razor\src\Microsoft.NET.Sdk.Razor.csproj"
ReferenceOutputAssembly="false"
SkipGetTargetFrameworkProperties="true" />
<Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task ManualServerShutdown_NoPipeName_ShutsDownServer()
var repositoryRoot = ProjectDirectory.SearchUp(AppContext.BaseDirectory, "global.json");
var solutionRoot = Path.Combine(repositoryRoot, "src", "Razor");
var toolAssemblyDirectory = Path.Combine(solutionRoot, "Microsoft.AspNetCore.Razor.Tools", "src");
var toolAssemblyPath = Path.Combine(toolAssemblyDirectory, "Microsoft.AspNetCore.Razor.Tools.csproj");
var toolAssemblyPath = Path.Combine(toolAssemblyDirectory, "rzc.csproj");
var projectDirectory = new TestProjectDirectory(solutionRoot, toolAssemblyDirectory, toolAssemblyPath);
var publishDir = Path.Combine(Path.GetTempPath(), "Razor", Path.GetRandomFileName(), "RzcPublish");
var publishResult = await MSBuildProcessManager.RunProcessAsync(projectDirectory, $"/t:Publish /p:PublishDir=\"{publishDir}\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@
<ItemGroup>
<Reference Include="rzc" />
<ProjectReference Include="..\..\test\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib\Microsoft.AspNetCore.Razor.Test.MvcShim.ClassLib.csproj" />

<ProjectReference Include="..\src\Microsoft.NET.Sdk.Razor.csproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<SkipGetTargetFrameworkProperties>true</SkipGetTargetFrameworkProperties>
</ProjectReference>
<Reference Include="Microsoft.NET.Sdk.Razor" ReferenceOutputAssembly="false" SkipGetTargetFrameworkProperties="true" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading