C# Class MSBuild.Abstractions.MSBuildHelpers

Static helper methods for working with general MSBuildisms.
Afficher le fichier Open project: dotnet/upgrade-assistant Class Usage Examples

Méthodes publiques

Méthode Description
AddImportWindowsDesktopTargets ( ProjectPropertyGroupElement propGroup ) : void

Adds the ImportWindowsDesktopTargets=true property to ensure builds targeting .NET Framework will succeed.

AddUseWPF ( ProjectPropertyGroupElement propGroup ) : void

Adds the UseWPF=true property to the top-level project property group.

AddUseWinForms ( ProjectPropertyGroupElement propGroup ) : void

Adds the UseWindowsForms=True property to the top-level project property group.

AddUseWinUI ( ProjectPropertyGroupElement propGroup ) : void

Adds the UseWinUI=true property to the top-level project property group.

ConditionToDimensionValues ( string condition, ImmutableDictionary &dimensionalValues ) : bool

Tries to parse an MSBuild condition to a dimensional vector only matches standard pattern: '$(DimensionName1)|$(DimensionName2)|...|$(DimensionNameN)'=='DimensionValue1|...|DimensionValueN'.

FrameworkHasAValueTuple ( string tfm ) : bool

Given a TFM string, determines if that TFM has an explicit System.ValueTuple reference.

GetAllProjectTypeGuids ( IProjectRootElement root ) : IEnumerable

Gets a flat list of all project type guids.

GetConfigurationName ( ImmutableDictionary dimensionValues ) : string

Returns a name of a configuration like Debug|AnyCPU.

GetConfigurationName ( string condition ) : string

Returns a name of a configuration like Debug|AnyCPU.

GetOrCreatePackageReferencesItemGroup ( IProjectRootElement rootElement ) : ProjectItemGroupElement

Finds the item group where PackageReferences are specified. Usually there is only one.

GetOrCreateTopLevelPropertyGroup ( BaselineProject baselineProject, IProjectRootElement projectRootElement ) : ProjectPropertyGroupElement

Gets the top-level property group, and if it doesn't exist, creates it.

GetOrCreateTopLevelPropertyGroupWithTFM ( IProjectRootElement rootElement ) : ProjectPropertyGroupElement

Finds the property group with the TFM specified, which is normally the top-level property group.

GetPackagesConfigItem ( ProjectItemGroupElement packagesConfigItemGroup ) : ProjectItemElement

Finds the packages.config item in its containing item group.

GetPackagesConfigItemGroup ( IProjectRootElement root ) : ProjectItemGroupElement?

Finds the item group where a packages.config is included. Assumes only one.

HasProjectTypeGuidsNode ( IProjectRootElement root ) : bool

Checks if a root has a project type guids node.

HasWPFOrWinForms ( ProjectPropertyGroupElement propGroup ) : bool
IsAspNetCore ( IProjectRootElement projectRoot, string tfm ) : bool

