public static IEnumerable<string> GetPatternsCollection(JsonObject rawProject, string projectDirectory, string projectFilePath, string propertyName, IEnumerable<string> defaultPatterns = null, bool literalPath = false) { defaultPatterns = defaultPatterns ?? Enumerable.Empty<string>(); try { if (!rawProject.Keys.Contains(propertyName)) { return CreateCollection(projectDirectory, propertyName, defaultPatterns, literalPath); } var valueInString = rawProject.ValueAsString(propertyName); if (valueInString != null) { return CreateCollection(projectDirectory, propertyName, new string[] { valueInString }, literalPath); } var valuesInArray = rawProject.ValueAsStringArray(propertyName); if (valuesInArray != null) { return CreateCollection(projectDirectory, propertyName, valuesInArray.Select(s => s.ToString()), literalPath); } } catch (Exception ex) { throw FileFormatException.Create(ex, rawProject.Value(propertyName), projectFilePath); } throw FileFormatException.Create("Value must be either string or array.", rawProject.Value(propertyName), projectFilePath); }
/// <summary> /// Parse a Json object which represents project configuration for a specified framework /// </summary> /// <param name="frameworkKey">The name of the framework</param> /// <param name="frameworkValue">The Json object represent the settings</param> /// <returns>Returns true if it successes.</returns> private bool BuildTargetFrameworkNode(Project project, string frameworkKey, JsonObject frameworkValue) { // If no compilation options are provided then figure them out from the node var compilerOptions = GetCompilationOptions(frameworkValue) ?? new CommonCompilerOptions(); var frameworkName = NuGetFramework.Parse(frameworkKey); // If it's not unsupported then keep it if (frameworkName.IsUnsupported) { // REVIEW: Should we skip unsupported target frameworks return false; } // Add the target framework specific define var defines = new HashSet<string>(compilerOptions.Defines ?? Enumerable.Empty<string>()); var frameworkDefine = MakeDefaultTargetFrameworkDefine(frameworkName); if (!string.IsNullOrEmpty(frameworkDefine)) { defines.Add(frameworkDefine); } compilerOptions.Defines = defines; var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = frameworkName, Dependencies = new List<LibraryRange>(), CompilerOptions = compilerOptions, Line = frameworkValue.Line, Column = frameworkValue.Column }; var frameworkDependencies = new List<LibraryRange>(); PopulateDependencies( project.ProjectFilePath, frameworkDependencies, frameworkValue, "dependencies", isGacOrFrameworkReference: false); var frameworkAssemblies = new List<LibraryRange>(); PopulateDependencies( project.ProjectFilePath, frameworkAssemblies, frameworkValue, "frameworkAssemblies", isGacOrFrameworkReference: true); frameworkDependencies.AddRange(frameworkAssemblies); targetFrameworkInformation.Dependencies = frameworkDependencies; targetFrameworkInformation.WrappedProject = frameworkValue.ValueAsString("wrappedProject"); var binNode = frameworkValue.ValueAsJsonObject("bin"); if (binNode != null) { targetFrameworkInformation.AssemblyPath = binNode.ValueAsString("assembly"); targetFrameworkInformation.PdbPath = binNode.ValueAsString("pdb"); } project._targetFrameworks[frameworkName] = targetFrameworkInformation; return true; }
private static bool TryGetStringEnumerable(JsonObject parent, string property, out IEnumerable<string> result) { var collection = new List<string>(); var valueInString = parent.ValueAsString(property); if (valueInString != null) { collection.Add(valueInString); } else { var valueInArray = parent.ValueAsStringArray(property); if (valueInArray != null) { collection.AddRange(valueInArray); } else { result = null; return false; } } result = collection.SelectMany(value => value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)); return true; }