private void BuildTargetFrameworksAndConfigurations(JsonObject projectJsonObject, ICollection <ICompilationMessage> diagnostics) { // Get the shared compilationOptions _defaultCompilerOptions = GetCompilationOptions(projectJsonObject) ?? new CompilerOptions(); _defaultTargetFrameworkConfiguration = new TargetFrameworkInformation { Dependencies = new List <LibraryDependency>() }; // Add default configurations _configurations["Debug"] = new CompilerOptions { Defines = new[] { "DEBUG", "TRACE" }, Optimize = false }; _configurations["Release"] = new CompilerOptions { Defines = new[] { "RELEASE", "TRACE" }, Optimize = true }; // The configuration node has things like debug/release compiler settings /* * { * "configurations": { * "Debug": { * }, * "Release": { * } * } * } */ var configurations = projectJsonObject.ValueAsJsonObject("configurations"); if (configurations != null) { foreach (var configKey in configurations.Keys) { var compilerOptions = GetCompilationOptions(configurations.ValueAsJsonObject(configKey)); // Only use this as a configuration if it's not a target framework _configurations[configKey] = compilerOptions; } } // The frameworks node is where target frameworks go /* * { * "frameworks": { * "net45": { * }, * "k10": { * } * } * } */ var frameworks = projectJsonObject.ValueAsJsonObject("frameworks"); if (frameworks != null) { foreach (var frameworkKey in frameworks.Keys) { try { var frameworkToken = frameworks.ValueAsJsonObject(frameworkKey); var success = BuildTargetFrameworkNode(frameworkKey, frameworkToken); if (!success) { diagnostics?.Add( new FileFormatMessage( $"\"{frameworkKey}\" is an unsupported framework", ProjectFilePath, CompilationMessageSeverity.Error, frameworkToken)); } } catch (Exception ex) { throw FileFormatException.Create(ex, frameworks.Value(frameworkKey), 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(string frameworkKey, JsonObject frameworkValue) { // If no compilation options are provided then figure them out from the node var compilerOptions = GetCompilationOptions(frameworkValue) ?? new CompilerOptions(); var frameworkName = FrameworkNameHelper.ParseFrameworkName(frameworkKey); // If it's not unsupported then keep it if (frameworkName == VersionUtility.UnsupportedFrameworkName) { // 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 frameworkDefinition = Tuple.Create(frameworkKey, frameworkName); var frameworkDefine = FrameworkNameHelper.MakeDefaultTargetFrameworkDefine(frameworkDefinition); if (!string.IsNullOrEmpty(frameworkDefine)) { defines.Add(frameworkDefine); } compilerOptions.Defines = defines; var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = frameworkName, Dependencies = new List <LibraryDependency>() }; var frameworkDependencies = new List <LibraryDependency>(); PopulateDependencies( ProjectFilePath, frameworkDependencies, frameworkValue, "dependencies", isGacOrFrameworkReference: false); var frameworkAssemblies = new List <LibraryDependency>(); PopulateDependencies( 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"); } _compilationOptions[frameworkName] = compilerOptions; _targetFrameworks[frameworkName] = targetFrameworkInformation; return(true); }
private void BuildTargetFrameworksAndConfigurations(JObject rawProject) { // Get the shared compilationOptions _defaultCompilerOptions = GetCompilationOptions(rawProject) ?? _emptyOptions; _defaultTargetFrameworkConfiguration = new TargetFrameworkInformation { Dependencies = new List <LibraryDependency>() }; // Add default configurations _configurations["Debug"] = new CompilerOptions { Defines = new[] { "DEBUG", "TRACE" }, Optimize = false }; _configurations["Release"] = new CompilerOptions { Defines = new[] { "RELEASE", "TRACE" }, Optimize = true }; // The configuration node has things like debug/release compiler settings /* * { * "configurations": { * "Debug": { * }, * "Release": { * } * } * } */ var configurations = rawProject["configurations"] as JObject; if (configurations != null) { foreach (var configuration in configurations) { var compilerOptions = GetCompilationOptions(configuration.Value); // Only use this as a configuration if it's not a target framework _configurations[configuration.Key] = compilerOptions; } } // The frameworks node is where target frameworks go /* * { * "frameworks": { * "net45": { * }, * "k10": { * } * } * } */ var frameworks = rawProject["frameworks"] as JObject; if (frameworks != null) { foreach (var framework in frameworks) { try { BuildTargetFrameworkNode(framework); } catch (Exception ex) { throw FileFormatException.Create(ex, framework.Value, ProjectFilePath); } } } }
private void BuildTargetFrameworksAndConfigurations(JsonObject projectJsonObject, ICollection<ICompilationMessage> diagnostics) { // Get the shared compilationOptions _defaultCompilerOptions = GetCompilationOptions(projectJsonObject) ?? new CompilerOptions(); _defaultTargetFrameworkConfiguration = new TargetFrameworkInformation { Dependencies = new List<LibraryDependency>() }; // Add default configurations _configurations["Debug"] = new CompilerOptions { Defines = new[] { "DEBUG", "TRACE" }, Optimize = false }; _configurations["Release"] = new CompilerOptions { Defines = new[] { "RELEASE", "TRACE" }, Optimize = true }; // The configuration node has things like debug/release compiler settings /* { "configurations": { "Debug": { }, "Release": { } } } */ var configurations = projectJsonObject.ValueAsJsonObject("configurations"); if (configurations != null) { foreach (var configKey in configurations.Keys) { var compilerOptions = GetCompilationOptions(configurations.ValueAsJsonObject(configKey)); // Only use this as a configuration if it's not a target framework _configurations[configKey] = compilerOptions; } } // The frameworks node is where target frameworks go /* { "frameworks": { "net45": { }, "k10": { } } } */ var frameworks = projectJsonObject.ValueAsJsonObject("frameworks"); if (frameworks != null) { foreach (var frameworkKey in frameworks.Keys) { try { var frameworkToken = frameworks.ValueAsJsonObject(frameworkKey); var success = BuildTargetFrameworkNode(frameworkKey, frameworkToken); if (!success) { diagnostics?.Add( new FileFormatMessage( $"\"{frameworkKey}\" is an unsupported framework", ProjectFilePath, CompilationMessageSeverity.Error, frameworkToken)); } } catch (Exception ex) { throw FileFormatException.Create(ex, frameworks.Value(frameworkKey), 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(string frameworkKey, JsonObject frameworkValue) { // If no compilation options are provided then figure them out from the node var compilerOptions = GetCompilationOptions(frameworkValue) ?? new CompilerOptions(); var frameworkName = FrameworkNameHelper.ParseFrameworkName(frameworkKey); // If it's not unsupported then keep it if (frameworkName == VersionUtility.UnsupportedFrameworkName) { // 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 frameworkDefinition = Tuple.Create(frameworkKey, frameworkName); var frameworkDefine = FrameworkNameHelper.MakeDefaultTargetFrameworkDefine(frameworkDefinition); if (!string.IsNullOrEmpty(frameworkDefine)) { defines.Add(frameworkDefine); } compilerOptions.Defines = defines; var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = frameworkName, Dependencies = new List<LibraryDependency>() }; var frameworkDependencies = new List<LibraryDependency>(); PopulateDependencies( ProjectFilePath, frameworkDependencies, frameworkValue, "dependencies", isGacOrFrameworkReference: false); var frameworkAssemblies = new List<LibraryDependency>(); PopulateDependencies( 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"); } _compilationOptions[frameworkName] = compilerOptions; _targetFrameworks[frameworkName] = targetFrameworkInformation; return true; }
private void BuildTargetFrameworksAndConfigurations(JObject rawProject) { // Get the shared compilationOptions _defaultCompilerOptions = GetCompilationOptions(rawProject) ?? _emptyOptions; _defaultTargetFrameworkConfiguration = new TargetFrameworkInformation { Dependencies = new List<LibraryDependency>() }; // Add default configurations _configurations["Debug"] = new CompilerOptions { Defines = new[] { "DEBUG", "TRACE" }, Optimize = false }; _configurations["Release"] = new CompilerOptions { Defines = new[] { "RELEASE", "TRACE" }, Optimize = true }; // The configuration node has things like debug/release compiler settings /* { "configurations": { "Debug": { }, "Release": { } } } */ var configurations = rawProject["configurations"] as JObject; if (configurations != null) { foreach (var configuration in configurations) { var compilerOptions = GetCompilationOptions(configuration.Value); // Only use this as a configuration if it's not a target framework _configurations[configuration.Key] = compilerOptions; } } // The frameworks node is where target frameworks go /* { "frameworks": { "net45": { }, "k10": { } } } */ var frameworks = rawProject["frameworks"] as JObject; if (frameworks != null) { foreach (var framework in frameworks) { try { BuildTargetFrameworkNode(framework); } catch (Exception ex) { throw FileFormatException.Create(ex, framework.Value, ProjectFilePath); } } } }
private bool BuildTargetFrameworkNode(KeyValuePair <string, JToken> targetFramework) { // If no compilation options are provided then figure them out from the node var compilerOptions = GetCompilationOptions(targetFramework.Value) ?? new CompilerOptions(); var frameworkName = ParseFrameworkName(targetFramework.Key); // If it's not unsupported then keep it if (frameworkName == VersionUtility.UnsupportedFrameworkName) { // 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 frameworkDefinition = Tuple.Create(targetFramework.Key, frameworkName); var frameworkDefine = MakeDefaultTargetFrameworkDefine(frameworkDefinition); if (!string.IsNullOrEmpty(frameworkDefine)) { defines.Add(frameworkDefine); } compilerOptions.Defines = defines; var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = frameworkName, Dependencies = new List <LibraryDependency>() }; var properties = targetFramework.Value.Value <JObject>(); PopulateDependencies( targetFrameworkInformation.Dependencies, properties, "dependencies", isGacOrFrameworkReference: false); var frameworkAssemblies = new List <LibraryDependency>(); PopulateDependencies( frameworkAssemblies, properties, "frameworkAssemblies", isGacOrFrameworkReference: true); targetFrameworkInformation.Dependencies.AddRange(frameworkAssemblies); var binNode = properties["bin"]; if (binNode != null) { targetFrameworkInformation.AssemblyPath = GetValue <string>(binNode, "assembly"); targetFrameworkInformation.PdbPath = GetValue <string>(binNode, "pdb"); } _compilationOptions[frameworkName] = compilerOptions; _targetFrameworks[frameworkName] = targetFrameworkInformation; return(true); }