Documentation
¶
Overview ¶
Package frameworks provides Target Framework Moniker (TFM) parsing and compatibility checking.
It supports parsing TFMs for .NET, .NET Standard, .NET Core, .NET Framework, and PCL.
Example:
fw, err := frameworks.ParseFramework("net8.0")
if err != nil {
log.Fatal(err)
}
fmt.Println(fw.Framework, fw.Version.Major) // .NETCoreApp 8
Index ¶
- Variables
- func GetFrameworkPrecedence(framework string) int
- func IsCompatible(pkg, target *NuGetFramework) bool
- func NormalizeFrameworkName(frameworkName string) string
- type FrameworkNameProvider
- type FrameworkReducer
- type FrameworkVersion
- type NuGetFramework
- func (fw *NuGetFramework) Equals(other *NuGetFramework) bool
- func (fw *NuGetFramework) GetShortFolderName(provider FrameworkNameProvider) string
- func (fw *NuGetFramework) IsAny() bool
- func (fw *NuGetFramework) IsCompatible(target *NuGetFramework) bool
- func (fw *NuGetFramework) IsNet5Era() bool
- func (fw *NuGetFramework) IsPCL() bool
- func (fw *NuGetFramework) IsSpecificFramework() bool
- func (fw *NuGetFramework) String() string
Constants ¶
This section is empty.
Variables ¶
var AnyFramework = NuGetFramework{ Framework: "Any", Version: FrameworkVersion{Major: 0, Minor: 0, Build: 0, Revision: 0}, }
AnyFramework represents the special "any" framework that matches all target frameworks. Used for dependencies without a target framework group.
var CommonFrameworks = struct { DotNet *NuGetFramework Net *NuGetFramework }{ DotNet: &NuGetFramework{ Framework: ".NETCoreApp", Version: FrameworkVersion{Major: 5, Minor: 0}, }, Net: &NuGetFramework{ Framework: ".NETFramework", Version: FrameworkVersion{Major: 4, Minor: 5}, }, }
CommonFrameworks provides common .NET framework instances.
var FrameworkCompatibilityMap = map[string][]string{
".NETStandard": {
".NETFramework",
".NETCoreApp",
".NETStandard",
},
".NETCoreApp": {
".NETStandard",
".NETCoreApp",
},
".NETFramework": {
".NETStandard",
".NETFramework",
},
}
FrameworkCompatibilityMap defines which frameworks are compatible with which.
var FrameworkPrecedence = []string{
".NETStandard",
".NETCoreApp",
".NETFramework",
}
FrameworkPrecedence defines the precedence order for framework selection. Higher index = higher precedence.
var FrameworkShortNames = map[string]string{
"net": ".NETFramework",
"netframework": ".NETFramework",
"netstandard": ".NETStandard",
"netcoreapp": ".NETCoreApp",
"netcore": "NetCore",
"uap": "UAP",
"tizen": "Tizen",
"monoandroid": "MonoAndroid",
"xamarinios": "Xamarin.iOS",
"xamarinmac": "Xamarin.Mac",
}
FrameworkShortNames maps short names to full framework identifiers.
var FrameworkToNetStandardTable = map[string]map[string]string{
"Tizen": {
"3.0": "1.6",
"4.0": "2.0",
"6.0": "2.1",
},
"UAP": {
"10.0.15064": "2.0",
"*": "1.4",
},
".NETCoreApp": {
"1.0": "1.6",
"1.1": "1.7",
"2.0": "2.0",
"3.0": "2.1",
},
".NETFramework": {
"4.5": "1.1",
"4.5.1": "1.2",
"4.5.2": "1.2",
"4.6": "1.3",
"4.6.1": "2.0",
"4.6.2": "2.0",
"4.6.3": "2.0",
"4.7": "2.0",
"4.7.1": "2.0",
"4.7.2": "2.0",
"4.8": "2.0",
"4.8.1": "2.0",
},
"WindowsPhoneApp": {
"8.1": "1.2",
},
"WindowsPhone": {
"8.0": "1.0",
"8.1": "1.0",
},
"NetCore": {
"4.5": "1.1",
"4.5.1": "1.2",
"5.0": "1.4",
},
"DNXCore": {
"*": "1.5",
},
"MonoAndroid": {
"*": "2.1",
},
"MonoMac": {
"*": "2.1",
},
"MonoTouch": {
"*": "2.1",
},
"Xamarin.iOS": {
"*": "2.1",
},
"Xamarin.Mac": {
"*": "2.1",
},
"Xamarin.PlayStation3": {
"*": "2.0",
},
"Xamarin.PlayStation4": {
"*": "2.0",
},
"Xamarin.PlayStationVita": {
"*": "2.0",
},
"Xamarin.Xbox360": {
"*": "2.0",
},
"Xamarin.XboxOne": {
"*": "2.0",
},
"Xamarin.TVOS": {
"*": "2.1",
},
"Xamarin.WatchOS": {
"*": "2.1",
},
}
FrameworkToNetStandardTable maps various frameworks to their .NET Standard support.
Source: DefaultFrameworkMappings.cs
var NetStandardCompatibilityTable = map[versionKey]FrameworkVersion{
{1, 0}: {4, 5, 0, 0},
{1, 1}: {4, 5, 0, 0},
{1, 2}: {4, 5, 1, 0},
{1, 3}: {4, 6, 0, 0},
{1, 4}: {4, 6, 1, 0},
{1, 5}: {4, 6, 1, 0},
{1, 6}: {4, 6, 1, 0},
{2, 0}: {4, 6, 1, 0},
}
NetStandardCompatibilityTable defines .NET Standard → .NET Framework version mappings. Maps .NET Standard version to minimum .NET Framework version.
Source: DefaultFrameworkMappings.cs
var NetStandardToCoreAppTable = map[versionKey]FrameworkVersion{
{1, 0}: {1, 0, 0, 0},
{1, 1}: {1, 0, 0, 0},
{1, 2}: {1, 0, 0, 0},
{1, 3}: {1, 0, 0, 0},
{1, 4}: {1, 0, 0, 0},
{1, 5}: {1, 0, 0, 0},
{1, 6}: {1, 0, 0, 0},
{1, 7}: {1, 1, 0, 0},
{2, 0}: {2, 0, 0, 0},
{2, 1}: {3, 0, 0, 0},
}
NetStandardToCoreAppTable defines .NET Standard → .NET Core version mappings.
Source: DefaultFrameworkMappings.cs
Functions ¶
func GetFrameworkPrecedence ¶
GetFrameworkPrecedence returns the precedence value for a framework. Higher value = higher precedence.
func IsCompatible ¶
func IsCompatible(pkg, target *NuGetFramework) bool
IsCompatible checks if the package framework is compatible with the target framework. This is a convenience function that wraps the NuGetFramework.IsCompatible method.
func NormalizeFrameworkName ¶
NormalizeFrameworkName converts various framework name formats to the standard TFM short folder name. It handles:
- V3 registration API format: ".NETStandard2.0" -> "netstandard2.0"
- Full framework names: ".NETCoreApp,Version=v2.2" -> "netcoreapp2.2"
- Already normalized names: "netstandard2.0" -> "netstandard2.0" (passthrough)
Types ¶
type FrameworkNameProvider ¶
type FrameworkNameProvider interface {
// TryGetShortIdentifier gets the short framework identifier.
TryGetShortIdentifier(identifier string) (string, bool)
// GetVersionString formats a version for the given framework.
GetVersionString(framework string, version FrameworkVersion) string
// TryGetShortProfile gets the short profile name.
TryGetShortProfile(framework, profile string) (string, bool)
// TryGetPortableFrameworks parses a portable profile string into frameworks.
TryGetPortableFrameworks(profile string, includeOptional bool) ([]*NuGetFramework, bool)
// TryGetPortableProfile gets the profile number for a set of frameworks.
TryGetPortableProfile(frameworks []*NuGetFramework) (int, bool)
}
FrameworkNameProvider provides framework name mappings and formatting. Reference: DefaultFrameworkNameProvider in NuGet.Client
func DefaultFrameworkNameProvider ¶
func DefaultFrameworkNameProvider() FrameworkNameProvider
DefaultFrameworkNameProvider returns the default framework name provider.
type FrameworkReducer ¶
type FrameworkReducer struct{}
FrameworkReducer helps find the nearest compatible framework.
func NewFrameworkReducer ¶
func NewFrameworkReducer() *FrameworkReducer
NewFrameworkReducer creates a new framework reducer.
func (*FrameworkReducer) GetNearest ¶
func (fr *FrameworkReducer) GetNearest(target *NuGetFramework, available []*NuGetFramework) *NuGetFramework
GetNearest finds the nearest compatible framework from available frameworks.
type FrameworkVersion ¶
FrameworkVersion represents a framework version number.
func (FrameworkVersion) Compare ¶
func (v FrameworkVersion) Compare(other FrameworkVersion) int
Compare compares two framework versions. Returns -1 if v < other, 0 if v == other, 1 if v > other.
func (FrameworkVersion) IsEmpty ¶
func (v FrameworkVersion) IsEmpty() bool
IsEmpty returns true if the version is empty (0.0.0.0).
func (FrameworkVersion) String ¶
func (v FrameworkVersion) String() string
String returns the string representation of the framework version. It trims trailing zero components to match NuGet.Client behavior:
- 4.7.2.0 → "4.7.2"
- 6.0.0.0 → "6.0"
- 4.8.0.0 → "4.8"
- 1.0.0.0 → "1.0"
type NuGetFramework ¶
type NuGetFramework struct {
// Framework is the framework identifier (e.g., ".NETFramework", ".NETStandard")
Framework string
// Version is the framework version
Version FrameworkVersion
// Platform is the platform identifier (e.g., "windows", "android")
Platform string
// PlatformVersion is the platform version
PlatformVersion FrameworkVersion
// Profile is used for PCL (Portable Class Library) profiles
Profile string
// contains filtered or unexported fields
}
NuGetFramework represents a Target Framework Moniker (TFM).
func GetNearest ¶
func GetNearest(target *NuGetFramework, available []*NuGetFramework) *NuGetFramework
GetNearest finds the nearest compatible framework from a list.
Given a target framework and a list of available frameworks, returns the most compatible one, preferring: 1. Exact match 2. Same framework, nearest lower version 3. Compatible framework with highest precedence
Returns nil if no compatible framework found.
func MustParseFramework ¶
func MustParseFramework(tfm string) *NuGetFramework
MustParseFramework parses a TFM and panics on error.
func ParseFramework ¶
func ParseFramework(tfm string) (*NuGetFramework, error)
ParseFramework parses a TFM string into a NuGetFramework.
Supported formats:
net10.0 - .NET 10.0 (.NETCoreApp) net9.0 - .NET 9.0 (.NETCoreApp) net8.0 - .NET 8.0 (.NETCoreApp) net5.0 - .NET 5.0 (.NETCoreApp) netstandard2.1 - .NET Standard 2.1 netcoreapp3.1 - .NET Core 3.1 net481 - .NET Framework 4.8.1 (compact: 3-digit) net48 - .NET Framework 4.8 (compact: 2-digit) net4721 - .NET Framework 4.7.2.1 (compact: 4-digit) net6.0-windows - .NET 6.0 for Windows (platform-specific) portable-net45+win8 - PCL Profile
.NET 5+ (net5.0, net6.0, etc.) maps to .NETCoreApp. .NET Framework 4.x and below (net48, net472, etc.) maps to .NETFramework. Compact versions support 2-4 digits without dots (net48, net472, net4721).
Returns an error if the TFM string is invalid.
func (*NuGetFramework) Equals ¶
func (fw *NuGetFramework) Equals(other *NuGetFramework) bool
Equals checks if two frameworks are equal.
func (*NuGetFramework) GetShortFolderName ¶
func (fw *NuGetFramework) GetShortFolderName(provider FrameworkNameProvider) string
GetShortFolderName returns the short folder name representation of the framework. This matches NuGet.Client's GetShortFolderName implementation.
func (*NuGetFramework) IsAny ¶
func (fw *NuGetFramework) IsAny() bool
IsAny returns true if this framework represents the special "any" framework.
func (*NuGetFramework) IsCompatible ¶
func (fw *NuGetFramework) IsCompatible(target *NuGetFramework) bool
IsCompatible checks if this framework is compatible with the target framework.
Returns true if a package targeting this framework can be used by the target.
Example:
netstandard2.0.IsCompatible(net6.0) → true net48.IsCompatible(netstandard2.1) → false
func (*NuGetFramework) IsNet5Era ¶
func (fw *NuGetFramework) IsNet5Era() bool
IsNet5Era returns true if this is .NET 5+ (.NETCoreApp with version >= 5).
func (*NuGetFramework) IsPCL ¶
func (fw *NuGetFramework) IsPCL() bool
IsPCL returns true if this is a Portable Class Library framework.
func (*NuGetFramework) IsSpecificFramework ¶
func (fw *NuGetFramework) IsSpecificFramework() bool
IsSpecificFramework returns true if this is a specific framework (not special or unsupported).
func (*NuGetFramework) String ¶
func (fw *NuGetFramework) String() string
String returns the string representation of the framework.