Determines if a project should be treated as an ASP.NET Core project (as opposed to classic ASP.NET). Returns true if the project is a web app (since there's no good way to build an ASP.NET app with an SDK-style project except to upgrade to ASP.NET Core) or the project has web dependencies and will target .NET/.NET Core.

IsDesktop ( IProjectRootElement projectRoot ) : bool

Determines if a given project references Desktop assemblies.

IsNETFrameworkMSTestProject ( IProjectRootElement projectRoot ) : bool

Determines if a project is a .NET Framework MSTest project by looking at its references.

IsNotNetFramework ( string tfm ) : bool

Checks if a given TFM is not .NET Framework.

IsTargetFromNuGetPackage ( ProjectImportElement import ) : bool

Checks if an import is a target that comes from the packages directory (which would mean it's probably brought in via a NuGet package).

IsUwp ( IProjectRootElement projectRoot ) : bool

Determines if a given project is UWP.

IsValidMetadataForConversionPurposes ( IProjectMetadata projectMetadata ) : bool

Checks if a metadata item can stay or if it needs to be converted.

IsWPF ( IProjectRootElement projectRoot ) : bool

Determines if a given project is a WPF project by looking at its references.

IsWeb ( IProjectRootElement projectRoot ) : bool

Determines if a given project references ASP.NET assemblies.

IsWebApp ( IProjectRootElement projectRoot ) : bool

Determines if a given project uses ASP.NET web app project type guid.

IsWinForms ( IProjectRootElement projectRoot ) : bool

Determines if a given project is a WinForms project by looking at its references.

IsWindows ( string tfm ) : bool

Checks if a given TFM include -windows.

Private Methods

Méthode Description
DimensionalValuePairsToCondition ( ImmutableDictionary dimensionalValues ) : string

Converts configuration dimensional value vector to a msbuild condition Use the standard format of '$(DimensionName1)|$(DimensionName2)|...|$(DimensionNameN)'=='DimensionValue1|...|DimensionValueN'.

GetPackageReferences ( ProjectItemGroupElement itemGroup ) : IEnumerable

Gets all PackageReference items from a given item group.

GetReferences ( ProjectItemGroupElement itemGroup ) : IEnumerable

Gets all Reference items from a given item group.

Method Details

AddImportWindowsDesktopTargets() public static méthode

Adds the ImportWindowsDesktopTargets=true property to ensure builds targeting .NET Framework will succeed.
public static AddImportWindowsDesktopTargets ( ProjectPropertyGroupElement propGroup ) : void
propGroup ProjectPropertyGroupElement
Résultat void

AddUseWPF() public static méthode

Adds the UseWPF=true property to the top-level project property group.
public static AddUseWPF ( ProjectPropertyGroupElement propGroup ) : void
propGroup ProjectPropertyGroupElement
Résultat void

AddUseWinForms() public static méthode

Adds the UseWindowsForms=True property to the top-level project property group.
public static AddUseWinForms ( ProjectPropertyGroupElement propGroup ) : void
propGroup ProjectPropertyGroupElement
Résultat void

AddUseWinUI() public static méthode

Adds the UseWinUI=true property to the top-level project property group.
public static AddUseWinUI ( ProjectPropertyGroupElement propGroup ) : void
propGroup ProjectPropertyGroupElement
Résultat void

ConditionToDimensionValues() public static méthode

Tries to parse an MSBuild condition to a dimensional vector only matches standard pattern: '$(DimensionName1)|$(DimensionName2)|...|$(DimensionNameN)'=='DimensionValue1|...|DimensionValueN'.
public static ConditionToDimensionValues ( string condition, ImmutableDictionary &dimensionalValues ) : bool
condition string msbuild condition string.
dimensionalValues ImmutableDictionary configuration dimensions vector (output).
Résultat bool

FrameworkHasAValueTuple() public static méthode

Given a TFM string, determines if that TFM has an explicit System.ValueTuple reference.
public static FrameworkHasAValueTuple ( string tfm ) : bool
tfm string
Résultat bool

GetAllProjectTypeGuids() public static méthode

Gets a flat list of all project type guids.
public static GetAllProjectTypeGuids ( IProjectRootElement root ) : IEnumerable
root IProjectRootElement
Résultat IEnumerable

GetConfigurationName() public static méthode

Returns a name of a configuration like Debug|AnyCPU.
public static GetConfigurationName ( ImmutableDictionary dimensionValues ) : string
dimensionValues ImmutableDictionary
Résultat string

GetConfigurationName() public static méthode

Returns a name of a configuration like Debug|AnyCPU.
public static GetConfigurationName ( string condition ) : string
condition string
Résultat string

GetOrCreatePackageReferencesItemGroup() public static méthode

Finds the item group where PackageReferences are specified. Usually there is only one.
public static GetOrCreatePackageReferencesItemGroup ( IProjectRootElement rootElement ) : ProjectItemGroupElement
rootElement IProjectRootElement
Résultat ProjectItemGroupElement

GetOrCreateTopLevelPropertyGroup() public static méthode

Gets the top-level property group, and if it doesn't exist, creates it.
public static GetOrCreateTopLevelPropertyGroup ( BaselineProject baselineProject, IProjectRootElement projectRootElement ) : ProjectPropertyGroupElement
baselineProject BaselineProject
projectRootElement IProjectRootElement
Résultat ProjectPropertyGroupElement

GetOrCreateTopLevelPropertyGroupWithTFM() public static méthode

Finds the property group with the TFM specified, which is normally the top-level property group.
public static GetOrCreateTopLevelPropertyGroupWithTFM ( IProjectRootElement rootElement ) : ProjectPropertyGroupElement
rootElement IProjectRootElement
Résultat ProjectPropertyGroupElement

GetPackagesConfigItem() public static méthode

Finds the packages.config item in its containing item group.
public static GetPackagesConfigItem ( ProjectItemGroupElement packagesConfigItemGroup ) : ProjectItemElement
packagesConfigItemGroup ProjectItemGroupElement
Résultat ProjectItemElement

GetPackagesConfigItemGroup() public static méthode

Finds the item group where a packages.config is included. Assumes only one.
public static GetPackagesConfigItemGroup ( IProjectRootElement root ) : ProjectItemGroupElement?
root IProjectRootElement
Résultat ProjectItemGroupElement?

HasProjectTypeGuidsNode() public static méthode

Checks if a root has a project type guids node.
public static HasProjectTypeGuidsNode ( IProjectRootElement root ) : bool
root IProjectRootElement
Résultat bool

HasWPFOrWinForms() public static méthode

public static HasWPFOrWinForms ( ProjectPropertyGroupElement propGroup ) : bool
propGroup ProjectPropertyGroupElement
Résultat bool

IsAspNetCore() public static méthode

Determines if a project should be treated as an ASP.NET Core project (as opposed to classic ASP.NET). Returns true if the project is a web app (since there's no good way to build an ASP.NET app with an SDK-style project except to upgrade to ASP.NET Core) or the project has web dependencies and will target .NET/.NET Core.
public static IsAspNetCore ( IProjectRootElement projectRoot, string tfm ) : bool
projectRoot IProjectRootElement
tfm string
Résultat bool

IsDesktop() public static méthode

Determines if a given project references Desktop assemblies.
public static IsDesktop ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsNETFrameworkMSTestProject() public static méthode

Determines if a project is a .NET Framework MSTest project by looking at its references.
public static IsNETFrameworkMSTestProject ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsNotNetFramework() public static méthode

Checks if a given TFM is not .NET Framework.
public static IsNotNetFramework ( string tfm ) : bool
tfm string
Résultat bool

IsTargetFromNuGetPackage() public static méthode

Checks if an import is a target that comes from the packages directory (which would mean it's probably brought in via a NuGet package).
public static IsTargetFromNuGetPackage ( ProjectImportElement import ) : bool
import ProjectImportElement
Résultat bool

IsUwp() public static méthode

Determines if a given project is UWP.
public static IsUwp ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsValidMetadataForConversionPurposes() public static méthode

Checks if a metadata item can stay or if it needs to be converted.
public static IsValidMetadataForConversionPurposes ( IProjectMetadata projectMetadata ) : bool
projectMetadata IProjectMetadata
Résultat bool

IsWPF() public static méthode

Determines if a given project is a WPF project by looking at its references.
public static IsWPF ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsWeb() public static méthode

Determines if a given project references ASP.NET assemblies.
public static IsWeb ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsWebApp() public static méthode

Determines if a given project uses ASP.NET web app project type guid.
public static IsWebApp ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsWinForms() public static méthode

Determines if a given project is a WinForms project by looking at its references.
public static IsWinForms ( IProjectRootElement projectRoot ) : bool
projectRoot IProjectRootElement
Résultat bool

IsWindows() public static méthode

Checks if a given TFM include -windows.
public static IsWindows ( string tfm ) : bool
tfm string
Résultat bool