Skip to content

Commit e480259

Browse files
ericstjlewing
andauthored
[release/8.0-staging] Remove reference / redistribution of externally provided packages in MSBuild tasks (#113404)
* Backport PackageDownloadAndReference for tasks Backporting a subset of df76a01 to 8.0 * Convert a couple PackageReferences to PackageDownloadAndReference * See how far we get with this * Small cleanups * remove unreachable code * Fix reference * Add another workaround * Another silly fix --------- Co-authored-by: Larry Ewing <[email protected]>
1 parent 29db7c7 commit e480259

File tree

21 files changed

+121
-136
lines changed

21 files changed

+121
-136
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<Project>
2+
3+
<!-- This file supports using PackageDownloadAndReference items.
4+
5+
The PackageDownloadAndReference item is used to download a package and reference it in the project, without restoring the package's dependency closure.
6+
7+
When using PackageDownloadAndReference you are responsible for selecting the correct assets from the package and ensuring that the package and it's
8+
dependencies are available at runtime.
9+
10+
The PackageDownloadAndReference item has the following metadata:
11+
- Folder: The folder in the package where the assembly is located.
12+
- AssemblyName: The name of the assembly to reference.
13+
- Private: Whether the reference should be private (copied to the output directory) or not. Default is false.
14+
15+
A common use case for PackageDownloadAndReference is to reference assemblies provided by MSBuild or the .NET SDK.
16+
-->
17+
18+
<ItemDefinitionGroup>
19+
<PackageDownloadAndReference>
20+
<Folder>lib/$(TargetFramework)</Folder>
21+
<AssemblyName>%(Identity)</AssemblyName>
22+
<Private>false</Private>
23+
</PackageDownloadAndReference>
24+
</ItemDefinitionGroup>
25+
26+
<ItemGroup>
27+
<PackageDownload Include="@(PackageDownloadAndReference)" />
28+
<PackageDownload Update="@(PackageDownloadAndReference)" Version="[%(Version)]"/>
29+
<PackageDownloadAndReference Update="@(PackageDownloadAndReference)" PackageFolder="$([System.String]::new(%(Identity)).ToLowerInvariant())" />
30+
<Reference Include="@(PackageDownloadAndReference->'$(NuGetPackageRoot)%(PackageFolder)/%(Version)/%(Folder)/%(AssemblyName).dll')" />
31+
</ItemGroup>
32+
33+
</Project>

eng/Versions.props

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,18 @@
136136
<SystemSecurityCryptographyOpenSslVersion>5.0.0</SystemSecurityCryptographyOpenSslVersion>
137137
<SystemSecurityPrincipalWindowsVersion>5.0.0</SystemSecurityPrincipalWindowsVersion>
138138
<SystemSecurityPermissionsVersion>7.0.0</SystemSecurityPermissionsVersion>
139-
<!-- The JSON version that's present in minimum MSBuild / VS version that this release is supported on -->
139+
140+
<!-- The following package versions are present in minimum MSBuild / VS version that this release is supported on -->
141+
<MicrosoftBclAsyncInterfacesToolsetVersion>7.0.0</MicrosoftBclAsyncInterfacesToolsetVersion>
142+
<SystemBuffersToolsetVersion>4.5.1</SystemBuffersToolsetVersion>
143+
<SystemCollectionsImmutableToolsetVersion>7.0.0</SystemCollectionsImmutableToolsetVersion>
144+
<SystemMemoryToolsetVersion>4.5.5</SystemMemoryToolsetVersion>
145+
<SystemReflectionMetadataLoadContextToolsetVersion>7.0.0</SystemReflectionMetadataLoadContextToolsetVersion>
146+
<SystemReflectionMetadataToolsetVersion>7.0.0</SystemReflectionMetadataToolsetVersion>
147+
<SystemTextEncodingsWebToolsetVersion>7.0.0</SystemTextEncodingsWebToolsetVersion>
140148
<SystemTextJsonToolsetVersion>7.0.3</SystemTextJsonToolsetVersion>
149+
<SystemThreadingTasksExtensionsToolsetVersion>4.5.4</SystemThreadingTasksExtensionsToolsetVersion>
150+
141151
<SystemTextJsonVersion>8.0.0-rc.1.23406.6</SystemTextJsonVersion>
142152
<SystemRuntimeCompilerServicesUnsafeVersion>6.0.0</SystemRuntimeCompilerServicesUnsafeVersion>
143153
<SystemThreadingAccessControlVersion>7.0.0</SystemThreadingAccessControlVersion>
@@ -178,8 +188,10 @@
178188
<MicrosoftBuildTasksCoreVersion>$(MicrosoftBuildVersion)</MicrosoftBuildTasksCoreVersion>
179189
<MicrosoftBuildFrameworkVersion>$(MicrosoftBuildVersion)</MicrosoftBuildFrameworkVersion>
180190
<MicrosoftBuildUtilitiesCoreVersion>$(MicrosoftBuildVersion)</MicrosoftBuildUtilitiesCoreVersion>
191+
<NugetFrameworksVersion>6.2.4</NugetFrameworksVersion>
181192
<NugetProjectModelVersion>6.2.4</NugetProjectModelVersion>
182193
<NugetPackagingVersion>6.2.4</NugetPackagingVersion>
194+
<NugetVersioningVersion>6.2.4</NugetVersioningVersion>
183195
<DotnetSosVersion>7.0.412701</DotnetSosVersion>
184196
<DotnetSosTargetFrameworkVersion>6.0</DotnetSosTargetFrameworkVersion>
185197
<!-- Testing -->

src/tasks/AndroidAppBuilder/AndroidAppBuilder.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<ItemGroup>
1111
<EmbeddedResource Include="Templates\*.*" />
1212
</ItemGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
15-
</ItemGroup>
1613
<ItemGroup>
1714
<ProjectReference Include="$(RepoRoot)src\tasks\MobileBuildTasks\MobileBuildTasks.csproj" />
1815
</ItemGroup>

src/tasks/AotCompilerTask/MonoAOTCompiler.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@
1111
<NoWarn Condition="$(TargetFramework.StartsWith('net4'))">$(NoWarn),CS8604,CS8602</NoWarn>
1212
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1313
</PropertyGroup>
14-
<ItemGroup>
15-
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
16-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
17-
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
18-
</ItemGroup>
1914
<ItemGroup>
2015
<Compile Include="MonoAOTCompiler.cs" />
2116
<Compile Include="..\Common\CompilerCache.cs" />

src/tasks/AppleAppBuilder/AppleAppBuilder.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<ItemGroup>
1111
<EmbeddedResource Include="Templates\*.*" />
1212
</ItemGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
15-
</ItemGroup>
1613
<ItemGroup>
1714
<Compile Include="AppleAppBuilder.cs" />
1815
<Compile Include="..\Common\Utils.cs" />

src/tasks/Crossgen2Tasks/Crossgen2Tasks.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
<NoWarn Condition="$(TargetFramework.StartsWith('net4'))">$(NoWarn),CS8604,CS8602</NoWarn>
1010
</PropertyGroup>
1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
13-
<PackageReference Include="NuGet.ProjectModel" Version="$(NugetProjectModelVersion)" />
12+
<!-- Bring in references for these assemblies which are provided by the SDK.
13+
We do this to avoid bringing the package closure for assemblies we don't use here. -->
14+
<PackageDownloadAndReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonVersion)" Folder="lib/netstandard2.0" />
15+
<PackageDownloadAndReference Include="NuGet.Frameworks" Version="$(NugetFrameworksVersion)" Folder="lib/netstandard2.0" />
16+
<PackageDownloadAndReference Include="NuGet.Packaging" Version="$(NugetPackagingVersion)" Folder="lib/netstandard2.0" />
17+
<PackageDownloadAndReference Include="NuGet.ProjectModel" Version="$(NugetProjectModelVersion)" Folder="lib/netstandard2.0" />
18+
<PackageDownloadAndReference Include="NuGet.Versioning" Version="$(NugetVersioningVersion)" Folder="lib/netstandard2.0" />
1419
</ItemGroup>
1520
<ItemGroup>
1621
<Content Include="Microsoft.NET.CrossGen.targets">

src/tasks/Directory.Build.targets

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project>
2+
<ItemGroup>
3+
<!-- reference MSBuild directly to avoid bringing in it's package closure. These all represent assemblies available to tasks and provided by MSBuild -->
4+
<PackageDownloadAndReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" Folder="ref/net472" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net472'))" />
5+
<PackageDownloadAndReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" Folder="ref/net8.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
6+
<PackageDownloadAndReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" Folder="ref/net472" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net472'))" />
7+
<PackageDownloadAndReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" Folder="ref/net8.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
8+
<PackageDownloadAndReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCoreVersion)" Folder="ref/net472" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net472'))" />
9+
<PackageDownloadAndReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCoreVersion)" Folder="ref/net8.0" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
10+
<PackageDownloadAndReference Include="System.Reflection.MetadataLoadContext" Version="$(SystemReflectionMetadataLoadContextToolsetVersion)" Folder="lib/netstandard2.0" />
11+
</ItemGroup>
12+
13+
<ItemGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net462'))">
14+
<!-- These assemblies are made available by MSBuild on .NET Framework -->
15+
<PackageDownloadAndReference Include="Microsoft.Bcl.AsyncInterfaces" Version="$(MicrosoftBclAsyncInterfacesToolsetVersion)" Folder="lib/net462" />
16+
<PackageDownloadAndReference Include="System.Buffers" Version="$(SystemBuffersToolsetVersion)" Folder="lib/net461" />
17+
<PackageDownloadAndReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableToolsetVersion)" Folder="lib/net462" />
18+
<PackageDownloadAndReference Include="System.Memory" Version="$(SystemMemoryToolsetVersion)" Folder="lib/net461" />
19+
<PackageDownloadAndReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataToolsetVersion)" Folder="lib/net462" />
20+
<PackageDownloadAndReference Include="System.Text.Encodings.Web" Version="$(SystemTextEncodingsWebToolsetVersion)" Folder="lib/net462" />
21+
<PackageDownloadAndReference Include="System.Text.Json" Version="$(SystemTextJsonToolsetVersion)" Folder="lib/net462" />
22+
<PackageDownloadAndReference Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsToolsetVersion)" Folder="lib/net461" />
23+
</ItemGroup>
24+
25+
<Import Project="$(RepositoryEngineeringDir)PackageDownloadAndReference.targets" />
26+
27+
<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets, $(MSBuildThisFileDirectory)..))" />
28+
</Project>

