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
31 changes: 31 additions & 0 deletions eng/targets/PackageDownloadAndReference.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project>

<!--
Based on https://github.com/dotnet/runtime/blob/9893d145ebb61ae592afa1a64baa2f6f094b1f6b/eng/PackageDownloadAndReference.targets

These file supports using PackageDownloadAndReference items.
The PackageDownloadAndReference item is used to download a package and reference it in the project, without restoring the package's dependency closure.
When using PackageDownloadAndReference you are responsible for selecting the correct assets from the package and ensuring that the package and it's
dependencies are available at runtime.
The PackageDownloadAndReference item has the following metadata:
- Folder: The folder in the package where the assembly is located.
- AssemblyName: The name of the assembly to reference.
- Private: Whether the reference should be private (copied to the output directory) or not. Default is false.
A common use case for PackageDownloadAndReference is to reference assemblies provided by MSBuild or the .NET SDK.
-->

<ItemDefinitionGroup>
<PackageDownloadAndReference>
<Folder>lib/$(TargetFramework)</Folder>
<Private>false</Private>
</PackageDownloadAndReference>
</ItemDefinitionGroup>

<ItemGroup>
<PackageDownload Include="@(PackageDownloadAndReference)" />
<PackageDownload Update="@(PackageDownloadAndReference)" Version="[%(Version)]"/>
<PackageDownloadAndReference Update="@(PackageDownloadAndReference)" PackageFolder="$([System.String]::new(%(Identity)).ToLowerInvariant())" AssemblyName="%(Identity)" />
<Reference Include="@(PackageDownloadAndReference->'$(NuGetPackageRoot)%(PackageFolder)/%(Version)/%(Folder)/%(AssemblyName).dll')" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,32 @@
a RuntimeIdentifier given to us, since we really don't want to accidentally pick up platform specific binaries since we also have to run on Mono.
-->
<PlatformTarget>AnyCPU</PlatformTarget>

<!--
We specifically reference Microsoft.Build 17.3.4, since it's the oldest version still compatible $(NetRoslynBuildHostNetCoreVersion).
The version targeted is only used for build time, since we use MSBuildLocator to discover the proper version at runtime.
-->
<_MsbuildVersion>17.3.4</_MsbuildVersion>
</PropertyGroup>
<ItemGroup Condition="'$(DotnetBuildFromSource)' == 'true'">
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 reason we wouldn't just do the PackageDownloadAndReference for source build too? I guess maybe it's going to break source build because it doesn't know how to redirect it to the source built version?

Copy link
Member Author

Choose a reason for hiding this comment

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

From a comment on the original PR:

I see what happened, in SBRP the net472 asset is missing: https://github.com/dotnet/source-build-reference-packages/tree/main/src/referencePackages/src/microsoft.build.framework/17.3.4/ref

I learned that source build isn't really meant to have .NETFramework targets so that might not have been the root cause, but I bet there is something like that - where the SBRP packages differ from the real packages in a way that causes an error

Copy link
Member Author

Choose a reason for hiding this comment

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

@jasonmalinowski Since we know this is working in main, I would prefer not to try anything new in the servicing PR.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good.

<PackageReference Include="Microsoft.Build" VersionOverride="$(_MsbuildVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" VersionOverride="$(_MsbuildVersion)" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Tasks.Core" VersionOverride="$(_MsbuildVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Utilities.Core" VersionOverride="$(_MsbuildVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(DotnetBuildFromSource)' != 'true'">
<!-- Reference MSBuild directly to avoid redistributing its package closure and including the dependencies in deps.json file. -->
<PackageDownloadAndReference Include="Microsoft.Build" Version="$(_MsbuildVersion)" Folder="ref/$(TargetFramework)" />
<PackageDownloadAndReference Include="Microsoft.Build.Framework" Version="$(_MsbuildVersion)" Folder="ref/$(TargetFramework)" />
<PackageDownloadAndReference Include="Microsoft.Build.Tasks.Core" Version="$(_MsbuildVersion)" Folder="ref/$(TargetFramework)" />
<PackageDownloadAndReference Include="Microsoft.Build.Utilities.Core" Version="$(_MsbuildVersion)" Folder="ref/$(TargetFramework)" />
</ItemGroup>
<ItemGroup>
<!-- We specifically reference Microsoft.Build 17.3.4, since it's the oldest version still compatible net6.0. The version targeted is only used for build time, since
we use MSBuildLocator to discover the proper version at runtime. -->
<PackageReference Include="Microsoft.Build" VersionOverride="17.3.4" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" VersionOverride="17.3.4" ExcludeAssets="Runtime" />
<PackageReference Include="Microsoft.Build.Tasks.Core" VersionOverride="17.3.4" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Utilities.Core" VersionOverride="17.3.4" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Locator" PrivateAssets="All" />
<PackageReference Include="System.Text.Json" VersionOverride="8.0.5" PrivateAssets="All" Condition="'$(DotnetBuildFromSource)' != 'true'"/>
<PackageReference Include="System.CommandLine" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="System.CommandLine" />
<PackageReference Include="System.Text.Json" VersionOverride="8.0.5" PrivateAssets="All" Condition="'$(DotnetBuildFromSource)' != 'true'"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
Expand All @@ -49,18 +62,18 @@
<PublicAPI Include="PublicAPI.Shipped.txt" />
<PublicAPI Include="PublicAPI.Unshipped.txt" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.LanguageServer" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests" />
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" Key="$(MoqPublicKey)" LoadsWithinVisualStudio="false" />
</ItemGroup>

<ItemGroup>
<None Include="Rpc\Readme.md" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Update="WorkspaceMSBuildBuildHostResources.resx" GenerateSource="true" />
</ItemGroup>
Expand All @@ -76,4 +89,6 @@
</ProjectDepsJsonFile>
</ItemGroup>
</Target>

<Import Project="$(RepositoryEngineeringDir)targets\PackageDownloadAndReference.targets"/>
</Project>
Loading