 |
|
|
 |
|
 |
nice structured. Did you do some tests with Umlaute äöü? I had a lot of trouble with it. Hint: Add an entry in the eventlog and 'return with integers' eg. return -5. If there is an error in the postbuild-process you get only the integer as result.
Ariadne
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
1) After the post build command args exec, I end up with a few high-ascii characters at the beginning of my AssemblyInfo.cs file, and before a couple other characters (the (c) char) I have to manually remove these characters.
2) it updates the AssemblyVersion number just fine, but when I reference "Application.ProductVersion" in my code, I get the AssemblyFileVersion version number.
Basically, I just need the version num to be incremented, AND accessible at runtime...
Any thoughts?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
SirGolphknut wrote: I end up with a few high-ascii characters at the beginning of my AssemblyInfo.cs file
Workaround: 1. copy contents of AssemblyInfo.cs to Clipboard. 2. delete AssemblyInfo.cs from your project 3. add a new element to your project 4. select C#-class and name it AssemblyInfo.cs 5. Replace the default contents of the new class with contents of clipboard.
SirGolphknut wrote: when I reference "Application.ProductVersion" in my code, I get the AssemblyFileVersion version number.
I use Application.ProductVersion.ToString() too, and get the right build #. Are you shure, that you use the appropriate AssemblyInfo.cs?
Ariadne
modified on Tuesday, January 29, 2008 2:06:43 AM
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi all,
Since there are also VB.NET users out there, but only C#.Net has `Build Events`, it seems that we guys and gals cant do this trick. Well, there is a work-a-round:
Download `PrePostBuildRules Add-in` from this page, that contains the "Visual Studio .NET 2003 Automation Samples":
http://www.microsoft.com/downloads/details.aspx?FamilyId=3FF9C915-30E5-430E-95B3-621DCCD25150&displaylang=en#filelist
Follow the instructions as in the Readme file, that is: (1) open and build this addin project, (2) close all VS.net instances (3) run the .reg file within the project dit
Then there will be added a `Solution Build Rules` to the Tools menu in VS.NET next time you open your project. So, open your project (that you want the autoincrement working on) and click:
Tools > Solution Build Rules > Pre-Build rules > (select your project) > Add new
Set program to: IncBuildNo.exe (download from this code project page) Set Command line to: (dont need to set this! I adjusted the code as seen below to always open AssemblyInfo.vb)
I replaced the code within the project with this one. The code supports the AssemblyInfo format used in VB.net. Also, I couldnt get command line arguments correctly passed. So, I deleted that piece of code and replaced it with the standard `AssemblyInfo.vb` string. So, you will only be able to work ith and use this filename. Else change this source or get this arg[] thing working (see original source code!)
It works fine for me:
using System; using System.IO; namespace IncBuildNo{ class IncBuildNo{ [STAThread] static int Main(string[] args){
#region local variable definitions StreamReader file; string sLine; string filename = "AssemblyInfo.vb"; string sFile=""; string[] sTmp; int iPos=0; #endregion #region open and read cs file try {file = new StreamReader(filename,System.Text.Encoding.UTF7);} catch (Exception Ex){ Console.WriteLine("(0) File '"+args[0]+"' not found\nException thrown: "+Ex); return -1; } try{ while ((sLine = file.ReadLine()) != null){ #region interpret version line iPos=sLine.IndexOf("Assembly: AssemblyVersion("); if(iPos>0){ sTmp=sLine.Split('.'); if(sTmp[sTmp.Length-1]=="*\")>")sTmp[sTmp.Length-1]="0\")>"; int iTmp=int.Parse(sTmp[sTmp.Length-1].Substring(0,sTmp[sTmp.Length-1].Length-3))+1; sTmp[sTmp.Length-1]=iTmp.ToString(); sLine=""; for(int i=0;i"."; sLine=sLine.Substring(0,sLine.Length-1)+"\")>"; } #endregion sFile+=sLine+"\n"; } } catch(Exception ex){ Console.WriteLine("(1) (Reading File) Exception thrown: "+ex); return -1; } file.Close(); #endregion #region write cs file back try{ StreamWriter fileW = new StreamWriter(filename,false,System.Text.Encoding.UTF8); fileW.Write(sFile.Substring(0,sFile.Length)); fileW.Close(); return 0; } catch (Exception Ex){ Console.WriteLine("(2) (Reading File) Exception thrown: "+Ex); return -1; } #endregion } } }
NOTE: in VS.NET 2005, Build Events will be integrated, just like C# via the properties menu!
|
| Sign In·View Thread·PermaLink | 1.00/5 |
|
|
|
 |
|
 |
Here is the actual VB.NET Code if desired:
Imports System.IO Imports System
Public Class BuildNumberIncrmenter
Public Shared Function Main(ByVal aArgs() As String) As Int32
Dim oFile As IO.File Dim oReader As StreamReader = Nothing Dim sLine As String = String.Empty Dim csFileName As String = "AssemblyInfo.vb" Dim sFile As String = String.Empty Dim aTmp() As String Dim iPos As Int32 = 0
' Try to open the file Try 'oFile = New StreamReader(csFileName, System.Text.Encoding.UTF7) oReader = oFile.OpenText(csFileName) Catch ex As Exception Console.WriteLine("(0) File '" & csFileName & "' not found" & vbCrLf & "Exception thrown: " & ex.Message) Return -1 End Try
Try
' Get and read all lines While oReader.Peek <> -1 sLine = oReader.ReadLine()
' This is the ONLY line we want to change iPos = sLine.IndexOf("Assembly: AssemblyVersion(") If (iPos > 0) Then
' Get the text between '.' separated in an array aTmp = sLine.Split(".".ToCharArray)
' Add a 0 if the last set is an asterisk If aTmp(aTmp.Length - 1).Trim = "*"")>".Trim Then aTmp(aTmp.Length - 1) = "0"")>" End If
' Increment the last number by 1 Dim iTmp As Int32 = CInt(aTmp(aTmp.Length - 1).Substring(0, aTmp(aTmp.Length - 1).Length - 3)) + 1
aTmp(aTmp.Length - 1) = CStr(iTmp) sLine = String.Empty
' Concatenate the string again For i As Int32 = 0 To aTmp.Length - 1 sLine &= aTmp(i) & "." Next sLine = sLine.Substring(0, sLine.Length - 1) & """)]"
End If ' If (iPos > 0) Then
' Get the rest of the line sFile &= sLine & vbCrLf
End While
oReader.Close()
Catch ex As Exception Console.WriteLine("(1) (Reading File) Exception thrown: " & ex.Message) Return -1 End Try
Try
' Write the file back Dim oFileW As New StreamWriter(csFileName, False, System.Text.Encoding.UTF8) With oFileW .WriteLine(sFile.Substring(0, sFile.Length)) .Close() End With Return 0
Catch ex As Exception Console.WriteLine("(2) (Writing File) Exception thrown: " & ex.Message) Return -1 End Try
End Function
End Class
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
This is possible to use * in AssemblyInfo.cs. You can read: " You do not have to set and update each part explicitly because you can use wild characters (*) to automatically generate the build and revision numbers. Visual Studio .NET generates an AssemblyInfo source file with the AssemblyVersion attribute defined as follows:
[assembly: AssemblyVersion("1.0.*")] The result of this is a build number set to the number of days since a random, designated start date and the revision based on the number of seconds since midnight.
You can either use auto-increment version numbers or opt to manually control version numbers as part of the build process. Each approach has associated benefits and drawbacks. " in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/tdlg_ch5.asp[^] The problem is that in some cases this is better to control version number manually. However there is a number of build tools (relatively cheap), which help you with such type of task eg. FinalBuilder or Visual Build Professional. In VS 2005 will be introduced also some new build tool.
------------------------- Adam Koszlajda
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
In the same Microsoft Doc you see:
Disadvantages
Using auto-increment version numbers has the following disadvantages:
- The internal assembly build number does not match your system build number, which means there is no easy way to correlate a particular assembly with the build that generated it. This may be particularly problematic when you need to support your system in a production environment.
- Build and revision numbers are not increased by one but are based on the time an assembly is built.
- A new version of an assembly is generated each time it is built regardless of whether any changes have been made to the assembly. For strongly named assemblies, this means that all clients of that assembly must also be rebuilt to point to the correct version. However, if the build process rebuilds the whole system this should not be an issue.
Even the 2nd point was the reason to write IncBuildNo
Ariadne
|
| Sign In·View Thread·PermaLink | 3.50/5 |
|
|
|
 |