Skip to content

Generating Versions

TheCloudlessSky edited this page Mar 2, 2012 · 2 revisions

Asset versioning is a way to ensure that client-cached assets are re-fetched. A v parameter is added to the end of each asset URL when not debugging.

Versions are generated with an implementation of the IVersionGenerator interface. The version generator can then be supplied to the PackageContainer via the VersionGenerator method.

The default version generator is the HashedVersionGenerator.cs. It will generate a random hash for each asset's v parameter:

<script type="text/javascript" src="/assets/core.js?v=3fa224672904"></script>

If you wanted to implement a version generator that, for example, used the current assembly's version you could write something similar to the following:

public class AssemblyVersionGenerator : IVersionGenerator
{
    public string Generate()
    {
        return Assembly.GetEntryAssembly().GetName().Version.ToString();
    }
}
Clone this wiki locally