Click here to Skip to main content
15,894,825 members
Articles / Programming Languages / C#

VS.NET Deployment Project Version Updater

Rate me:
Please Sign up or sign in to vote.
4.88/5 (25 votes)
3 Jan 2004CPOL6 min read 241.7K   1.6K   58  
A command line ulitity that updates the version and GUID of VS.NET deployment project files.
using System;
using System.IO;
using System.Collections;

namespace VersionVDProj
{
	/// <summary>
	/// Summary description for ArgumentParser.
	/// </summary>
	public class ArgumentParser
	{
		public readonly Hashtable Options;
		public readonly string Command;
		public readonly FileInfo ProjectFile;

		public ArgumentParser( string[] args )
		{
			Options = new Hashtable();

			if ( args.Length < 2 )
				throw new Exception( "Wrong number of arguments" );

			Command = ParseCommand( args[0] );
			ProjectFile = ParseFileName( args[1] );

			for ( int i = 2; i < args.Length; i++ )
				ParseArgument( args[i] );
		}		

		private string ParseCommand( string command )
		{
			if ( command.Substring( 0, 1 ) != "-" )
				throw new Exception( string.Format( "Unrecognized command {0}", command ) );

			return command.Substring( 1 ).ToLower();
		}

		private FileInfo ParseFileName( string path )
		{
			FileInfo file = new FileInfo( path );
			if ( !file.Exists )
				throw new Exception( string.Format( "The file {0} could not be found", path ) );

			return file;
		}

		private void ParseArgument( string arg )
		{
			int eqPos = arg.IndexOf( '=', 0 );
			
			if ( eqPos == -1 )
				throw new Exception( string.Format( "The argument {0} is not in the format NAME=VALUE", arg ) );

			string name = arg.Substring( 0, eqPos );
			string val = arg.Substring( eqPos + 1 );

			Options.Add( name.ToLower(), val );
		}
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader Starkey Laboratories
United States United States
The first computer program I ever wrote was in BASIC on a TRS-80 Model I and it looked something like:
10 PRINT "Don is cool"
20 GOTO 10

It only went downhill from there.

Hey look, I've got a blog

Comments and Discussions