Skip to content

MattKotsenas/GetPackFromProject

Repository files navigation

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()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages