Click here to Skip to main content
12,695,076 members (31,297 online)
Click here to Skip to main content

Stats

160.9K views
2.6K downloads
101 bookmarked
Posted

Automatic Build Versioning in Visual Studio

, 7 May 2005
Automatic build version awareness, incrementing, and archiving.
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

You may also be interested in...

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