GetPackFromProject 1.0.10
dotnet add package GetPackFromProject --version 1.0.10
NuGet\Install-Package GetPackFromProject -Version 1.0.10
<PackageReference Include="GetPackFromProject" Version="1.0.10"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add GetPackFromProject --version 1.0.10
#r "nuget: GetPackFromProject, 1.0.10"
// Install GetPackFromProject as a Cake Addin #addin nuget:?package=GetPackFromProject&version=1.0.10 // Install GetPackFromProject as a Cake Tool #tool nuget:?package=GetPackFromProject&version=1.0.10
GetPackFromProject
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:
- 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).
Add the outputs of the pack operation (e.g. .nupkg and .nuspec files) as metadata on the
<ProjectReference>
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()
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.