Click here to Skip to main content
15,894,017 members
Articles / Programming Languages / C#
Tip/Trick

How to Setup a Managed postbuild Without Scripting Thanks to NuPack

Rate me:
Please Sign up or sign in to vote.
4.75/5 (6 votes)
4 Jun 2017CPOL3 min read 11.6K   1  
Postbuild is commonly used to update configuration file, rewrite MSIL, generate additional code, prepare deployment and many other things. The ability to manage it easily can be important to industrialize it.

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

Image 1

2. Manage Nuget Package for the Console Application

Image 2

3. Install NuPack on Console Application

Image 3

4. Edit Console Application to Do What You Want in your postbuild.

In the example, I just show arguments passed by NuPack.

Image 4

5. Build Your Console Application to Generate Binary and Nuget Package

Image 5

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

Image 6

2. Copy it into a Folder of Your Choice (that Represents the Local nuget Repository)

In the example, I place it into D:\Nuget\

Image 7

3. Create a Library Project to Test the postbuild

Image 8

4. Manage nuget Package of this Test Project

Image 9

5. Configure Your Local Nuget Repository

Image 10

Image 11

6. Install your postbuild nuget into the Test Project

Image 12

7. Build Your Test Project

Image 13

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
France France
After working in electronics, I fall in love with software development which is a real passion for me, particulary architecture concerns for productivity.

Comments and Discussions

 
-- There are no messages in this forum --