private ITaskItem GetHostItem(string runtimeIdentifier, List <ITaskItem> knownAppHostPacksForTargetFramework, IDictionary <string, string> packagesToDownload, string hostNameWithoutExtension, string itemName, bool isExecutable, bool errorIfNotFound) { var selectedAppHostPack = knownAppHostPacksForTargetFramework.Single(); string appHostRuntimeIdentifiers = selectedAppHostPack.GetMetadata("AppHostRuntimeIdentifiers"); string appHostPackPattern = selectedAppHostPack.GetMetadata("AppHostPackNamePattern"); string appHostPackVersion = selectedAppHostPack.GetMetadata("AppHostPackVersion"); string runtimeIdentifiersToExclude = selectedAppHostPack.GetMetadata(MetadataKeys.ExcludedRuntimeIdentifiers); if (!string.IsNullOrEmpty(RuntimeFrameworkVersion)) { appHostPackVersion = RuntimeFrameworkVersion; } string bestAppHostRuntimeIdentifier = NuGetUtils.GetBestMatchingRidWithExclusion( new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath), runtimeIdentifier, runtimeIdentifiersToExclude.Split(';'), appHostRuntimeIdentifiers.Split(';'), out bool wasInGraph); if (bestAppHostRuntimeIdentifier == null) { if (wasInGraph) { // NETSDK1084: There was no app host for available for the specified RuntimeIdentifier '{0}'. if (errorIfNotFound) { Log.LogError(Strings.NoAppHostAvailable, runtimeIdentifier); } else { Log.LogMessage(Strings.NoAppHostAvailable, runtimeIdentifier); } } else { // NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized. if (errorIfNotFound) { Log.LogError(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier); } else { Log.LogMessage(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier); } } return(null); } else { string hostPackName = appHostPackPattern.Replace("**RID**", bestAppHostRuntimeIdentifier); 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)) { appHostPackPath = Path.Combine(TargetingPackRoot, hostPackName, appHostPackVersion); } if (appHostPackPath != null && Directory.Exists(appHostPackPath)) { // Use AppHost from packs folder appHostItem.SetMetadata(MetadataKeys.PackageDirectory, appHostPackPath); appHostItem.SetMetadata(MetadataKeys.Path, Path.Combine(appHostPackPath, hostRelativePathInPackage)); } else { // C++/CLI does not support package download && dedup error if (!NuGetRestoreSupported && !packagesToDownload.ContainsKey(hostPackName)) { Log.LogError( Strings.TargetingApphostPackMissingCannotRestore, "Apphost", $"{NetCoreTargetingPackRoot}\\{hostPackName}", selectedAppHostPack.GetMetadata("TargetFramework") ?? "", hostPackName, appHostPackVersion ); } // use the first one added if (!packagesToDownload.ContainsKey(hostPackName)) { packagesToDownload.Add(hostPackName, appHostPackVersion); } appHostItem.SetMetadata(MetadataKeys.NuGetPackageId, hostPackName); appHostItem.SetMetadata(MetadataKeys.NuGetPackageVersion, appHostPackVersion); } appHostItem.SetMetadata(MetadataKeys.PathInPackage, hostRelativePathInPackage); appHostItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier); return(appHostItem); } }
private void ProcessRuntimeIdentifier( string runtimeIdentifier, KnownRuntimePack selectedRuntimePack, string runtimePackVersion, List <string> additionalFrameworkReferencesForRuntimePack, HashSet <string> unrecognizedRuntimeIdentifiers, List <ITaskItem> unavailableRuntimePacks, List <ITaskItem> runtimePacks, List <ITaskItem> packagesToDownload, string isTrimmable, bool addRuntimePackAndDownloadIfNecessary) { var runtimeGraph = new RuntimeGraphCache(this).GetRuntimeGraph(RuntimeGraphPath); var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = selectedRuntimePack.RuntimePackRuntimeIdentifiers.Split(';'); var knownFrameworkReferenceRuntimePackExcludedRuntimeIdentifiers = selectedRuntimePack.RuntimePackExcludedRuntimeIdentifiers.Split(';'); string runtimePackRuntimeIdentifier = NuGetUtils.GetBestMatchingRidWithExclusion( runtimeGraph, runtimeIdentifier, knownFrameworkReferenceRuntimePackExcludedRuntimeIdentifiers, knownFrameworkReferenceRuntimePackRuntimeIdentifiers, out bool wasInGraph); if (runtimePackRuntimeIdentifier == null) { if (wasInGraph) { // Report this as an error later, if necessary. This is because we try to download // all available runtime packs in case there is a transitive reference to a shared // framework we don't directly reference. But we don't want to immediately error out // here if a runtime pack that we might not need to reference isn't available for the // targeted RID (e.g. Microsoft.WindowsDesktop.App for a linux RID). var unavailableRuntimePack = new TaskItem(selectedRuntimePack.Name); unavailableRuntimePack.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier); unavailableRuntimePacks.Add(unavailableRuntimePack); } else if (!unrecognizedRuntimeIdentifiers.Contains(runtimeIdentifier)) { // NETSDK1083: The specified RuntimeIdentifier '{0}' is not recognized. Log.LogError(Strings.RuntimeIdentifierNotRecognized, runtimeIdentifier); unrecognizedRuntimeIdentifiers.Add(runtimeIdentifier); } } else if (addRuntimePackAndDownloadIfNecessary) { foreach (var runtimePackNamePattern in selectedRuntimePack.RuntimePackNamePatterns.Split(';')) { string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimePackRuntimeIdentifier); // Look up runtimePackVersion from workload manifests if necessary string resolvedRuntimePackVersion = GetResolvedPackVersion(runtimePackName, runtimePackVersion); string runtimePackPath = GetPackPath(runtimePackName, resolvedRuntimePackVersion); if (runtimePacks != null) { TaskItem runtimePackItem = new TaskItem(runtimePackName); runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageId, runtimePackName); runtimePackItem.SetMetadata(MetadataKeys.NuGetPackageVersion, resolvedRuntimePackVersion); runtimePackItem.SetMetadata(MetadataKeys.FrameworkName, selectedRuntimePack.Name); runtimePackItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimePackRuntimeIdentifier); runtimePackItem.SetMetadata(MetadataKeys.IsTrimmable, isTrimmable); if (selectedRuntimePack.RuntimePackAlwaysCopyLocal) { runtimePackItem.SetMetadata(MetadataKeys.RuntimePackAlwaysCopyLocal, "true"); } if (additionalFrameworkReferencesForRuntimePack != null) { runtimePackItem.SetMetadata(MetadataKeys.AdditionalFrameworkReferences, string.Join(";", additionalFrameworkReferencesForRuntimePack)); } if (runtimePackPath != null) { runtimePackItem.SetMetadata(MetadataKeys.PackageDirectory, runtimePackPath); } runtimePacks.Add(runtimePackItem); } if (runtimePackPath == null) { TaskItem packageToDownload = new TaskItem(runtimePackName); packageToDownload.SetMetadata(MetadataKeys.Version, resolvedRuntimePackVersion); packagesToDownload.Add(packageToDownload); } } } }