Skip to content
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

Use Roslyn to create ref/ assemblies #23403

Merged
merged 10 commits into from
Jul 17, 2020
10 changes: 9 additions & 1 deletion eng/Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@
</ItemGroup>

<Choose>
<!-- Project selection can be overridden on the command line by passing in -projects -->
<!-- Project selection can be overridden on the command line by passing in -projects. -->
<When Condition="'$(ProjectToBuild)' != ''">
<ItemGroup>
<!-- Include RTMVersions.csproj unless this invocation is building RepoTasks.csproj or won't compile C#. -->
<ProjectToBuild Include="$(RepoRoot)eng\RTMVersions\RTMVersions.csproj"
Exclude="@(ProjectToExclude)"
Condition=" $(ProjectToBuild.EndsWith('.csproj')) AND !$(ProjectToBuild.EndsWith('RepoTasks.csproj')) " />
<ProjectToBuild Include="$(ProjectToBuild)" Exclude="@(ProjectToExclude);$(RepoRoot)**\bin\**\*;$(RepoRoot)**\obj\**\*">
<RestoreInParallel Condition="'%(Extension)' == '.npmproj'">false</RestoreInParallel>
</ProjectToBuild>
Expand Down Expand Up @@ -121,8 +125,11 @@
<!--
Use caution to avoid deep recursion. If the globbing pattern picks up something which exceeds MAX_PATH,
the entire pattern will silently fail to evaluate correctly.

Include RTMVersions.csproj when building any managed projects.
-->
<DotNetProjects Include="
$(RepoRoot)eng\RTMVersions\RTMVersions.csproj;
$(RepoRoot)src\Framework\App.Ref\src\Microsoft.AspNetCore.App.Ref.csproj;
$(RepoRoot)src\Framework\App.Runtime\src\Microsoft.AspNetCore.App.Runtime.csproj;
$(RepoRoot)src\Framework\App.Ref.Internal\src\Microsoft.AspNetCore.App.Ref.Internal.csproj;
Expand Down Expand Up @@ -170,6 +177,7 @@
$(RepoRoot)**\obj\**\*;"
Condition=" '$(BuildMainlyReferenceProviders)' != 'true' " />
<DotNetProjects Include="
$(RepoRoot)eng\RTMVersions\RTMVersions.csproj;
$(RepoRoot)src\DefaultBuilder\**\src\*.csproj;
$(RepoRoot)src\Features\JsonPatch\**\src\*.csproj;
$(RepoRoot)src\DataProtection\**\src\*.csproj;
Expand Down
6 changes: 6 additions & 0 deletions eng/RTMVersions/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<!-- Minimize what gets set to avoid useless references in this simple project. -->
<Import Project="..\Common.props" />
<Import Project="..\Versions.props" />
<Import Project="..\Dependencies.props" />
</Project>
1 change: 1 addition & 0 deletions eng/RTMVersions/Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<Project />
28 changes: 28 additions & 0 deletions eng/RTMVersions/RTMVersions.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<!--
Gather project references for compilation against RTM packages. %(RTMVersion) is set for about a dozen packages
in all servicing builds. Cannot reference two versions of a package, mandating this separate package.
-->
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
Copy link
Member

Choose a reason for hiding this comment

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

Can't be parameterized?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not unless I remove the Directory.Build.* files. I'll test out whether that causes any problems after getting this in and doing the merge to 'master'. It's no worse at the moment than the hard-coded TFMs in (say) our project templates. But, I'll clean it up next if possible.

<IsPackable>false</IsPackable>

<!-- Don't bother building anything here. We only need to ensure the RTM packages are on disk. -->
<DebugType>none</DebugType>
<IncludeBuildOutput>false</IncludeBuildOutput>
<CopyBuildOutputToPublishDirectory>false</CopyBuildOutputToPublishDirectory>
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>false</CopyOutputSymbolsToOutputDirectory>
<GenerateDependencyFile>false</GenerateDependencyFile>

<!-- This project should not be referenced via the `<Reference>` implementation. -->
<IsProjectReferenceProvider>false</IsProjectReferenceProvider>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="@(LatestPackageReference->HasMetadata('RTMVersion'))" Version="%(RTMVersion)" />
</ItemGroup>

<!-- Arcade SDK calls Test target on every project in the repo but provides an empty fallback. Do same here. -->
<Target Name="Test" />
</Project>
37 changes: 37 additions & 0 deletions eng/targets/ResolveReferences.targets
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,43 @@
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>

<!--
Muck with @(ResolvedCompileFileDefinitions) items between generation and use in order to compile against RTM lib/
or ref/ assemblies. The approach works for all TFMs because it happens after a specific assembly is chosen for
compilation; no need to restrict this to (say) the default TFM.

Condition checks for RTMVersions.csproj.nuget.g.props file only to ensure restore operation is complete.

This target could get confused if the layout changes for one of the dozen special-cased packages during servicing.
E.g. ResolvePackageAssets picks a compatible assembly from the 5.0.1 package and _UseRTMReferenceAssemblies
changes the path to one not present in the 5.0.0 package. Fortunately, this will break the build with complaints
about the "invalid strong name".
-->
<Target Name="_UseRTMReferenceAssemblies"
Condition=" '$(EnableCustomReferenceResolution)' == 'true' AND EXISTS('$(RepoRoot)eng\RTMVersions\obj\RTMVersions.csproj.nuget.g.props') "
BeforeTargets="GenerateBuildDependencyFile;GeneratePublishDependencyFile;ILLink;ResolveLockFileReferences"
DependsOnTargets="ResolvePackageAssets">
<JoinItems Left="@(ResolvedCompileFileDefinitions)"
Right="@(LatestPackageReference->HasMetadata('RTMVersion'))"
LeftKey="Filename"
ItemSpecToUse="Left"
LeftMetadata="*"
RightMetadata="RTMVersion;Version">
<Output TaskParameter="JoinResult" ItemName="_ResolvedCompileFileDefinitionsToChange" />
</JoinItems>

<ItemGroup>
<ResolvedCompileFileDefinitions Remove="@(_ResolvedCompileFileDefinitionsToChange)" />

<!-- Ignore %(NuGetPackageVersion) when doing substitution because some projects use downlevel packages. -->
<_ResolvedCompileFileDefinitionsToChange
HintPath="$([System.String]::new('%(Identity)').Replace('\%(Version)\', '\%(RTMVersion)\').Replace('/%(Version)/', '/%(RTMVersion)/'))" />
<ResolvedCompileFileDefinitions Include="@(_ResolvedCompileFileDefinitionsToChange -> '%(HintPath)')" />

<_ResolvedCompileFileDefinitionsToChange Remove="@(_ResolvedCompileFileDefinitionsToChange)" />
</ItemGroup>
</Target>

<PropertyGroup>
<_CompileTfmUsingReferenceAssemblies>false</_CompileTfmUsingReferenceAssemblies>
<_CompileTfmUsingReferenceAssemblies
Expand Down