ProjectParserExtensions.

GetPackage(CustomProjectParserResult, string, string) Method

Summary

Gets a project package reference

Syntax

public static PackageReference GetPackage(this CustomProjectParserResult projectParserResult, string packageName, string targetFramework = null)

Examples

Get the NUnit package reference
CustomParseProjectResult project 
        = ParseProject(new FilePath("test.csproj"), configuration: "Release", platform: "x86");

PackageReference ref = project.GetReference("NUnit");
string nUnitVersion = ref.Version;

PackageReference ref = project.GetReference("NUnit", "netstandard2.0");
string nUnitVersion = ref.Version;

Parameters

Name Type Description
projectParserResult CustomProjectParserResult the parsed project
packageName string the package name
targetFramework string the specific targetframework, if not specified, returns the package for any TargetFramework

Return Value

Type Description
PackageReference The package reference if found