How to add version number dynamically to the end of the bundle URLs.
For example:
My bundle url: ~/Bundle/style.min.css?v=123
I wonder, how to dynamically change or add version number before deployment or push or when style.min.css
changes.
Is it possible or not?
I'm search around and find this article.
Based on it, in your BundleConfig
you can redefine Styles.DefaultTagFormat
and Scripts.DefaultTagFormat
.
So if you need to change version on every build of application you can do this in RegisterBundles
method:
var assemblyVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
Styles.DefaultTagFormat = "<link href='{0}?v=" + assemblyVersion + "' rel='stylesheet'/>";
Scripts.DefaultTagFormat = "<script src='{0}?v=" + assemblyVersion + "'></script>";
Of course you can get version from your Config
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With