private void AddFrameworks()

in src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs [101:155]


        private void AddFrameworks(RuntimeOptions runtimeOptions, ProjectContext projectContext)
        {
            if (projectContext.IsFrameworkDependent)
            {
                runtimeOptions.tfm = TargetFramework;

                if (projectContext.RuntimeFrameworks == null || projectContext.RuntimeFrameworks.Length == 0)
                {
                    //  If there are no RuntimeFrameworks (which would be set in the ResolveFrameworkReference task based
                    //  on FrameworkReference items), then use package resolved from MicrosoftNETPlatformLibrary for
                    //  the runtimeconfig
                    RuntimeConfigFramework framework = new RuntimeConfigFramework();
                    framework.Name = projectContext.PlatformLibrary.Name;
                    framework.Version = projectContext.PlatformLibrary.Version.ToNormalizedString();

                    runtimeOptions.Framework = framework;
                }
                else
                {
                    foreach (var platformLibrary in projectContext.RuntimeFrameworks)
                    {
                        if (projectContext.RuntimeFrameworks.Length > 1 &&
                            platformLibrary.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase))
                        {
                            //  If there are multiple runtime frameworks, then exclude Microsoft.NETCore.App,
                            //  as a workaround for https://github.com/dotnet/core-setup/issues/4947
                            continue;
                        }

                        RuntimeConfigFramework framework = new RuntimeConfigFramework();
                        framework.Name = platformLibrary.Name;
                        framework.Version = platformLibrary.Version;

                        //  If there is only one runtime framework, then it goes in the framework property of the json
                        //  If there are multiples, then we leave the framework property unset and put the list in
                        //  the frameworks property.
                        if (runtimeOptions.Framework == null && runtimeOptions.Frameworks == null)
                        {
                            runtimeOptions.Framework = framework;
                        }
                        else
                        {
                            if (runtimeOptions.Frameworks == null)
                            {
                                runtimeOptions.Frameworks = new List<RuntimeConfigFramework>();
                                runtimeOptions.Frameworks.Add(runtimeOptions.Framework);
                                runtimeOptions.Framework = null;
                            }

                            runtimeOptions.Frameworks.Add(framework);
                        }
                    }
                }
            }
        }