Home > Enterprise >  Run NuGet add in Visual Studio 2022 post build event
Run NuGet add in Visual Studio 2022 post build event

Time:04-30

I've created a local NuGet feed for some testing. In an attempt to automate the process, I've tried to create a post-build event to execute the 'NuGet add' for the package. The NuGet add fails with:

Provided Nupkg file 'XXXXX\bin\x64\Debug\XXXXX.1.0.0.nupkg' is not found.

However, when I look at the folder, the 'nupkg' file is where I expect it to be. I'm using the following command in the post-build event:

nuget add "$(ProjectDir)bin\$(Platform)\$(Configuration)\$(ProjectName).$(PackageVersion).nupkg" -Source "C:\XXXXX\NuGet Local Source"

Is this a problem with 'timing'?

How can I perform the 'NuGet add' in a post-build event?

I found How to run 'nuget add' as a post-build evnet in Visual Studio, but, I can't tell what I'm doing wrong.

CodePudding user response:

After some more digging, I found a workaround. I found .Net Core 2.0 "Generate Nuget package on build" issue with Post-build events that mentioned using "Pack" as an 'AfterTargets'. The current build events tab does not offer 'Pack' as an option. So, the procedure I used was to fill in the post-build event, save the project and close it. Then, I edit the .csproj file and change this line in the file:

<Target Name="PostBuild" AfterTargets="Pack">

This allowed me to run the 'nuget' command from the post-build event.

  • Related