Skip to main content

An MSBuild task helper to simplify testing NuGet packages by automatically ensuring the latest package is built and placed in the output directory for test projects.

Total Downloads
43.7K
43,693
Published
Nov 23, 2024
1y ago

Get Started

dotnet add package GetPackFromProject --version 1.0.10

No framework information available.

README

Icon

GetPackFromProject

Build status Nuget Downloads

An MSBuild task / helper to simplify testing NuGet packages by automatically ensuring the latest package is built and placed in the output directory for test projects. To use, first install the package, then add the metadata AddPackageAsOutput=true to any <ProjectReference> items like this:

<ItemGroup>
  <ProjectReference Include="..\MyPackage\MyPackage.csproj" AddPackageAsOutput="true" />
</ItemGroup>

Adding that metadata will do a few things:

  1. Ensure the package is generated on every build

To avoid working with stale packages, the build will validate that any projects with this metadata have the GeneratePackageOnBuild property set (by default, a project only creates a package when you run the Pack target).

  1. Add the outputs of the pack operation (e.g. .nupkg and .nuspec files) as metadata on the <ProjectReference>

  2. Add all .nupkg files as <Content> items for your build

This ensures that the packages can be copied to your output directory for tests.

Finding the package in tests

Add this snippet to your unit tests to get the path to an output NuGet package:

FileInfo package = new(Assembly.GetExecutingAssembly().Location)
    .Directory!
    .GetFiles("NameOfNuGetPackageToTest*.nupkg")
    .OrderByDescending(f => f.LastWriteTimeUtc)
    .First()

Downloads by Version

Similar & Alternative Packages

Hand-picked matching NuGet libraries based on tags & ecosystem

Depended On By

Find packages that declare this package as a dependency. NuGet does not provide a reverse-dependency endpoint, so candidates are checked on demand.

Adoption Assessment

Assess this package against its supported frameworks, license, maintenance signals and dependency graph before making it a project standard.

No target framework metadata is available. Confirm compatibility in a representative project before standardising on this package.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.