Define Build Logic For Your App
When building your package, your project source (or pre-built binary) goes through a series of steps as part of the package compilation process. Depending on whether or not your Chef Habitat plan resides in the same repo as your project, these steps could include downloading your source, unpacking it, building it, and then installing it into the appropriate location within a Chef Habitat package.
The default behavior for these build steps are defined in build phase callbacks, which are functions called by Chef Habitat when building your package. When overriding any callbacks, you may use any of the plan variables, settings, or functions in the Plan syntax guide, except for the runtime configuration settings. Those can only be used in runtime hooks once a Chef Habitat service is running.
Overriding Build Phase Callbacks
You can override build phase callbacks in your plan. Default behavior may be changed and new functionality can be introduced to package your ASP.NET application appropriately.
At a minimum, you will want to override the
Invoke-Build function to install dependent .Net assemblies and compile your application code. You will also need to override
Invoke-Install to publish the artifacts of your build to the Chef Habitat build's package directory.
Here we use the
nuget.exe utility to populate dependencies and install the
MSBUILD target we need to build Visual Studio web projects. We use
MSBUILD.exe, included in the Visual Studio Build Tools, to build our C# code and compile our .NET assembly. Next we use the
WebPublish target from
MSBUILD to copy all of our web application artifacts to the
$pkg_prefix directory. This variable is defined by the Chef Habitat build system and expands to the absolute path of the Chef Habitat package staging area. All files located in that directory will find their way to the final Chef Habitat
.hart file which is the Chef Habitat package artifact.