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

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;

namespace BeauSkinner.VerCopy
{
	/// <summary>
	/// Summary description for Class1.
	/// </summary>
	class VerCopy
	{
		/// <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: VerCopy <filename> [destination-dir].\n");
        return 1;
      }
      string PathFile = args[0];

      FileInfo fileInfo = new FileInfo(PathFile);
      if (!fileInfo.Exists)
      {
        Console.WriteLine("File does not exist.");
        return 1;
      }

      string destPath = null;
      if (args.Length == 2)
      {
        destPath = args[1].Trim("\\".ToCharArray());
        if (!Directory.Exists(destPath))
          Directory.CreateDirectory(destPath);
      }

      FileVersionInfo verInfo = FileVersionInfo.GetVersionInfo(PathFile);
      string destFile = fileInfo.Name.Substring(0,fileInfo.Name.Length-fileInfo.Extension.Length) + "-"
        + verInfo.FileMajorPart + "-" + verInfo.FileMinorPart + "-" + verInfo.FileBuildPart + fileInfo.Extension;
      if (destPath != null)
        destFile = destPath + "\\" + destFile;
      File.Copy(PathFile, destFile, true);

      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 | Mobile
Web01 | 2.8.140905.1 | Last Updated 7 May 2005
Article Copyright 2005 by Beau Skinner
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid