C# Class MSBuild.Abstractions.MSBuildHelpers

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

Public Methods

Method 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

Method 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 method

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

AddUseWPF() public static method

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

AddUseWinForms() public static method

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

AddUseWinUI() public static method

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

ConditionToDimensionValues() public static method

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).
return bool

FrameworkHasAValueTuple() public static method

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

GetAllProjectTypeGuids() public static method

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

GetConfigurationName() public static method

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

GetConfigurationName() public static method

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

GetOrCreatePackageReferencesItemGroup() public static method

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

GetOrCreateTopLevelPropertyGroup() public static method

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
return ProjectPropertyGroupElement

GetOrCreateTopLevelPropertyGroupWithTFM() public static method

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

GetPackagesConfigItem() public static method

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

GetPackagesConfigItemGroup() public static method

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

HasProjectTypeGuidsNode() public static method

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

HasWPFOrWinForms() public static method

public static HasWPFOrWinForms ( ProjectPropertyGroupElement propGroup ) : bool
propGroup ProjectPropertyGroupElement
return bool

IsAspNetCore() public static method

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
return bool

IsDesktop() public static method

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

IsNETFrameworkMSTestProject() public static method

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

IsNotNetFramework() public static method

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

IsTargetFromNuGetPackage() public static method

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
return bool

IsUwp() public static method

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

IsValidMetadataForConversionPurposes() public static method

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

IsWPF() public static method

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

IsWeb() public static method

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

IsWebApp() public static method

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

IsWinForms() public static method

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

IsWindows() public static method

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