public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencySets.Any() && !FrameworkReferences.Any()) { throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage); } ValidateDependencySets(Version, DependencySets); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); using (Package package = Package.Open(stream, FileMode.Create)) { // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files)); // Write the files to the package WriteFiles(package); // Copy the metadata properties back to the package package.PackageProperties.Creator = String.Join(",", Authors); package.PackageProperties.Description = Description; package.PackageProperties.Identifier = Id; package.PackageProperties.Version = Version.ToString(); package.PackageProperties.Language = Language; package.PackageProperties.Keywords = ((IPackageMetadata)this).Tags; package.PackageProperties.Title = Title; package.PackageProperties.Subject = "NuGet Package Explorer"; } }
public void Populate(ManifestMetadata manifestMetadata) { IPackageMetadata metadata = manifestMetadata; Id = metadata.Id; Version = metadata.Version; Title = metadata.Title; Authors.AddRange(metadata.Authors); Owners.AddRange(metadata.Owners); IconUrl = metadata.IconUrl; LicenseUrl = metadata.LicenseUrl; ProjectUrl = metadata.ProjectUrl; RequireLicenseAcceptance = metadata.RequireLicenseAcceptance; // DevelopmentDependency = metadata.DevelopmentDependency; Description = metadata.Description; Summary = metadata.Summary; ReleaseNotes = metadata.ReleaseNotes; Language = metadata.Language; Copyright = metadata.Copyright; MinClientVersion = metadata.MinClientVersion; if (metadata.Tags != null) { Tags.AddRange(ParseTags(metadata.Tags)); } DependencySets.AddRange(metadata.DependencySets); FrameworkReferences.AddRange(metadata.FrameworkAssemblies); if (manifestMetadata.ReferenceSets != null) { PackageAssemblyReferences.AddRange(manifestMetadata.ReferenceSets.Select(r => new PackageReferenceSet(r))); } }
private List <FrameworkAssemblyReference> GetFrameworkAssemblies() { return((from fr in FrameworkReferences.NullAsEmpty() orderby fr.ItemSpec, StringComparer.Ordinal select new FrameworkAssemblyReference(fr.ItemSpec, new[] { fr.GetTargetFramework() }) ).Distinct(frameworkAssemblyReferenceComparer).ToList()); }
public bool Equals(LockFileTargetLibrary other) { if (other == null) { return(false); } if (Object.ReferenceEquals(this, other)) { return(true); } return(string.Equals(Name, other.Name) && VersionComparer.Default.Equals(Version, other.Version) && string.Equals(Type, other.Type, StringComparison.Ordinal) && string.Equals(Framework, other.Framework, StringComparison.Ordinal) && Dependencies.OrderedEquals(other.Dependencies, dependency => dependency.Id, StringComparer.OrdinalIgnoreCase) && FrameworkAssemblies.OrderedEquals(other.FrameworkAssemblies, s => s, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase) && FrameworkReferences.OrderedEquals(other.FrameworkReferences, s => s, StringComparer.OrdinalIgnoreCase, StringComparer.OrdinalIgnoreCase) && RuntimeAssemblies.OrderedEquals(other.RuntimeAssemblies, item => item.Path, StringComparer.OrdinalIgnoreCase) && ResourceAssemblies.OrderedEquals(other.ResourceAssemblies, item => item.Path, StringComparer.OrdinalIgnoreCase) && CompileTimeAssemblies.OrderedEquals(other.CompileTimeAssemblies, item => item.Path, StringComparer.OrdinalIgnoreCase) && NativeLibraries.OrderedEquals(other.NativeLibraries, item => item.Path, StringComparer.OrdinalIgnoreCase) && ContentFiles.OrderedEquals(other.ContentFiles, item => item.Path, StringComparer.OrdinalIgnoreCase) && RuntimeTargets.OrderedEquals(other.RuntimeTargets, item => item.Path, StringComparer.OrdinalIgnoreCase) && Build.OrderedEquals(other.Build, item => item.Path, StringComparer.OrdinalIgnoreCase) && BuildMultiTargeting.OrderedEquals(other.BuildMultiTargeting, item => item.Path, StringComparer.OrdinalIgnoreCase) && ToolsAssemblies.OrderedEquals(other.ToolsAssemblies, item => item.Path, StringComparer.OrdinalIgnoreCase) && EmbedAssemblies.OrderedEquals(other.EmbedAssemblies, item => item.Path, StringComparer.OrdinalIgnoreCase)); }
protected override void ExecuteCore() { var runtimePackAssets = new List <ITaskItem>(); HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase); foreach (var unavailableRuntimePack in UnavailableRuntimePacks) { if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec)) { // This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier // NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'. Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec, unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier)); } } HashSet <string> processedRuntimePackRoots = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var runtimePack in ResolvedRuntimePacks) { if (!frameworkReferenceNames.Contains(runtimePack.GetMetadata(MetadataKeys.FrameworkName))) { // This is a runtime pack for a shared framework that ultimately wasn't referenced, so don't include its assets continue; } string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory); if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot)) { // If we do the work in https://github.com/dotnet/cli/issues/10528, // then we should add a new error message here indicating that the runtime pack hasn't // been downloaded, and that restore should be run with that runtime identifier. Log.LogError(Strings.NoRuntimePackAvailable, runtimePack.ItemSpec, runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier)); } if (!processedRuntimePackRoots.Add(runtimePackRoot)) { // We already added assets from this runtime pack (which can happen with FrameworkReferences to different // profiles of the same shared framework) continue; } var runtimeListPath = Path.Combine(runtimePackRoot, "data", "RuntimeListList.xml"); if (File.Exists(runtimeListPath)) { AddRuntimePackAssetsFromManifest(runtimePackAssets, runtimePackRoot, runtimeListPath, runtimePack); } else { runtimePackAssets.AddRange(GetRuntimePackAssetsFromConvention(runtimePackRoot, runtimePack)); } } RuntimePackAssets = runtimePackAssets.ToArray(); }
public void AddFrameworkReference(string name) { if (FrameworkReferences.Contains(name)) { throw new InvalidOperationException("Cannot add existing reference. That would be a COMException in VS"); } FrameworkReferences.Add(name); }
private List <ManifestFrameworkAssembly> GetFrameworkAssemblies() { return((from fr in FrameworkReferences.NullAsEmpty() select new ManifestFrameworkAssembly { AssemblyName = fr.ItemSpec, TargetFramework = fr.GetTargetFramework().GetShortFrameworkName(), }).ToList()); }
public Task AddFrameworkReferenceAsync(string name, string packageId) { if (FrameworkReferences.Contains(name)) { throw new InvalidOperationException("Cannot add existing reference. That would be a COMException in VS"); } FrameworkReferences.Add(name); return(Task.CompletedTask); }
private void ReadManifest(Stream stream, string basePath) { // Deserialize the document and extract the metadata Manifest manifest = Manifest.ReadFrom(stream); IPackageMetadata metadata = manifest.Metadata; Id = metadata.Id; Version = metadata.Version; Title = metadata.Title; Authors.AddRange(metadata.Authors); Owners.AddRange(metadata.Owners); IconUrl = metadata.IconUrl; LicenseUrl = metadata.LicenseUrl; ProjectUrl = metadata.ProjectUrl; RequireLicenseAcceptance = metadata.RequireLicenseAcceptance; Description = metadata.Description; Summary = metadata.Summary; ReleaseNotes = metadata.ReleaseNotes; Language = metadata.Language; Copyright = metadata.Copyright; Serviceable = metadata.Serviceable; MinClientVersion = metadata.MinClientVersion; DevelopmentDependency = metadata.DevelopmentDependency; if (metadata.Tags != null) { Tags.AddRange(ParseTags(metadata.Tags)); } DependencySets.AddRange(metadata.DependencySets); FrameworkReferences.AddRange(metadata.FrameworkAssemblies); if (metadata.PackageAssemblyReferences != null) { PackageAssemblyReferences.AddRange(metadata.PackageAssemblyReferences); } // If there's no base path then ignore the files node if (basePath != null) { if (manifest.Files == null) { AddFiles(basePath, @"**\*.*", null); } else { foreach (ManifestFile file in manifest.Files) { AddFiles(basePath, file.Source, file.Target, file.Exclude); } } } }
protected override void ExecuteCore() { foreach (var packageReference in PackageReferences) { if (packageReference.ItemSpec.Equals(PackageReferenceToReplace, StringComparison.OrdinalIgnoreCase)) { ShouldRemovePackageReference = true; if (!FrameworkReferences.Any(fr => fr.ItemSpec.Equals(FrameworkReferenceToUse, StringComparison.OrdinalIgnoreCase))) { ShouldAddFrameworkReference = true; } } } }
public void Populate(ManifestMetadata manifestMetadata) { IPackageMetadata metadata = manifestMetadata; Id = metadata.Id; Version = metadata.Version; Title = metadata.Title; Authors.AddRange(metadata.Authors); Owners.AddRange(metadata.Owners); IconUrl = metadata.IconUrl; LicenseUrl = metadata.LicenseUrl; ProjectUrl = metadata.ProjectUrl; RequireLicenseAcceptance = metadata.RequireLicenseAcceptance; DevelopmentDependency = metadata.DevelopmentDependency; Description = metadata.Description; Summary = metadata.Summary; ReleaseNotes = metadata.ReleaseNotes; Language = metadata.Language; Copyright = metadata.Copyright; MinClientVersion = metadata.MinClientVersion; ContentFiles = new Collection <ManifestContentFiles>(manifestMetadata.ContentFiles); ProjectSourceUrl = metadata.ProjectSourceUrl; PackageSourceUrl = metadata.PackageSourceUrl; DocsUrl = metadata.DocsUrl; WikiUrl = metadata.WikiUrl; MailingListUrl = metadata.MailingListUrl; BugTrackerUrl = metadata.BugTrackerUrl; Replaces.AddRange(metadata.Replaces); Provides.AddRange(metadata.Provides); Conflicts.AddRange(metadata.Conflicts); SoftwareDisplayName = metadata.SoftwareDisplayName; SoftwareDisplayVersion = metadata.SoftwareDisplayVersion; if (metadata.Tags != null) { Tags.AddRange(ParseTags(metadata.Tags)); } DependencySets.AddRange(metadata.DependencySets); FrameworkReferences.AddRange(metadata.FrameworkAssemblies); if (manifestMetadata.ReferenceSets != null) { PackageAssemblyReferences.AddRange(manifestMetadata.ReferenceSets.Select(r => new PackageReferenceSet(r))); } }
/// <summary> /// Convert node with code Callvirt. /// /// For arrays: intercepts call to IEnumerable.IEnumerable_GetEnumerator generated /// by foreach statements and swaps them out to System.Array.GetEnumerator. /// /// This call will then at a later compilation stage be replaced with the final destination. /// </summary> private static void ConvertCallvirtIEnumerable(AssemblyCompiler compiler, AstExpression node, XTypeSystem typeSystem) { var targetMethodRef = ((XMethodReference)node.Operand); var targetMethodDefOrRef = targetMethodRef; if (targetMethodDefOrRef.DeclaringType.IsSystemCollectionsIEnumerable() && targetMethodDefOrRef.Name == "IEnumerable_GetEnumerator" && node.Arguments.Count == 1) { var argument = node.Arguments[0]; if (!argument.InferredType.IsArray) { return; } // swap the call to System.Array var systemArray = compiler.GetDot42InternalType("System", "Array").Resolve(); var getEnumerator = systemArray.Methods.First(x => x.Name == "GetEnumerator" && !x.IsStatic && x.Parameters.Count == 0); node.Operand = getEnumerator; } else if (targetMethodDefOrRef.DeclaringType.IsSystemCollectionsIEnumerableT() && targetMethodDefOrRef.Name.EndsWith("_GetEnumerator") && node.Arguments.Count == 1) { var argument = node.Arguments[0]; if (!argument.InferredType.IsArray) { return; } var elementType = argument.InferredType.ElementType; // Use As...Enumerable to convert var asEnumerableName = FrameworkReferences.GetAsEnumerableTMethodName(elementType); var compilerHelper = compiler.GetDot42InternalType(InternalConstants.CompilerHelperName).Resolve(); var asEnumerableMethod = compilerHelper.Methods.First(x => x.Name == asEnumerableName); var call = new AstExpression(node.SourceLocation, AstCode.Call, asEnumerableMethod, argument) { InferredType = asEnumerableMethod.ReturnType }; node.Arguments[0] = call; argument.ExpectedType = argument.InferredType; } }
public void Populate(ManifestMetadata manifestMetadata) { IPackageMetadata metadata = manifestMetadata; Id = metadata.Id; Version = metadata.Version; Title = metadata.Title; Authors.AddRange(metadata.Authors); Owners.AddRange(metadata.Owners); IconUrl = metadata.IconUrl; LicenseUrl = metadata.LicenseUrl; ProjectUrl = metadata.ProjectUrl; RequireLicenseAcceptance = metadata.RequireLicenseAcceptance; DevelopmentDependency = metadata.DevelopmentDependency; Serviceable = metadata.Serviceable; Description = metadata.Description; Summary = metadata.Summary; ReleaseNotes = metadata.ReleaseNotes; Language = metadata.Language; Copyright = metadata.Copyright; MinClientVersion = metadata.MinClientVersion; Repository = metadata.Repository; ContentFiles = new Collection <ManifestContentFiles>(manifestMetadata.ContentFiles.ToList()); LicenseMetadata = metadata.LicenseMetadata; Icon = metadata.Icon; if (metadata.Tags != null) { Tags.AddRange(ParseTags(metadata.Tags)); } DependencyGroups.AddRange(metadata.DependencyGroups); FrameworkReferences.AddRange(metadata.FrameworkReferences); FrameworkReferenceGroups.AddRange(metadata.FrameworkReferenceGroups); if (manifestMetadata.PackageAssemblyReferences != null) { PackageAssemblyReferences.AddRange(manifestMetadata.PackageAssemblyReferences); } if (manifestMetadata.PackageTypes != null) { PackageTypes = new Collection <PackageType>(metadata.PackageTypes.ToList()); } }
public override int GetHashCode() { var hashCode = new HashCodeCombiner(); hashCode.AddObject(FrameworkName); hashCode.AddObject(AssetTargetFallback); hashCode.AddSequence(Dependencies.OrderBy(s => s.Name, StringComparer.OrdinalIgnoreCase)); hashCode.AddSequence(Imports); hashCode.AddObject(Warn); hashCode.AddSequence(DownloadDependencies.OrderBy(s => s.Name, StringComparer.OrdinalIgnoreCase)); hashCode.AddSequence(FrameworkReferences.OrderBy(s => s.Name, ComparisonUtility.FrameworkReferenceNameComparer)); if (RuntimeIdentifierGraphPath != null) { hashCode.AddObject(PathUtility.GetStringComparerBasedOnOS().GetHashCode(RuntimeIdentifierGraphPath)); } hashCode.AddSequence(CentralPackageVersions.Values.OrderBy(s => s.Name, StringComparer.OrdinalIgnoreCase)); hashCode.AddStringIgnoreCase(TargetAlias); return(hashCode.CombinedHash); }
private void ReadManifest(Stream stream, string basePath) { // Deserialize the document and extract the metadata Manifest manifest = Manifest.ReadFrom(stream); IPackageMetadata metadata = manifest.Metadata; Id = metadata.Id; Version = metadata.Version; Title = metadata.Title; Authors.AddRange(metadata.Authors); Owners.AddRange(metadata.Owners); IconUrl = metadata.IconUrl; LicenseUrl = metadata.LicenseUrl; ProjectUrl = metadata.ProjectUrl; RequireLicenseAcceptance = metadata.RequireLicenseAcceptance; Description = metadata.Description; Summary = metadata.Summary; Language = metadata.Language; if (metadata.Tags != null) { Tags.AddRange(ParseTags(metadata.Tags)); } Dependencies.AddRange(metadata.Dependencies); FrameworkReferences.AddRange(metadata.FrameworkAssemblies); // If there's no base path then ignore the files node if (basePath != null) { if (manifest.Files == null || !manifest.Files.Any()) { AddFiles(basePath, @"**\*.*", null); } else { foreach (var file in manifest.Files) { AddFiles(basePath, file.Source, file.Target); } } } }
public bool Equals(TargetFrameworkInformation other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(EqualityUtility.EqualsWithNullCheck(FrameworkName, other.FrameworkName) && Dependencies.OrderedEquals(other.Dependencies, dependency => dependency.Name, StringComparer.OrdinalIgnoreCase) && Imports.SequenceEqualWithNullCheck(other.Imports) && AssetTargetFallback == other.AssetTargetFallback && DownloadDependencies.OrderedEquals(other.DownloadDependencies, dep => dep) && FrameworkReferences.OrderedEquals(other.FrameworkReferences, fr => fr) && string.Equals(RuntimeIdentifierGraphPath, other.RuntimeIdentifierGraphPath)); }
protected override void ExecuteCore() { if (FrameworkReferences == null || FrameworkReferences.Length == 0) { return; } var duplicateItems = FrameworkReferences.GroupBy(i => i.ItemSpec, StringComparer.OrdinalIgnoreCase).Where(g => g.Count() > 1); if (duplicateItems.Any()) { List <ITaskItem> itemsToAdd = new List <ITaskItem>(); List <ITaskItem> itemsToRemove = new List <ITaskItem>(); foreach (var duplicateItemGroup in duplicateItems) { int remainingItems = 0; foreach (var item in duplicateItemGroup) { if (item.GetMetadata(MetadataKeys.IsImplicitlyDefined).Equals("true", StringComparison.OrdinalIgnoreCase)) { itemsToRemove.Add(item); Log.LogWarning(Strings.FrameworkReferenceOverrideWarning, item.ItemSpec, MoreInformationLink); } else { remainingItems++; itemsToAdd.Add(item); } } if (remainingItems > 1) { Log.LogError(Strings.FrameworkReferenceDuplicateError, duplicateItemGroup.Key); } } ItemsToAdd = itemsToAdd.ToArray(); ItemsToRemove = itemsToRemove.ToArray(); } }
public override bool Execute() { var log = new MSBuildLogger(Log); log.LogDebug($"(in) ProjectUniqueName '{ProjectUniqueName}'"); log.LogDebug($"(in) TargetFrameworks '{TargetFrameworks}'"); log.LogDebug($"(in) FrameworkReferences '{string.Join(";", FrameworkReferences.Select(p => p.ItemSpec))}'"); var entries = new List <ITaskItem>(); var seenIds = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var msbuildItem in FrameworkReferences) { var frameworkReference = msbuildItem.ItemSpec; if (string.IsNullOrEmpty(frameworkReference) || !seenIds.Add(frameworkReference)) { // Skip empty or already processed ids continue; } var properties = new Dictionary <string, string>(); properties.Add("ProjectUniqueName", ProjectUniqueName); properties.Add("Type", "FrameworkReference"); properties.Add("Id", frameworkReference); if (!string.IsNullOrEmpty(TargetFrameworks)) { properties.Add("TargetFrameworks", TargetFrameworks); } BuildTasksUtility.CopyPropertyIfExists(msbuildItem, properties, "PrivateAssets"); entries.Add(new TaskItem(Guid.NewGuid().ToString(), properties)); } RestoreGraphItems = entries.ToArray(); return(true); }
public void Populate(IPackageMetadata metadata) { Id = metadata.Id; Version = metadata.Version; Title = metadata.Title; Authors.AddRange(metadata.Authors); Owners.AddRange(metadata.Owners); IconUrl = metadata.IconUrl; LicenseUrl = metadata.LicenseUrl; ProjectUrl = metadata.ProjectUrl; RequireLicenseAcceptance = metadata.RequireLicenseAcceptance; Description = metadata.Description; Summary = metadata.Summary; Language = metadata.Language; if (metadata.Tags != null) { Tags.AddRange(ParseTags(metadata.Tags)); } Dependencies.AddRange(metadata.Dependencies); FrameworkReferences.AddRange(metadata.FrameworkAssemblies); }
protected override void ExecuteCore() { // Perf optimization: If there are no FrameworkReference items, then don't do anything // (This means that if you don't have any direct framework references, you won't get any transitive ones either if (FrameworkReferences == null || FrameworkReferences.Length == 0) { return; } _normalizedTargetFrameworkVersion = NormalizeVersion(new Version(TargetFrameworkVersion)); var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences .Select(item => new KnownFrameworkReference(item)) .Where(KnownFrameworkReferenceAppliesToTargetFramework) .ToList(); // Get known runtime packs from known framework references. // Only use items where the framework reference name matches the RuntimeFrameworkName. // This will filter out known framework references for "profiles", ie WindowsForms and WPF var knownRuntimePacksForTargetFramework = knownFrameworkReferencesForTargetFramework .Where(kfr => kfr.Name.Equals(kfr.RuntimeFrameworkName, StringComparison.OrdinalIgnoreCase)) .Select(kfr => kfr.ToKnownRuntimePack()) .ToList(); // Add additional known runtime packs knownRuntimePacksForTargetFramework.AddRange( KnownRuntimePacks.Select(item => new KnownRuntimePack(item)) .Where(krp => krp.TargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) && NormalizeVersion(krp.TargetFramework.Version) == _normalizedTargetFrameworkVersion)); var frameworkReferenceMap = FrameworkReferences.ToDictionary(fr => fr.ItemSpec, StringComparer.OrdinalIgnoreCase); List <ITaskItem> packagesToDownload = new List <ITaskItem>(); List <ITaskItem> runtimeFrameworks = new List <ITaskItem>(); List <ITaskItem> targetingPacks = new List <ITaskItem>(); List <ITaskItem> runtimePacks = new List <ITaskItem>(); List <ITaskItem> unavailableRuntimePacks = new List <ITaskItem>(); HashSet <string> unrecognizedRuntimeIdentifiers = new HashSet <string>(StringComparer.OrdinalIgnoreCase); bool windowsOnlyErrorLogged = false; foreach (var knownFrameworkReference in knownFrameworkReferencesForTargetFramework) { frameworkReferenceMap.TryGetValue(knownFrameworkReference.Name, out ITaskItem frameworkReference); // Handle Windows-only frameworks on non-Windows platforms if (knownFrameworkReference.IsWindowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // It is an error to reference the framework from non-Windows if (!windowsOnlyErrorLogged && frameworkReference != null) { Log.LogError(Strings.WindowsDesktopFrameworkRequiresWindows); windowsOnlyErrorLogged = true; } // Ignore (and don't download) this known framework reference as it requires Windows continue; } KnownRuntimePack?selectedRuntimePack = SelectRuntimePack(frameworkReference, knownFrameworkReference, knownRuntimePacksForTargetFramework); // Add targeting pack and all known runtime packs to "preferred packages" list. // These are packages that will win in conflict resolution for assets that have identical assembly and file versions var preferredPackages = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); preferredPackages.Add(knownFrameworkReference.TargetingPackName); if (selectedRuntimePack != null) { var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = selectedRuntimePack?.RuntimePackRuntimeIdentifiers.Split(';'); foreach (var runtimeIdentifier in knownFrameworkReferenceRuntimePackRuntimeIdentifiers) { foreach (var runtimePackNamePattern in selectedRuntimePack?.RuntimePackNamePatterns.Split(';')) { string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimeIdentifier); preferredPackages.Add(runtimePackName); } } } TaskItem targetingPack = new TaskItem(knownFrameworkReference.Name); targetingPack.SetMetadata(MetadataKeys.NuGetPackageId, knownFrameworkReference.TargetingPackName); targetingPack.SetMetadata(MetadataKeys.PackageConflictPreferredPackages, string.Join(";", preferredPackages)); string targetingPackVersion = null; if (frameworkReference != null) { // Allow targeting pack version to be overridden via metadata on FrameworkReference targetingPackVersion = frameworkReference.GetMetadata("TargetingPackVersion"); } if (string.IsNullOrEmpty(targetingPackVersion)) { targetingPackVersion = knownFrameworkReference.TargetingPackVersion; } targetingPack.SetMetadata(MetadataKeys.NuGetPackageVersion, targetingPackVersion); targetingPack.SetMetadata("TargetingPackFormat", knownFrameworkReference.TargetingPackFormat); targetingPack.SetMetadata("TargetFramework", knownFrameworkReference.TargetFramework.GetShortFolderName()); targetingPack.SetMetadata(MetadataKeys.RuntimeFrameworkName, knownFrameworkReference.RuntimeFrameworkName); if (selectedRuntimePack != null) { targetingPack.SetMetadata(MetadataKeys.RuntimePackRuntimeIdentifiers, selectedRuntimePack?.RuntimePackRuntimeIdentifiers); } if (!string.IsNullOrEmpty(knownFrameworkReference.Profile)) { targetingPack.SetMetadata("Profile", knownFrameworkReference.Profile); } // Get the path of the targeting pack in the targeting pack root (e.g. dotnet/packs) string targetingPackPath = null; if (!string.IsNullOrEmpty(TargetingPackRoot)) { targetingPackPath = Path.Combine(TargetingPackRoot, knownFrameworkReference.TargetingPackName, targetingPackVersion); } if (targetingPackPath != null && Directory.Exists(targetingPackPath)) { // Use targeting pack from packs folder targetingPack.SetMetadata(MetadataKeys.PackageDirectory, targetingPackPath); targetingPack.SetMetadata(MetadataKeys.Path, targetingPackPath); } else { if (EnableTargetingPackDownload) { // Download targeting pack TaskItem packageToDownload = new TaskItem(knownFrameworkReference.TargetingPackName); packageToDownload.SetMetadata(MetadataKeys.Version, targetingPackVersion); packagesToDownload.Add(packageToDownload); } } targetingPacks.Add(targetingPack); var runtimeFrameworkVersion = GetRuntimeFrameworkVersion( frameworkReference, knownFrameworkReference, selectedRuntimePack, out string runtimePackVersion); string isTrimmable = null; if (frameworkReference != null) { // Allow IsTrimmable to be overridden via metadata on FrameworkReference isTrimmable = frameworkReference.GetMetadata(MetadataKeys.IsTrimmable); } if (string.IsNullOrEmpty(isTrimmable)) { isTrimmable = selectedRuntimePack?.IsTrimmable; } bool includeInPackageDownload; KnownRuntimePack runtimePackForRuntimeIDProcessing; if (knownFrameworkReference.Name.Equals(knownFrameworkReference.RuntimeFrameworkName, StringComparison.OrdinalIgnoreCase)) { // Only add runtime packs where the framework reference name matches the RuntimeFrameworkName // Framework references for "profiles" will use the runtime pack from the corresponding non-profile framework runtimePackForRuntimeIDProcessing = selectedRuntimePack.Value; includeInPackageDownload = true; } else if (!knownFrameworkReference.RuntimePackRuntimeIdentifiers.Equals(selectedRuntimePack?.RuntimePackRuntimeIdentifiers)) { // If the profile has a different set of runtime identifiers than the runtime pack, use the profile. runtimePackForRuntimeIDProcessing = knownFrameworkReference.ToKnownRuntimePack(); includeInPackageDownload = true; } else { // For the remaining profiles, don't include them in package download but add them to unavaliable if necessary. runtimePackForRuntimeIDProcessing = knownFrameworkReference.ToKnownRuntimePack(); includeInPackageDownload = false; } bool processedPrimaryRuntimeIdentifier = false; var hasRuntimePackAlwaysCopyLocal = selectedRuntimePack != null && selectedRuntimePack.Value.RuntimePackAlwaysCopyLocal; var runtimeRequiredByDeployment = (SelfContained || ReadyToRunEnabled) && !string.IsNullOrEmpty(RuntimeIdentifier) && selectedRuntimePack != null && !string.IsNullOrEmpty(selectedRuntimePack.Value.RuntimePackNamePatterns); if (hasRuntimePackAlwaysCopyLocal || runtimeRequiredByDeployment) { // Find other KnownFrameworkReferences that map to the same runtime pack, if any List <string> additionalFrameworkReferencesForRuntimePack = null; foreach (var additionalKnownFrameworkReference in knownFrameworkReferencesForTargetFramework) { if (additionalKnownFrameworkReference.RuntimeFrameworkName.Equals(knownFrameworkReference.RuntimeFrameworkName, StringComparison.OrdinalIgnoreCase) && !additionalKnownFrameworkReference.RuntimeFrameworkName.Equals(additionalKnownFrameworkReference.Name, StringComparison.OrdinalIgnoreCase)) { if (additionalFrameworkReferencesForRuntimePack == null) { additionalFrameworkReferencesForRuntimePack = new List <string>(); } additionalFrameworkReferencesForRuntimePack.Add(additionalKnownFrameworkReference.Name); } } ProcessRuntimeIdentifier(hasRuntimePackAlwaysCopyLocal ? "any" : RuntimeIdentifier, runtimePackForRuntimeIDProcessing, runtimePackVersion, additionalFrameworkReferencesForRuntimePack, unrecognizedRuntimeIdentifiers, unavailableRuntimePacks, runtimePacks, packagesToDownload, isTrimmable, includeInPackageDownload); processedPrimaryRuntimeIdentifier = true; } if (RuntimeIdentifiers != null) { foreach (var runtimeIdentifier in RuntimeIdentifiers) { if (processedPrimaryRuntimeIdentifier && runtimeIdentifier == this.RuntimeIdentifier) { // We've already processed this RID continue; } // Pass in null for the runtimePacks list, as for these runtime identifiers we only want to // download the runtime packs, but not use the assets from them ProcessRuntimeIdentifier(runtimeIdentifier, runtimePackForRuntimeIDProcessing, runtimePackVersion, additionalFrameworkReferencesForRuntimePack: null, unrecognizedRuntimeIdentifiers, unavailableRuntimePacks, runtimePacks: null, packagesToDownload, isTrimmable, includeInPackageDownload); } } if (!string.IsNullOrEmpty(knownFrameworkReference.RuntimeFrameworkName) && !knownFrameworkReference.RuntimePackAlwaysCopyLocal) { TaskItem runtimeFramework = new TaskItem(knownFrameworkReference.RuntimeFrameworkName); runtimeFramework.SetMetadata(MetadataKeys.Version, runtimeFrameworkVersion); runtimeFramework.SetMetadata(MetadataKeys.FrameworkName, knownFrameworkReference.Name); runtimeFrameworks.Add(runtimeFramework); } } if (ReadyToRunEnabled && ReadyToRunUseCrossgen2) { if (!SelfContained) { Log.LogError(Strings.Crossgen2RequiresSelfContained); return; } if (!AddCrossgen2Package(_normalizedTargetFrameworkVersion, packagesToDownload)) { Log.LogError(Strings.ReadyToRunNoValidRuntimePackageError); return; } } if (packagesToDownload.Any()) { PackagesToDownload = packagesToDownload.Distinct(new PackageToDownloadComparer <ITaskItem>()).ToArray(); } if (runtimeFrameworks.Any()) { RuntimeFrameworks = runtimeFrameworks.ToArray(); } if (targetingPacks.Any()) { TargetingPacks = targetingPacks.ToArray(); } if (runtimePacks.Any()) { RuntimePacks = runtimePacks.ToArray(); } if (unavailableRuntimePacks.Any()) { UnavailableRuntimePacks = unavailableRuntimePacks.ToArray(); } }
public bool ReferenceExists(string name) { return(References.ContainsKey(name) || FrameworkReferences.Contains(name)); }
public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencyGroups.SelectMany(d => d.Packages).Any() && !FrameworkReferences.Any() && !FrameworkReferenceGroups.Any()) { throw new PackagingException(NuGetLogCode.NU5017, NuGetResources.CannotCreateEmptyPackage); } ValidateDependencies(Version, DependencyGroups); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); ValidateLicenseFile(Files, LicenseMetadata); ValidateIconFile(Files, Icon); using (var package = new ZipArchive(stream, ZipArchiveMode.Create, leaveOpen: true)) { string psmdcpPath = $"package/services/metadata/core-properties/{CalcPsmdcpName()}.psmdcp"; // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files, DependencyGroups), psmdcpPath); // Write the files to the package HashSet <string> filesWithoutExtensions = new HashSet <string>(); var extensions = WriteFiles(package, filesWithoutExtensions); extensions.Add("nuspec"); WriteOpcContentTypes(package, extensions, filesWithoutExtensions); WriteOpcPackageProperties(package, psmdcpPath); } }
public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkReferences.Any()) { throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage); } if (!ValidateSpecialVersionLength(Version)) { throw new InvalidOperationException(NuGetResources.SemVerSpecialVersionTooLong); } ValidateDependencySets(Version, DependencySets); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); using (var package = new ZipArchive(stream, ZipArchiveMode.Create)) { // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files)); // Write the files to the package var extensions = WriteFiles(package); extensions.Add("nuspec"); WriteOpcContentTypes(package, extensions); } }
public override int GetHashCode() { var combiner = new HashCodeCombiner(); combiner.AddObject(Name); combiner.AddObject(Version); combiner.AddObject(Type); combiner.AddObject(Framework); foreach (var dependency in Dependencies.OrderBy(dependency => dependency.Id, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(dependency); } foreach (var reference in FrameworkAssemblies.OrderBy(s => s, StringComparer.OrdinalIgnoreCase)) { combiner.AddStringIgnoreCase(reference); } foreach (var reference in FrameworkReferences.OrderBy(s => s, StringComparer.OrdinalIgnoreCase)) { combiner.AddStringIgnoreCase(reference); } foreach (var item in RuntimeAssemblies.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in ResourceAssemblies.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in CompileTimeAssemblies.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in NativeLibraries.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in ContentFiles.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in RuntimeTargets.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in Build.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in BuildMultiTargeting.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in ToolsAssemblies.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } foreach (var item in EmbedAssemblies.OrderBy(item => item.Path, StringComparer.OrdinalIgnoreCase)) { combiner.AddObject(item); } return(combiner.CombinedHash); }
protected override void ExecuteCore() { var runtimePackAssets = new List <ITaskItem>(); HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase); foreach (var unavailableRuntimePack in UnavailableRuntimePacks) { if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec)) { // This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier // NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'. Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec, unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier)); } } HashSet <string> processedRuntimePackRoots = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var runtimePack in ResolvedRuntimePacks) { if (!frameworkReferenceNames.Contains(runtimePack.GetMetadata(MetadataKeys.FrameworkName))) { // This is a runtime pack for a shared framework that ultimately wasn't referenced, so don't include its assets continue; } string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory); if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot)) { if (!DesignTimeBuild) { // Don't treat this as an error if we are doing a design-time build. This is because the design-time // build needs to succeed in order to get the right information in order to run a restore to download // the runtime pack. Log.LogError(Strings.RuntimePackNotDownloaded, runtimePack.ItemSpec, runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier)); } continue; } if (!processedRuntimePackRoots.Add(runtimePackRoot)) { // We already added assets from this runtime pack (which can happen with FrameworkReferences to different // profiles of the same shared framework) continue; } var runtimeListPath = Path.Combine(runtimePackRoot, "data", "RuntimeList.xml"); if (File.Exists(runtimeListPath)) { AddRuntimePackAssetsFromManifest(runtimePackAssets, runtimePackRoot, runtimeListPath, runtimePack); } else { throw new BuildErrorException(string.Format(Strings.RuntimeListNotFound, runtimeListPath)); } } RuntimePackAssets = runtimePackAssets.ToArray(); }
public void Save(Stream stream) { // Make sure we're saving a valid package id PackageIdValidator.ValidatePackageId(Id); // Throw if the package doesn't contain any dependencies nor content if (!Files.Any() && !DependencySets.SelectMany(d => d.Dependencies).Any() && !FrameworkReferences.Any()) { throw new InvalidOperationException(NuGetResources.CannotCreateEmptyPackage); } if (!ValidateSpecialVersionLength(Version)) { throw new InvalidOperationException(NuGetResources.SemVerSpecialVersionTooLong); } ValidateDependencySets(Version, DependencySets); ValidateReferenceAssemblies(Files, PackageAssemblyReferences); if (PlatformHelper.IsMono) { #if NET45 // Mono's zip implementation isn't complete as yet using (var package = System.IO.Packaging.Package.Open(stream, FileMode.Create)) { // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files)); // Write the files to the package WriteFiles(package); // Copy the metadata properties back to the package package.PackageProperties.Creator = String.Join(",", Authors); package.PackageProperties.Description = Description; package.PackageProperties.Identifier = Id; package.PackageProperties.Version = Version.ToString(); package.PackageProperties.Language = Language; package.PackageProperties.Keywords = ((IPackageMetadata)this).Tags; package.PackageProperties.Title = Title; package.PackageProperties.LastModifiedBy = CreatorInfo(); } #endif } else { using (var package = new ZipArchive(stream, ZipArchiveMode.Update)) { // Validate and write the manifest WriteManifest(package, DetermineMinimumSchemaVersion(Files)); // Write the files to the package var extensions = WriteFiles(package); extensions.Add("nuspec"); WriteOpcContentTypes(package, extensions); } } }
protected override void ExecuteCore() { // Perf optimization: If there are no FrameworkReference items, then don't do anything // (This means that if you don't have any direct framework references, you won't get any transitive ones either if (FrameworkReferences == null || FrameworkReferences.Length == 0) { return; } var normalizedTargetFrameworkVersion = NormalizeVersion(new Version(TargetFrameworkVersion)); var knownFrameworkReferencesForTargetFramework = KnownFrameworkReferences.Select(item => new KnownFrameworkReference(item)) .Where(kfr => kfr.TargetFramework.Framework.Equals(TargetFrameworkIdentifier, StringComparison.OrdinalIgnoreCase) && NormalizeVersion(kfr.TargetFramework.Version) == normalizedTargetFrameworkVersion) .ToList(); var frameworkReferenceMap = FrameworkReferences.ToDictionary(fr => fr.ItemSpec, StringComparer.OrdinalIgnoreCase); List <ITaskItem> packagesToDownload = new List <ITaskItem>(); List <ITaskItem> runtimeFrameworks = new List <ITaskItem>(); List <ITaskItem> targetingPacks = new List <ITaskItem>(); List <ITaskItem> runtimePacks = new List <ITaskItem>(); List <ITaskItem> unavailableRuntimePacks = new List <ITaskItem>(); HashSet <string> unrecognizedRuntimeIdentifiers = new HashSet <string>(StringComparer.OrdinalIgnoreCase); bool windowsOnlyErrorLogged = false; foreach (var knownFrameworkReference in knownFrameworkReferencesForTargetFramework) { frameworkReferenceMap.TryGetValue(knownFrameworkReference.Name, out ITaskItem frameworkReference); // Handle Windows-only frameworks on non-Windows platforms if (knownFrameworkReference.IsWindowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // It is an error to reference the framework from non-Windows if (!windowsOnlyErrorLogged && frameworkReference != null) { Log.LogError(Strings.WindowsDesktopFrameworkRequiresWindows); windowsOnlyErrorLogged = true; } // Ignore (and don't download) this known framework reference as it requires Windows continue; } List <string> preferredPackages = new List <string>(); preferredPackages.Add(knownFrameworkReference.TargetingPackName); var knownFrameworkReferenceRuntimePackRuntimeIdentifiers = knownFrameworkReference.RuntimePackRuntimeIdentifiers.Split(';'); foreach (var runtimeIdentifier in knownFrameworkReferenceRuntimePackRuntimeIdentifiers) { foreach (var runtimePackNamePattern in knownFrameworkReference.RuntimePackNamePatterns.Split(';')) { string runtimePackName = runtimePackNamePattern.Replace("**RID**", runtimeIdentifier); preferredPackages.Add(runtimePackName); } } // Get the path of the targeting pack in the targeting pack root (e.g. dotnet/ref) TaskItem targetingPack = new TaskItem(knownFrameworkReference.Name); targetingPack.SetMetadata(MetadataKeys.PackageName, knownFrameworkReference.TargetingPackName); targetingPack.SetMetadata(MetadataKeys.PackageConflictPreferredPackages, string.Join(";", preferredPackages)); string targetingPackVersion = null; if (frameworkReference != null) { // Allow targeting pack version to be overridden via metadata on FrameworkReference targetingPackVersion = frameworkReference.GetMetadata("TargetingPackVersion"); } if (string.IsNullOrEmpty(targetingPackVersion)) { targetingPackVersion = knownFrameworkReference.TargetingPackVersion; } targetingPack.SetMetadata(MetadataKeys.PackageVersion, targetingPackVersion); targetingPack.SetMetadata("TargetingPackFormat", knownFrameworkReference.TargetingPackFormat); targetingPack.SetMetadata("TargetFramework", knownFrameworkReference.TargetFramework.GetShortFolderName()); targetingPack.SetMetadata("RuntimeFrameworkName", knownFrameworkReference.RuntimeFrameworkName); if (!string.IsNullOrEmpty(knownFrameworkReference.Profile)) { targetingPack.SetMetadata("Profile", knownFrameworkReference.Profile); } string targetingPackPath = null; if (!string.IsNullOrEmpty(TargetingPackRoot)) { targetingPackPath = Path.Combine(TargetingPackRoot, knownFrameworkReference.TargetingPackName, targetingPackVersion); } if (targetingPackPath != null && Directory.Exists(targetingPackPath)) { // Use targeting pack from packs folder targetingPack.SetMetadata(MetadataKeys.PackageDirectory, targetingPackPath); targetingPack.SetMetadata(MetadataKeys.Path, targetingPackPath); } else { if (EnableTargetingPackDownload) { // Download targeting pack TaskItem packageToDownload = new TaskItem(knownFrameworkReference.TargetingPackName); packageToDownload.SetMetadata(MetadataKeys.Version, targetingPackVersion); packagesToDownload.Add(packageToDownload); } } targetingPacks.Add(targetingPack); var runtimeFrameworkVersion = GetRuntimeFrameworkVersion(frameworkReference, knownFrameworkReference); string isTrimmable = null; if (frameworkReference != null) { // Allow IsTrimmable to be overridden via metadata on FrameworkReference isTrimmable = frameworkReference.GetMetadata(MetadataKeys.IsTrimmable); } if (string.IsNullOrEmpty(isTrimmable)) { isTrimmable = knownFrameworkReference.IsTrimmable; } bool processedPrimaryRuntimeIdentifier = false; if ((SelfContained || ReadyToRunEnabled) && !string.IsNullOrEmpty(RuntimeIdentifier) && !string.IsNullOrEmpty(knownFrameworkReference.RuntimePackNamePatterns)) { ProcessRuntimeIdentifier(RuntimeIdentifier, knownFrameworkReference, runtimeFrameworkVersion, unrecognizedRuntimeIdentifiers, unavailableRuntimePacks, runtimePacks, packagesToDownload, isTrimmable); processedPrimaryRuntimeIdentifier = true; } if (RuntimeIdentifiers != null) { foreach (var runtimeIdentifier in RuntimeIdentifiers) { if (processedPrimaryRuntimeIdentifier && runtimeIdentifier == this.RuntimeIdentifier) { // We've already processed this RID continue; } // Pass in null for the runtimePacks list, as for these runtime identifiers we only want to // download the runtime packs, but not use the assets from them ProcessRuntimeIdentifier(runtimeIdentifier, knownFrameworkReference, runtimeFrameworkVersion, unrecognizedRuntimeIdentifiers, unavailableRuntimePacks, runtimePacks: null, packagesToDownload, isTrimmable); } } if (!string.IsNullOrEmpty(knownFrameworkReference.RuntimeFrameworkName)) { TaskItem runtimeFramework = new TaskItem(knownFrameworkReference.RuntimeFrameworkName); runtimeFramework.SetMetadata(MetadataKeys.Version, runtimeFrameworkVersion); runtimeFramework.SetMetadata(MetadataKeys.FrameworkName, knownFrameworkReference.Name); runtimeFrameworks.Add(runtimeFramework); } } if (packagesToDownload.Any()) { PackagesToDownload = packagesToDownload.ToArray(); } if (runtimeFrameworks.Any()) { RuntimeFrameworks = runtimeFrameworks.ToArray(); } if (targetingPacks.Any()) { TargetingPacks = targetingPacks.ToArray(); } if (runtimePacks.Any()) { RuntimePacks = runtimePacks.ToArray(); } if (unavailableRuntimePacks.Any()) { UnavailableRuntimePacks = unavailableRuntimePacks.ToArray(); } }
protected override void ExecuteCore() { List <TaskItem> referencesToAdd = new List <TaskItem>(); List <TaskItem> platformManifests = new List <TaskItem>(); PackageConflictPreferredPackages = string.Empty; List <TaskItem> packageConflictOverrides = new List <TaskItem>(); var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(item => item.ItemSpec, StringComparer.OrdinalIgnoreCase); foreach (var frameworkReference in FrameworkReferences) { ITaskItem targetingPack; resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack); string targetingPackRoot = targetingPack?.GetMetadata("Path"); if (string.IsNullOrEmpty(targetingPackRoot) || !Directory.Exists(targetingPackRoot)) { if (GenerateErrorForMissingTargetingPacks) { Log.LogError(Strings.UnknownFrameworkReference, frameworkReference.ItemSpec); } } else { string targetingPackFormat = targetingPack.GetMetadata("TargetingPackFormat"); if (targetingPackFormat.Equals("NETStandardLegacy", StringComparison.OrdinalIgnoreCase)) { AddNetStandardTargetingPackAssets(targetingPack, targetingPackRoot, referencesToAdd); } else { string targetingPackTargetFramework = targetingPack.GetMetadata("TargetFramework"); if (string.IsNullOrEmpty(targetingPackTargetFramework)) { targetingPackTargetFramework = "netcoreapp3.0"; } string targetingPackDataPath = Path.Combine(targetingPackRoot, "data"); string[] possibleDllFolders = new[] { Path.Combine(targetingPackRoot, "ref", targetingPackTargetFramework), targetingPackDataPath }; string[] possibleManifestPaths = new[] { Path.Combine(targetingPackRoot, "build", targetingPackTargetFramework, targetingPack.GetMetadata(MetadataKeys.PackageName) + ".PlatformManifest.txt"), Path.Combine(targetingPackDataPath, "PlatformManifest.txt"), Path.Combine(targetingPackDataPath, targetingPack.GetMetadata(MetadataKeys.PackageName) + ".PlatformManifest.txt"), }; string targetingPackDllFolder = possibleDllFolders.First(path => Directory.Exists(path) && Directory.GetFiles(path, "*.dll").Any()); string platformManifestPath = possibleManifestPaths.FirstOrDefault(File.Exists); string packageOverridesPath = Path.Combine(targetingPackDataPath, "PackageOverrides.txt"); string frameworkListPath = Path.Combine(targetingPackDataPath, "FrameworkList.xml"); if (File.Exists(frameworkListPath)) { AddReferencesFromFrameworkList(frameworkListPath, targetingPackDllFolder, targetingPack, referencesToAdd); } else { foreach (var dll in Directory.GetFiles(targetingPackDllFolder, "*.dll")) { var reference = CreateReferenceItem(dll, targetingPack); referencesToAdd.Add(reference); } } if (platformManifestPath != null) { platformManifests.Add(new TaskItem(platformManifestPath)); } if (File.Exists(packageOverridesPath)) { packageConflictOverrides.Add(CreatePackageOverride(targetingPack.GetMetadata("RuntimeFrameworkName"), packageOverridesPath)); } if (targetingPack.ItemSpec.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)) { // Hardcode this for now. Load this from the targeting pack once we have "real" targeting packs // https://github.com/dotnet/cli/issues/10581 PackageConflictPreferredPackages = "Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App"; } } } } // Calculate which RuntimeFramework items should actually be used based on framework references HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(fr => fr.ItemSpec), StringComparer.OrdinalIgnoreCase); UsedRuntimeFrameworks = RuntimeFrameworks.Where(rf => frameworkReferenceNames.Contains(rf.GetMetadata(MetadataKeys.FrameworkName))) .ToArray(); // Filter out duplicate references (which can happen when referencing two different profiles that overlap) List <TaskItem> deduplicatedReferences = DeduplicateItems(referencesToAdd); ReferencesToAdd = deduplicatedReferences.Distinct().ToArray(); PlatformManifests = platformManifests.ToArray(); PackageConflictOverrides = packageConflictOverrides.ToArray(); }
protected override void ExecuteCore() { var runtimePackAssets = new List <ITaskItem>(); HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(item => item.ItemSpec), StringComparer.OrdinalIgnoreCase); foreach (var unavailableRuntimePack in UnavailableRuntimePacks) { if (frameworkReferenceNames.Contains(unavailableRuntimePack.ItemSpec)) { // This is a runtime pack that should be used, but wasn't available for the specified RuntimeIdentifier // NETSDK1082: There was no runtime pack for {0} available for the specified RuntimeIdentifier '{1}'. Log.LogError(Strings.NoRuntimePackAvailable, unavailableRuntimePack.ItemSpec, unavailableRuntimePack.GetMetadata(MetadataKeys.RuntimeIdentifier)); } } HashSet <string> processedRuntimePackRoots = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var runtimePack in ResolvedRuntimePacks) { if (!frameworkReferenceNames.Contains(runtimePack.GetMetadata(MetadataKeys.FrameworkName))) { // This is a runtime pack for a shared framework that ultimately wasn't referenced, so don't include its assets continue; } string runtimePackRoot = runtimePack.GetMetadata(MetadataKeys.PackageDirectory); if (string.IsNullOrEmpty(runtimePackRoot) || !Directory.Exists(runtimePackRoot)) { // If we do the work in https://github.com/dotnet/cli/issues/10528, // then we should add a new error message here indicating that the runtime pack hasn't // been downloaded, and that restore should be run with that runtime identifier. Log.LogError(Strings.NoRuntimePackAvailable, runtimePack.ItemSpec, runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier)); } if (!processedRuntimePackRoots.Add(runtimePackRoot)) { // We already added assets from this runtime pack (which can happen with FrameworkReferences to different // profiles of the same shared framework) continue; } string runtimeIdentifier = runtimePack.GetMetadata(MetadataKeys.RuntimeIdentifier); // These hard-coded paths are temporary until we have "real" runtime packs, which will likely have a flattened // folder structure and a manifest indicating how the files should be used: https://github.com/dotnet/cli/issues/10442 string runtimeAssetsPath = Path.Combine(runtimePackRoot, "runtimes", runtimeIdentifier, "lib", "netcoreapp3.0"); string nativeAssetsPath = Path.Combine(runtimePackRoot, "runtimes", runtimeIdentifier, "native"); var runtimeAssets = Directory.Exists(runtimeAssetsPath) ? Directory.GetFiles(runtimeAssetsPath) : Array.Empty <string>(); var nativeAssets = Directory.Exists(nativeAssetsPath) ? Directory.GetFiles(nativeAssetsPath) : Array.Empty <string>(); void AddAsset(string assetPath, string assetType) { if (assetPath.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase) || assetPath.EndsWith(".map", StringComparison.OrdinalIgnoreCase) || assetPath.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) || assetPath.EndsWith(".xml", StringComparison.OrdinalIgnoreCase) || assetPath.EndsWith(".json", StringComparison.OrdinalIgnoreCase) || assetPath.EndsWith("._", StringComparison.Ordinal)) { // Don't add assets for these files (shouldn't be necessary if/once we have a manifest in the runtime pack // https://github.com/dotnet/cli/issues/10442 return; } var assetItem = new TaskItem(assetPath); assetItem.SetMetadata(MetadataKeys.CopyLocal, "true"); assetItem.SetMetadata(MetadataKeys.DestinationSubPath, Path.GetFileName(assetPath)); assetItem.SetMetadata(MetadataKeys.AssetType, assetType); assetItem.SetMetadata(MetadataKeys.PackageName, runtimePack.GetMetadata(MetadataKeys.PackageName)); assetItem.SetMetadata(MetadataKeys.PackageVersion, runtimePack.GetMetadata(MetadataKeys.PackageVersion)); assetItem.SetMetadata(MetadataKeys.RuntimeIdentifier, runtimeIdentifier); assetItem.SetMetadata(MetadataKeys.IsTrimmable, runtimePack.GetMetadata(MetadataKeys.IsTrimmable)); runtimePackAssets.Add(assetItem); } foreach (var asset in runtimeAssets) { AddAsset(asset, "runtime"); } foreach (var asset in nativeAssets) { AddAsset(asset, "native"); } runtimePackAssets.AddRange(EnumerateResourceAssets(runtimePackRoot, runtimeIdentifier, runtimePack)); } RuntimePackAssets = runtimePackAssets.ToArray(); }
protected override void ExecuteCore() { List <TaskItem> referencesToAdd = new List <TaskItem>(); List <TaskItem> platformManifests = new List <TaskItem>(); PackageConflictPreferredPackages = string.Empty; List <TaskItem> packageConflictOverrides = new List <TaskItem>(); var resolvedTargetingPacks = ResolvedTargetingPacks.ToDictionary(item => item.ItemSpec, StringComparer.OrdinalIgnoreCase); foreach (var frameworkReference in FrameworkReferences) { ITaskItem targetingPack; resolvedTargetingPacks.TryGetValue(frameworkReference.ItemSpec, out targetingPack); string targetingPackRoot = targetingPack?.GetMetadata("Path"); if (string.IsNullOrEmpty(targetingPackRoot) || !Directory.Exists(targetingPackRoot)) { if (GenerateErrorForMissingTargetingPacks) { Log.LogError(Strings.UnknownFrameworkReference, frameworkReference.ItemSpec); } } else { foreach (var dll in Directory.GetFiles(Path.Combine(targetingPackRoot, "ref", "netcoreapp3.0"), "*.dll")) { var reference = new TaskItem(dll); reference.SetMetadata(MetadataKeys.ExternallyResolved, "true"); reference.SetMetadata(MetadataKeys.Private, "false"); // TODO: Once we work out what metadata we should use here to display these references grouped under the targeting pack // in solution explorer, set that metadata here.These metadata values are based on what PCLs were using. // https://github.com/dotnet/sdk/issues/2802 reference.SetMetadata("WinMDFile", "false"); reference.SetMetadata("ReferenceGroupingDisplayName", targetingPack.ItemSpec); reference.SetMetadata("ReferenceGrouping", targetingPack.ItemSpec); reference.SetMetadata("ResolvedFrom", "TargetingPack"); reference.SetMetadata("IsSystemReference", "true"); referencesToAdd.Add(reference); } var platformManifestPath = Path.Combine(targetingPackRoot, "build", "netcoreapp3.0", targetingPack.GetMetadata(MetadataKeys.PackageName) + ".PlatformManifest.txt"); if (File.Exists(platformManifestPath)) { platformManifests.Add(new TaskItem(platformManifestPath)); } if (targetingPack.ItemSpec.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)) { // Hardcode this for now. Load this from the targeting pack once we have "real" targeting packs // https://github.com/dotnet/cli/issues/10581 PackageConflictPreferredPackages = "Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.linux-musl-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.rhel.6-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.osx-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.freebsd-x64.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-x86.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.win-arm64.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.linux-arm64.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.4.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.tizen.5.0.0-armel.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App;runtime.win-x64.Microsoft.NETCore.App"; } } } HashSet <string> frameworkReferenceNames = new HashSet <string>(FrameworkReferences.Select(fr => fr.ItemSpec), StringComparer.OrdinalIgnoreCase); RuntimeFrameworksToRemove = RuntimeFrameworks.Where(rf => !frameworkReferenceNames.Contains(rf.GetMetadata(MetadataKeys.FrameworkName))) .ToArray(); ReferencesToAdd = referencesToAdd.ToArray(); PlatformManifests = platformManifests.ToArray(); PackageConflictOverrides = packageConflictOverrides.ToArray(); }