0

I'm working on a Web Site solution (not a Web Application shame on me) in Visual Studio 2012 on a ASP.NET Web Forms (double shame on me) project. I would like to have an auto-increment version on each build so that I can retrieve it in my code and use for static files versioning (mostly css and js) to avoid chache it.

What I want to obtain are links like /mydir/mystyle.css?v=buildversionhere

I found a nice code to retrieve the version:

Dim web As Assembly = Assembly.GetExecutingAssembly()
Dim webName As AssemblyName = web.GetName()
Dim myVersion As String = webName.Version.ToString()

And it works, the problem is I always get 0.0.0.0. What I need to know is how to set an auto-increment on each website build, like where to set something like this:

[assembly:AssemblyFileVersion("1.0.*")]

Remember I'm on a Web Site project not on a Web Application. Thanks in advance

4
  • Are you precompiling for deployment? - msdn.microsoft.com/en-au/library/399f057w(v=vs.85).aspx Commented Apr 4, 2013 at 21:52
  • Hallo Snixtor, I didn't reach the deployment stage yet (I'm very far) but yes I guess I will Commented Apr 4, 2013 at 22:11
  • My suspicion is that unless you precompile, you won't get a version number. Or at least not a meaningful one. Commented Apr 4, 2013 at 23:06
  • But everytime I build there is a compilation going on and site .dll being created. Commented Apr 5, 2013 at 8:57

1 Answer 1

1

OK.. after some in-depth research and some head-crushing since documentation (official) is more than often very superficial I found a way to do it. So if you have a WEB SITE project and want to add semi-automatic versioning to your web site (maybe to retrieve this version for whatever usage you want like canceling static files cache appending ?v=version) here is how to do it:

  • Create a file in your project NOT INSIDE THE App_Code folder and name it like AssemblyInfo.vb (I'm coding in VB. If you need C# search "Telerik Code Converter" in Google). You can put the file inside App_Data folder if you want
  • Inside this file you don't need to create any class, just specify infos for your .DLLs inserting this code:

Example

Imports System.Reflection

<Assembly: AssemblyDescription("desc")> 
<Assembly: AssemblyCompany("company")> 
<Assembly: AssemblyCopyright("Copyright © 2013 your name")> 
<Assembly: AssemblyProduct("asdasd")> 
<Assembly: AssemblyVersion("2.0.*")> 

Then inside your web.config (between the "configuration" tags) insert this code:

<system.codedom>
 <compilers>
  <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    compilerOptions='"C:\Absolutepath\App_Data\AssemblyInfo.vb"' />
 </compilers>
</system.codedom>

with the path to your AssemblyInfo.vb file. ATTENTION: if you don't want to waste hours like me... this path has to be ABSOLUTE and cannot be relative. So when you move your site in production on another server remember to change it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.