Introduction
Visual Studio offers a cool feature to define prebuild and postbuild without any effort. Indeed, you just need to write your command line.
On the other hand, thanks to .targets file, postbuild can be externally defined and provides 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, defining postbuild is easy but the real challenge is to factorize it and share it without forcing all developers/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 supports a build action pattern when project to pack is a console application.
For more information, read this tip.
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)
- platform (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 organization 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 Your Application Console
2. Manage Nuget Package for the Console Application
3. Install NuPack on Console Application
4. Edit Console Application to Do What You Want in your postbuild.
In the example, I just show arguments passed by NuPack.
5. Build Your Console Application to Generate Binary and Nuget Package
Congratulations! You just created a postbuild application as nuget package is ready to be deployed 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 the 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
Congratulations! Your postbuild works and writes 5 lines:
- the solution path
- the project path
- the configuration used to build
- the platform used to build
- the output path
Conclusion
Postbuild can be useful and there are many way to implement it. However, the chosen way will 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 in your own way to have the same kind of features.