Visual Studio offer a cool feature to define prebuild and posbuild without any effort. Indeed, you just need to write your command line.
In other hand, thanks to .targets file, postbuild can be externally defined and provide the same kind of feature.
So why may I use NuPack to create a postbuild?
NuPack can help you to industrialize it without effort. Indeed, define postbuild is easy but the real challenge is to factorize it and share it without forcing all developpers/teams to rewrite files or scripts.
Postbuild with NuPack
NuPack is a nuget package used to automatically pack project output into a nuget package. It support a build action pattern when project to pack is a console application.
for more information : https://www.codeproject.com/Tips/1190135/How-to-create-a-nuget-package-on-each-Visual-Studi
It means that if you use NuPack on console application, your generated nuget will contains a build folder with a .targets file to include a postbuild to call your console application with 5 arguments :
- solution path (sln)
- project patch (csproj)
- configuration used for build (Debug/Release)
- plateform (AnyCPU…)
- output path (dll/exe)
At this point we can create easily a postbuild application that can be installed as nuget package.
What I gain to make a postbuild in a nuget package?
If your postbuild process is in nuget package, you gain all nuget organisation features : version management, easy install/uninstall, easy to share, deploy and update without forcing developers to update scripts or files manually.
How to : step by step
1 – Create you application console
2 – Manage Nuget Package for the console application
3 – Install NuPack on console application
4 – Edit cnsole application to do what you want in your postbuild.
In example I just show arguments passed by NuPack
5 – Build your console application to generate binary and nuget package
Congratulation you just create a postbuild application as nuget package ready to be deploy into a nuget repository.
Test the postbuild
1 – Find your generated nuget in your output directory
2 – Copy it into a folder of your choice (that represents the local nuget repository)
In example I place it into D:\Nuget\
3 – Create a library project to test the postbuild
4 – Manage nuget package of this test project
5 – Configure your local nuget repository
6 – Install your postbuild nuget into the test project
7 – Build your test project
Congratulation your postbuild work and write 5 lines :
- the solution path
- the project path
- the configuration used to build
- the plateform used to build
- the output path
Postbuild can be usefull and there is many way to implements it. However, the choosen way have an impact on your project organisation. This impact can change reliability, productivity and maintainability. Using NuPack to create a managed (console application) postbuild is just a way to do it without effort and bring a lot of advantages passing by nuget package style dependency.
Don’t forget you can manually create your postbuild process and pack it into a nuget package by your own way to have the same kind of features.