src/tasks/LibraryBuilder/LibraryBuilder.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<ItemGroup>
1111
<EmbeddedResource Include="Templates\*.*" />
1212
</ItemGroup>
13-
<ItemGroup>
14-
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(MicrosoftBuildTasksCoreVersion)" />
15-
</ItemGroup>
1613
<ItemGroup>
1714
<ProjectReference Include="$(RepoRoot)src\tasks\MobileBuildTasks\MobileBuildTasks.csproj" />
1815
</ItemGroup>

src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
<ItemGroup>
2020
<Compile Include="..\Common\Utils.cs" />
2121
<Compile Include="..\WasmAppBuilder\WebcilConverter.cs" />
22-
23-
<PackageReference Include="Microsoft.Build" Version="$(MicrosoftBuildVersion)" />
24-
<PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" ExcludeAssets="runtime" />
25-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(MicrosoftBuildUtilitiesCoreVersion)" ExcludeAssets="runtime" />
26-
22+
2723
<ProjectReference Include="..\Microsoft.NET.WebAssembly.Webcil\Microsoft.NET.WebAssembly.Webcil.csproj" />
2824
</ItemGroup>
2925

src/tasks/Microsoft.NET.WebAssembly.Webcil/Microsoft.NET.WebAssembly.Webcil.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414
<IsShippingPackage>false</IsShippingPackage>
1515
</PropertyGroup>
1616

17-
<ItemGroup>
18-
<!-- we need to keep the version of System.Reflection.Metadata in sync with dotnet/msbuild and dotnet/sdk -->
19-
<PackageReference Include="System.Memory" Version="$(SystemMemoryVersion)" />
20-
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
21-
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
22-
</ItemGroup>
23-
2417
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETFramework'">
2518
<Compile Include="$(CoreLibSharedDir)System\Diagnostics\CodeAnalysis\NullableAttributes.cs" Link="System\Diagnostics\CodeAnalysis\NullableAttributes.cs" />
2619
<Compile Include="..\Common\IsExternalInit.cs" />

0 commit comments

Comments
 (0)