Embed information on this deployment into your Asp.Net Mvc application. All via a Nuget package.
There are multiple builds of this package for different versions of Asp.Net Mvc
install-package Oaf.DeploymentInfo-mvc4.0 install-package Oaf.DeploymentInfo-mvc3.0
Each package also supports multiple .Net versions (at time of writing - 4.0 and 4.5). The build scripts for this are quite involved and can be used as examples for future package development. This might also work with Webforms but is at the moment untested
This project is MIT Licensed
Issue tracker is on bitbucket
Currently does the following
- Adds a Version.txt file to your project root. This is set as content and copy to output directory
- Assuming that hg/git is accessible to your powershell environment - Creates a prebuild event that writes this file with information on the current revision. It is recommended you deploy this along with your application to keep it easy to check what is deployed.
- On web application start read the current revision into the Oaf.DeploymentInfo.Revision variable
So you've run
Install-Package Oaf.DeploymentInfo-mvc4.0 in your web application. You're almost done!
The script created by this is inlined and very simple so it should not block the parser too much
Don't forget to remove this line when uninstalling the package
Revision number is the most common use-case for Oaf.DeploymentInfo so it is exposed as a static.This is just a simple facade for the
Oaf.DeploymentInfo.Instance singleton. This singleton exposes other further abilities.
PropertyBag / PropertyData
This is a simple in-memory dictionary which you can use to store your own deployment information. While impossible to enforce, in keeping with the spirit of the package, you should only use this to store information that is trully about the deployment of your application. A good place to set
PropertyBag variables is inside of
These properties work similarly to Asp.Net Mvc controllers'
ViewData properties. PropertyData is an
IDictionary<string, object> and
PropertyBag is a dynamic facade over PropertyData that can have properties added and queried in a dynamic fashion eg
DeploymentInfo.Instance.PropertyBag.AnyPropertyYouWant = "foo";. Querying a PropertyBag property that has not previously been set returns null.
DeploymentInfo.Instance singleton is based on the
Oaf.DeploymentInfo.IDeploymentInfoInstance interface and can be substituted with an alternate implementation for testing purposes. That being said, all DeploymentInfo behaviors should have a non-error-throwing default so this might not be necessary.
The package itself uses a combination of pre-build events, powershell, and WebActivator to push data on your current deployment into the application.
- You will need your powershell to be configured to run scripts (if you did Set-ExecutionPolicy ever before then it already is).
- You will need the psake build system. For this you can then either build the Oaf.DeploymentInfo project once from Visual Studio (which will run package restore) or run the Install-BuildTools.ps1 script at the solution root.
- You can then easily preform the default CreateAllPackages action with Run-DefaultBuild.ps1
If you are working with the command line you will want to have easy access to psake. If you do not have it already installed system-wide you can easily set it up using the local copy in the project
Oaf.DeploymentInfo> Set-Alias psake .\packages\psake.*\tools\psake.cmd
to execute psake with a specific target use
Oaf.DeploymentInfo> psake .\Oaf.DeploymentInfo\psake.ps1 TaskName
You can always get a list of all available build targets with
psake .\Oaf.DeploymentInfo\psake.ps1 -docs but the major ones are
- CreateAllPackages - (default) build and create a package for each supported mvc version in ProjectRoot/workspace/mvc/Oaf.DeploymentInfo-mvc.nupkg
- IncrementNuspecPatchVersion - Automatically increment the patch version of the nuspec template (you should commit after this)
- DeployPackagesNuget - CreateAllPackages then do a deployment to the central nuget server (this will be rejected if you are not a package owner)