private static void PopulateFrameworkReferences(ISet <FrameworkDependency> frameworkReferences, JObject properties, string frameworkReferenceName, string packageSpecPath) { var frameworkRefs = properties[frameworkReferenceName] as JObject; if (frameworkRefs != null) { foreach (var frameworkReference in frameworkRefs) { if (string.IsNullOrEmpty(frameworkReference.Key)) { throw FileFormatException.Create( "Unable to resolve frameworkReference.", frameworkReference.Value, packageSpecPath); } var privateAssets = FrameworkDependencyFlagsUtils.Default; if (frameworkReference.Value is JObject frameworkReferenceToken) { if (TryGetStringEnumerable(frameworkReferenceToken["privateAssets"], out var strings)) { privateAssets = FrameworkDependencyFlagsUtils.GetFlags(strings); } } frameworkReferences.Add(new FrameworkDependency(frameworkReference.Key, privateAssets)); } } }
private static IVsReferenceItem ToFrameworkReference(FrameworkDependency frameworkDependency) { var properties = new VsReferenceProperties( new[] { new VsReferenceProperty("PrivateAssets", FrameworkDependencyFlagsUtils.GetFlagString(frameworkDependency.PrivateAssets)) } ); return(new VsReferenceItem(frameworkDependency.Name, properties)); }
public void FrameworkDependencyFlagsUtils_GetFlagsFromAnEnumerable_ReturnsExpectedFlags() { Assert.Equal(FrameworkDependencyFlags.None, FrameworkDependencyFlagsUtils.GetFlags((IEnumerable <string>)null)); Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags(new string[] { "all" })); Assert.Equal(FrameworkDependencyFlags.None, FrameworkDependencyFlagsUtils.GetFlags(new string[] { "none" })); Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags(new string[] { "all", "none" })); Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags(new string[] { "none", "all" })); Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags(new string[] { "All", "None" })); }
public void FrameworkDependencyFlagsUtils_GetFlagsFromString_ReturnsExpectedFlags() { Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags("all")); Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags("All")); Assert.Equal(FrameworkDependencyFlags.None, FrameworkDependencyFlagsUtils.GetFlags("None")); Assert.Equal(FrameworkDependencyFlags.None, FrameworkDependencyFlagsUtils.GetFlags("none")); Assert.Equal(FrameworkDependencyFlags.None, FrameworkDependencyFlagsUtils.GetFlags((string)null)); Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags("none,all")); // Stupid to write this, but pointless to enforce that people don't :) Assert.Equal(FrameworkDependencyFlags.All, FrameworkDependencyFlagsUtils.GetFlags("all,none")); // Stupid to write this, but pointless to enforce that people don't :) }
private static void SetFrameworkReferences(IObjectWriter writer, ISet <FrameworkDependency> frameworkReferences) { if (frameworkReferences?.Any() == true) { writer.WriteObjectStart("frameworkReferences"); foreach (var dependency in frameworkReferences.OrderBy(dep => dep)) { writer.WriteObjectStart(dependency.Name); SetValue(writer, "privateAssets", FrameworkDependencyFlagsUtils.GetFlagString(dependency.PrivateAssets)); writer.WriteObjectEnd(); } writer.WriteObjectEnd(); } }
private static bool AddFrameworkReferenceIfNotExists(PackageSpec spec, NuGetFramework framework, string frameworkReference, string privateAssetsValue) { var frameworkInfo = spec.GetTargetFramework(framework); if (!frameworkInfo .FrameworkReferences .Select(f => f.Name) .Contains(frameworkReference, ComparisonUtility.FrameworkReferenceNameComparer)) { var privateAssets = FrameworkDependencyFlagsUtils.GetFlags(MSBuildStringUtility.Split(privateAssetsValue)); frameworkInfo.FrameworkReferences.Add(new FrameworkDependency(frameworkReference, privateAssets)); return(true); } return(false); }
/// <summary> /// Gets the framework references per target framework for the specified project. /// </summary> /// <param name="project">The <see cref="ProjectInstance" /> to get framework references for.</param> /// <returns>A <see cref="List{FrameworkDependency}" /> containing the framework references for the specified project.</returns> internal static List <FrameworkDependency> GetFrameworkReferences(IMSBuildProject project) { // Get the unique FrameworkReference items, ignoring duplicates var frameworkReferenceItems = project.GetItems("FrameworkReference").Distinct(ProjectItemInstanceEvaluatedIncludeComparer.Instance).ToList(); // For best performance, its better to create a list with the exact number of items needed rather than using a LINQ statement or AddRange. This is because if the list // is not allocated with enough items, the list has to be grown which can slow things down var frameworkDependencies = new List <FrameworkDependency>(frameworkReferenceItems.Count); foreach (var frameworkReferenceItem in frameworkReferenceItems) { var privateAssets = MSBuildStringUtility.Split(frameworkReferenceItem.GetProperty("PrivateAssets")); frameworkDependencies.Add(new FrameworkDependency(frameworkReferenceItem.Identity, FrameworkDependencyFlagsUtils.GetFlags(privateAssets))); } return(frameworkDependencies); }
/// <summary> /// Get the frameworkdependencyflag based on the name. /// </summary> private static FrameworkDependencyFlags GetFrameworkDependencyFlags(IVsReferenceItem item, string name) { var flags = GetPropertyValueOrNull(item, name); return(FrameworkDependencyFlagsUtils.GetFlags(flags)); }
public void FrameworkDependencyFlagsUtils_GetFlagString_ReturnsExpectedString() { Assert.Equal("all", FrameworkDependencyFlagsUtils.GetFlagString(FrameworkDependencyFlags.All)); Assert.Equal("none", FrameworkDependencyFlagsUtils.GetFlagString(FrameworkDependencyFlags.None)); }