From bb61c2ee95a6b938fa8ad92363a32f9f3ebe2d8c Mon Sep 17 00:00:00 2001 From: Viktor Hofer Date: Mon, 21 Nov 2022 14:09:34 +0100 Subject: [PATCH] Add switch to disable apphost pack restore (#29137) * Add switch to disable apphost pack restore Contributes to https://github.com/dotnet/runtime/issues/58109 In dotnet/runtime we live build targeting packs, runtime packs and app host packs. For the former two, switches already exist to disable nuget restore: - EnableTargetingPackDownload - EnableRuntimePackDownload The latter one doesn't yet have such a switch and therefore is always restored by NuGet. In the cases where want to use the live built apphost pack, restore fails, i.e. from a runtime build: `artifacts/bin/trimmingTests/projects/Microsoft.Extensions.DependencyInjection.TrimmingTests/ActivatorUtilitiesTests/osx-x64/project.csproj(0,0): error NU1102: (NETCORE_ENGINEERING_TELEMETRY=Build) Unable to find package Microsoft.NETCore.App.Host.osx-x64 with version (= 8.0.0)` --- src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs | 5 +++-- .../Microsoft.NET.Sdk.FrameworkReferenceResolution.targets | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs index eb0cee610880..c48734d35350 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolveAppHosts.cs @@ -54,6 +54,8 @@ public class ResolveAppHosts : TaskBase public bool NuGetRestoreSupported { get; set; } = true; public string NetCoreTargetingPackRoot { get; set; } + + public bool EnableAppHostPackDownload { get; set; } = true; [Output] public ITaskItem[] PackagesToDownload { get; set; } @@ -276,7 +278,6 @@ private ITaskItem GetHostItem(string runtimeIdentifier, string hostRelativePathInPackage = Path.Combine("runtimes", bestAppHostRuntimeIdentifier, "native", hostNameWithoutExtension + (isExecutable ? ExecutableExtension.ForRuntimeIdentifier(bestAppHostRuntimeIdentifier) : ".dll")); - TaskItem appHostItem = new TaskItem(itemName); string appHostPackPath = null; if (!string.IsNullOrEmpty(TargetingPackRoot)) @@ -289,7 +290,7 @@ private ITaskItem GetHostItem(string runtimeIdentifier, appHostItem.SetMetadata(MetadataKeys.PackageDirectory, appHostPackPath); appHostItem.SetMetadata(MetadataKeys.Path, Path.Combine(appHostPackPath, hostRelativePathInPackage)); } - else + else if (EnableAppHostPackDownload) { // C++/CLI does not support package download && dedup error if (!NuGetRestoreSupported && !packagesToDownload.ContainsKey(hostPackName)) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets index c66580e5e4e5..599cf7c6e11a 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets @@ -147,6 +147,7 @@ Copyright (c) .NET Foundation. All rights reserved. RuntimeGraphPath="$(BundledRuntimeIdentifierGraphFile)" KnownAppHostPacks="@(KnownAppHostPack)" NuGetRestoreSupported="$(_NuGetRestoreSupported)" + EnableAppHostPackDownload="$(EnableAppHostPackDownload)" NetCoreTargetingPackRoot="$(NetCoreTargetingPackRoot)">