private void AddFrameworks(RuntimeOptions runtimeOptions, ProjectContext projectContext) { if (projectContext.IsFrameworkDependent) { runtimeOptions.Tfm = TargetFramework; runtimeOptions.RollForward = RollForward; if (projectContext.RuntimeFrameworks == null || projectContext.RuntimeFrameworks.Length == 0) { // If there are no RuntimeFrameworks (which would be set in the ProcessFrameworkReferences 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); } } } } }
private void AddFramework(RuntimeOptions runtimeOptions, ProjectContext projectContext) { if (projectContext.IsPortable) { var platformLibrary = projectContext.PlatformLibrary; if (platformLibrary != null) { RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = platformLibrary.Name; framework.Version = platformLibrary.Version.ToNormalizedString(); runtimeOptions.Framework = framework; } } }
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) { 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); } } } } }
private void AddFrameworks(RuntimeOptions runtimeOptions, ProjectContext.RuntimeFramework[] runtimeFrameworks, LockFileTargetLibrary lockFilePlatformLibrary, bool isFrameworkDependent) { runtimeOptions.Tfm = TargetFramework; var frameworks = new List <RuntimeConfigFramework>(); if (runtimeFrameworks == null || runtimeFrameworks.Length == 0) { // If the project is not targetting .NET Core, it will not have any platform library (and is marked as non-FrameworkDependent). if (lockFilePlatformLibrary != null) { // If there are no RuntimeFrameworks (which would be set in the ProcessFrameworkReferences task based // on FrameworkReference items), then use package resolved from MicrosoftNETPlatformLibrary for // the runtimeconfig RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = lockFilePlatformLibrary.Name; framework.Version = lockFilePlatformLibrary.Version.ToNormalizedString(); frameworks.Add(framework); } } else { HashSet <string> usedFrameworkNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var platformLibrary in runtimeFrameworks) { if (runtimeFrameworks.Length > 1 && platformLibrary.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase) && isFrameworkDependent) { // If there are multiple runtime frameworks, then exclude Microsoft.NETCore.App, // as a workaround for https://github.com/dotnet/core-setup/issues/4947 // The workaround only applies to normal framework references, included frameworks // (in self-contained apps) must list all frameworks. continue; } // Don't add multiple entries for the same shared framework. // This is necessary if there are FrameworkReferences to different profiles // that map to the same shared framework. if (!usedFrameworkNames.Add(platformLibrary.Name)) { continue; } RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = platformLibrary.Name; framework.Version = platformLibrary.Version; frameworks.Add(framework); } } if (isFrameworkDependent) { runtimeOptions.RollForward = RollForward; // 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 (frameworks.Count == 1) { runtimeOptions.Framework = frameworks[0]; } else { runtimeOptions.Frameworks = frameworks; } } else if (WriteIncludedFrameworks) { // Self-contained apps don't have framework references, instead write the frameworks // into the includedFrameworks property. runtimeOptions.IncludedFrameworks = frameworks; } }
private void AddFrameworks(RuntimeOptions runtimeOptions, ProjectContext.RuntimeFramework[] runtimeFrameworks, LockFileTargetLibrary lockFilePlatformLibrary, bool isFrameworkDependent) { runtimeOptions.Tfm = NuGetFramework.Parse(TargetFrameworkMoniker).GetShortFolderName(); var frameworks = new List <RuntimeConfigFramework>(); if (runtimeFrameworks == null || runtimeFrameworks.Length == 0) { // If the project is not targetting .NET Core, it will not have any platform library (and is marked as non-FrameworkDependent). if (lockFilePlatformLibrary != null) { // If there are no RuntimeFrameworks (which would be set in the ProcessFrameworkReferences task based // on FrameworkReference items), then use package resolved from MicrosoftNETPlatformLibrary for // the runtimeconfig RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = lockFilePlatformLibrary.Name; framework.Version = lockFilePlatformLibrary.Version.ToNormalizedString(); frameworks.Add(framework); } } else { HashSet <string> usedFrameworkNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var platformLibrary in runtimeFrameworks) { // In earlier versions of the SDK, we would exclude Microsoft.NETCore.App from the frameworks listed in the runtimeconfig file. // This was originally a workaround for a bug: https://github.com/dotnet/core-setup/issues/4947 // We would only do this for framework-dependent apps, as the full list was required for self-contained apps. // As the bug is fixed, we now always include the Microsoft.NETCore.App framework by default for .NET Core 6 and higher if (!AlwaysIncludeCoreFramework && runtimeFrameworks.Length > 1 && platformLibrary.Name.Equals("Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase) && isFrameworkDependent) { continue; } // Don't add multiple entries for the same shared framework. // This is necessary if there are FrameworkReferences to different profiles // that map to the same shared framework. if (!usedFrameworkNames.Add(platformLibrary.Name)) { continue; } RuntimeConfigFramework framework = new RuntimeConfigFramework(); framework.Name = platformLibrary.Name; framework.Version = platformLibrary.Version; frameworks.Add(framework); } } if (isFrameworkDependent) { runtimeOptions.RollForward = RollForward; // 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 (frameworks.Count == 1) { runtimeOptions.Framework = frameworks[0]; } else { runtimeOptions.Frameworks = frameworks; } } else if (WriteIncludedFrameworks) { // Self-contained apps don't have framework references, instead write the frameworks // into the includedFrameworks property. runtimeOptions.IncludedFrameworks = frameworks; } }