Adding some automatic versioning to CSS files. How come I'm not able to pull assembly info?

1.2k views Asked by At
<link rel="stylesheet" type="text/css" href="../Content/Dashboard/CustomTooltip.css?v=<%= System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).FileVersion %>" />

Couple of questions:

  • Is this an alright way of going about this? The idea is that when our products assembly information changes, the version updates, the path to the CSS file gets modified and invalidates the cache.
  • If I place the C# code into a watch window I see the proper version info, but in the .aspx page it fails to load it. No error message, but it just says .css?v= with no version.

Thanks

Edit: It seems like its something to do with the reflection that's going on. If I say:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Name

I see the proper name in the watch window, but when evaluated on the .aspx page it is App_Web_35 (not correct). Any idea how to fix this?

Edit2: I ended up going with a solution I'm not quite happy with, but would love to hear other inputs. I just put:

protected string GetApplicationVersion()
{
    return System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;
}

on my related CS page -- and then in the code behing I called <% GetApplicationVersion() %> and now it happily returns the proper information. I wish it could be inlined, though.

1

There are 1 answers

2
dknaack On BEST ANSWER

A css file is static, like html. Think about create different css files and call it like this

<link rel="stylesheet" type="text/css" href="../Content/Dashboard/CustomTooltip_<%= `System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAsse`m`bly().Location).FileVersion %>.css" />`

so you need a css file like this ../Content/Dashboard/CustomTooltip_1.0.css