jos3m
jos3m

Reputation: 125

Adding build version to css files in asp.net

I need to add the version at each css file, for that I have created a function which returns the build version, but when I add the function to the path it doesn't get properly rendered:

<!--Code-->
<link href="Styles/Site.css<% Version() %>" rel="stylesheet" type="text/css" />

<!--Render-->
<link href="Styles/Site.css&lt;% Version() %>" rel="stylesheet" type="text/css" />

I tried both <% %> and <%= %> and even using a global variable instead of a public function but with no results, however I was able to add the version to js files through modifyng the path in the ScriptManager object.

Upvotes: 0

Views: 669

Answers (1)

VDWWD
VDWWD

Reputation: 35554

You can always add a stylesheet programatically.

 HtmlLink hl = new HtmlLink();

 hl.Href = "Styles/Site.css" + Version();
 hl.Attributes.Add("type", "text/css");
 hl.Attributes.Add("rel", "stylesheet");

 Page.Header.Controls.Add(hl);

The reason <%= %> does not work is because it is in the Head of the page, which is a Control in itself. If you put your sheet outside the Head, it does work.

Upvotes: 1

Related Questions