Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Automatic Build Versioning in Visual Studio

, 7 May 2005
Automatic build version awareness, incrementing, and archiving.
build_versioning_exe.zip
VerCopy.exe
VerHeader.exe
build_versioning_src.zip
VerCopy
VerCopy
VerHeader
VerHeader
using System;
using System.Diagnostics;
using System.IO;
using System.Collections;

namespace BeauSkinner.VerHeader
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class VerHeader
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static int Main(string[] args)
		{
      if (args.Length == 0 || args.Length > 2)
      {
        Console.WriteLine("Usage: VerHeader <resource-file> [output-file=version.h]");
        return 1;
      }
      string RCFileStr = args[0];

      string outFileStr = "version.h";
      if (args.Length == 2)
        outFileStr = args[1];

      StreamReader RCFile = null;
      try
      {
        RCFile = new StreamReader(RCFileStr);
      }
      catch
      {
        Console.WriteLine("Error opening resource file {0}.", RCFileStr);
        return 1;
      }

      string major = null, minor = null, build = null;
      string line;
      while ((line = RCFile.ReadLine()) != null)
      {
        int pos;
        if ((pos = line.IndexOf("FILEVERSION")) < 0)
          continue;
        pos += "FILEVERSION".Length + 1;
        string[] tempInfo = line.Substring(pos).Split(" .,".ToCharArray());
        ArrayList verInfo = new ArrayList(4);
        foreach (string s in tempInfo)
          if (s.Length > 0)
            verInfo.Add(s);
        if (verInfo.Count != 4)
          break;
        major = verInfo[0].ToString();
        minor = verInfo[1].ToString();
        build = verInfo[2].ToString();
      }

      if (major == null)
      {
        Console.WriteLine("Version information not found in resource file {0}.", RCFileStr);
        return 1;
      }

      StreamWriter outFile = null;
      try
      {
        outFile = new StreamWriter(outFileStr, false);
        outFile.AutoFlush = true;
      }
      catch
      {
        Console.WriteLine("Error opening output file {0} for overwriting.", outFileStr);
        return 1;
      }

      outFile.WriteLine("#define MAJORVERSION {0}", major);
      outFile.WriteLine("#define MINORVERSION {0}", minor);
      outFile.WriteLine("#define BUILDNUMBER {0}", build);

      RCFile.Close();
      outFile.Close();

      return 0;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Beau Skinner
Web Developer
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411022.1 | Last Updated 7 May 2005
Article Copyright 2005 by Beau Skinner
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid