Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / C++
Article

Visual Studio Project Renamer

Rate me:
Please Sign up or sign in to vote.
4.81/5 (44 votes)
4 Sep 2001 320K   8.9K   77   72
A utility that renames Visual Studio projects

Sample Image - vsrename.jpg

Introduction

This is a utility that renames Visual Studio projects.

Usage:

vsrename <oldname> <newname> <dir>

Where:

oldname : The old name of your project (typically the xxx from xxx.dsw)
newname : The new name for your project
dir : The directory tree that holds the project.

This program will replace all occurences of oldname to newname in all files and rename all filenames that have the old name in it. It will walk subdirectories.

Use with care and on your own risk! Make backups before you use this program. Do a 'rebuild all' on your renamed project.

History

5.Sep.2001 v0.5

  • Source code released.

30.Jun.2001 v0.4

  • Better handling of binary files. They should be alright after renaming the project.

15.Jun.2001 v0.3

  • Better renaming of projects with the same name in it, so you can rename a project from 'myproject' to 'supermyproject'. It should go ok.

14.Jun.2001 v0.2

  • Added renaming of main project directory

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


Written By
Web Developer
Netherlands Netherlands
Niek is the founder and programmer of DaanSystems.com and is working on many projects all the time. He makes a living by doing contractwork for others.

Comments and Discussions

 
GeneralGreat Work!! Pin
Ganesh_NV22-May-05 23:12
Ganesh_NV22-May-05 23:12 
GeneralAwesome! This is the bomb! Pin
Programmer_Chris30-Oct-04 21:48
Programmer_Chris30-Oct-04 21:48 
GeneralRe: Awesome! This is the bomb! Pin
Marco Incalcaterra24-Jan-05 8:17
Marco Incalcaterra24-Jan-05 8:17 
Generalworked for me Pin
Mandalay29-Jul-04 10:17
Mandalay29-Jul-04 10:17 
GeneralRe: worked for me Pin
pflei16-Sep-04 9:01
pflei16-Sep-04 9:01 
Generalbeginer Pin
dnqhung12-Jun-04 20:18
dnqhung12-Jun-04 20:18 
GeneralFantastic! Pin
sofia hiromi14-May-04 4:01
sofia hiromi14-May-04 4:01 
Generalbetter program for renaming Pin
sshd25-Mar-04 2:58
sshd25-Mar-04 2:58 
example of use: proj_rename.pl -if project1.dsp -on project2 -iw project1.dsw -ow project2.dsw -up -uw


#
# ProjRename v1.1.1
#
# (C) 2003 Alexander Dovgaluk (sshd@mail.ru)
#
# utility for renaming visual studio projects
# supported file-types: dsp, vcp, vcproj, vcw, dsw, sln
#
# Started: 07.11.2003
# Last Update: 10.11.2003
#

use strict;

my $me;

if ($0 =~ m;^(.*[/\\])?(.*)$;) {
$me = $2;
} else {
$me = $0;
}

sub PrintUsage
{
print <<"_EOF_";
Visual Studio projects rename utility

Usage: $me options
-up update project file
-if <filename> input project file
-of <filename> output project file
-in <name> input project name
-on <name> output project name
-uw update workspace file
-iw <filename> input workspace name
-ow <filename> output workspace name
_EOF_
};

if ($#ARGV < 0) {
PrintUsage;
exit 1;
}

my @args;

my $input_fname;
my $input_ext;
my $in_pr;
my $in_pr_guess;
my $in_pr_file;
my $output_fname;
my $output_ext;
my $out_pr;
my $out_pr_file;
my $pr_type;
my $update_project;

my $input_workspace;
my $output_workspace;
my $update_workspace;
my $input_ws_ext;
my $ws_type;

$input_fname = "";
$input_ext = "";
$in_pr = "";
$in_pr_guess = 1;
$in_pr_file = "";
$output_fname = "";
$output_ext = "";
$out_pr = "";
$out_pr_file = "";
$pr_type = "";
$update_project = 0;

$input_workspace = "";
$output_workspace = "";
$update_workspace = 0;
$input_ws_ext = "";
$ws_type = "";

@args = @ARGV;
while (@args) {
my $cmd;
$cmd = shift @args;
if ($cmd eq '-if') {
$input_fname = shift @args;
} elsif ($cmd eq '-of') {
$output_fname = shift @args;
} elsif ($cmd eq '-in') {
$in_pr = shift @args;
$in_pr_guess = 0;
} elsif ($cmd eq '-on') {
$out_pr = shift @args;
} elsif ($cmd eq '-pt') {
$pr_type = shift @args;
} elsif ($cmd eq '-iw') {
$input_workspace = shift @args;
} elsif ($cmd eq '-ow') {
$output_workspace = shift @args;
} elsif ($cmd eq '-wt') {
$ws_type = shift @args;
} elsif ($cmd eq '-up') {
$update_project = 1;
} elsif ($cmd eq '-uw') {
$update_workspace = 1;
}
}

$input_ext = $pr_type if $pr_type;
$input_fname = "$in_pr.$input_ext" if not $input_fname and $input_ext and $in_pr;

if ($input_fname =~ m!^(.*[/\\])?(.*)\.(.*)$!) {
$in_pr_file = $2;
$input_ext = $3;
}
$in_pr = $in_pr_file if not $in_pr;
$in_pr_file = $in_pr if not $in_pr_file;

if ($input_workspace =~ m!^(.*[/\\])?(.*)\.(.*)$!) {
$input_ws_ext = $3;
}

if ($update_project and not $pr_type) {
if ($input_ext =~ /^dsp$/) {
$pr_type = "dsp";
} elsif ($input_ext =~ /^vcp$/) {
$pr_type = "vcp";
} elsif ($input_ext =~ /^vcproj$/) {
$pr_type = "vcproj";
} else {
die "Unknown project file extension";
}
}

if ($update_workspace and not $ws_type) {
if ($input_ws_ext =~ /^dsw/) {
$ws_type = "dsw";
} elsif ($input_ws_ext =~ /^vcw/) {
$ws_type = "vcw";
} elsif ($input_ws_ext =~ /^sln$/) {
$ws_type = "sln";
} else {
die "Unknown workspace file extension";
}
}

$output_fname = "$out_pr.$input_ext" if not $output_fname;

if ($output_fname =~ m!^(.*[/\\])?(.*)\.(.*)$!) {
$out_pr_file = $2;
$output_ext = $3;
}
$out_pr = $out_pr_file if not $out_pr;

$update_project = 0 if not $input_fname or not $output_fname;
$update_workspace = 0 if not $input_workspace or not $output_workspace;

# warning if ($input_ext !~ /^\Q$output_ext\E$/);
# warning if ($input_ws_ext !~ /^\Q$output_ws_ext\E$/);

my $s;

if ($update_project or $in_pr_guess) {

open(IN, "<$input_fname") or die "Can't open input project file";
if ($update_project) {
open(OUT, ">$output_fname") or die "Can't open output project file";
}

if ($pr_type eq "dsp" or $pr_type eq "vcp") {

my $is_project;
my $is_beginning;
my $is_currcfg;
my $is_target;

$is_beginning = 1;
$is_currcfg = 1;
$is_project = 0;
$is_target = 0;

while ($s = <IN>) {
if ($s =~ /^# Begin Project$/) {
$is_project++;
$is_beginning = 0;
$is_currcfg = 0;
$is_target = 0;
} elsif ($s =~ /^# End Project$/) {
$is_project--;
$is_target = 0;
}
if ($is_beginning) {
if ($in_pr_guess) {
if ($s =~ s/^(# Microsoft (Developer Studio|eMbedded Visual Tools) Project File - Name=")(.*)(" - Package Owner=<.*>)$/$1$out_pr$4/) {
$in_pr = $3;
$in_pr_guess = 0;
$is_beginning = 0;
}
} else {
if ($s =~ s/^(# Microsoft (Developer Studio|eMbedded Visual Tools) Project File - Name=")\Q$in_pr\E(" - Package Owner=<.*>)$/$1$out_pr$3/) {
$is_beginning = 0;
}
}
} elsif ($is_currcfg) {
if ($s =~ s/^(CFG=)\Q$in_pr\E( - .*)$/$1$out_pr$2/) {
$is_currcfg = 0;
}
} elsif ($is_project > 0) {
if ($s =~ /^# Begin Target$/) {
$is_target++;
} elsif ($s =~ /^# End Target$/) {
$is_target--;
}
if ($is_target > 0) {
$s =~ s/^(# Name ")\Q$in_pr\E( - .*")$/$1$out_pr$2/;
}
$s =~ s/^(!(ELSE)?IF\s*"\$\(CFG\)"\s*==\s*")\Q$in_pr\E( - .*?")$/$1$out_pr$3/;
} else {
$s =~ s:^(!MESSAGE NMAKE /f ")\Q$in_pr_file\E(\.(mak|vcn)"\.)$:$1$out_pr_file$2:;
$s =~ s:^(!MESSAGE NMAKE /f ")\Q$in_pr_file\E(\.(mak|vcn)" CFG=")\Q$in_pr\E(.*?")$:$1$out_pr_file$2$out_pr$4:;
$s =~ s/^(!MESSAGE ")\Q$in_pr\E( - .*?".*)$/$1$out_pr$2/;
}
print OUT $s if $update_project;
}

} elsif ($pr_type eq "vcproj") {

my $is_project;
my $is_end;

$is_project = 0;
$is_end = 0;

while ($s = <IN>) {
if (not $is_end) {
if ($s =~ /^<VisualStudioProject$/) {
$is_project = 1;
}
if ($is_project) {
if ($in_pr_guess) {
if ($s =~ s/^(\s*Name=")(.*)("\s*)/$1$out_pr$3/) {
$in_pr = $2;
$in_pr_guess = 0;
$is_end = 1;
}
} else {
if ($s =~ s/^(\s*Name=")\Q$in_pr\E("\s*)/$1$out_pr$2/) {
$is_end = 1;
}
}
}
}
print OUT $s if $update_project;
}

}

if ($update_project) {
close(OUT);
}
close(IN);

}

if ($update_workspace) {

open(IN, "<$input_workspace") or die "Can't open input workspace file";
open(OUT, ">$output_workspace") or die "Can't open output workspace file";

if ($ws_type eq "dsw" or $ws_type eq "vcw") {

my $is_project;
my $is_package;
my $is_dependency;

$is_project = 0;
$is_package = 0;
$is_dependency = 0;

while ($s = <IN>) {

if ($is_project) {

if ($is_package) {

if ($s =~ /^\s*\}\}\}\s*$/) {
$is_package = 0;
$is_dependency = 0;
}

if ($is_dependency) {
if ($s =~ /^\s*End Project Dependency\s*$/) {
$is_dependency = 0;
}
$s =~ s/^(\s*Project_Dep_Name )\Q$in_pr\E/$1$out_pr/;
} else {
if ($s =~ /^\s*Begin Project Dependency\s*$/) {
$is_dependency = 1;
}
}

} else {

if ($s =~ /^\s*\{\{\{\s*$/) {
$is_package = 1;
$is_dependency = 0;
}

}

}

if ($s =~ /^(Project:\s*"[^"]*"=.*|Global:\s*)$/) {
$s =~ s/^(Project:\s*")\Q$in_pr\E("=.*)\Q$input_fname\E( - Package Owner=<.*>)$/$1$out_pr$2$output_fname$3/;
$is_project = 1;
$is_package = 0;
$is_dependency = 0;
}

print OUT $s;

}

} elsif ($ws_type eq "sln") {

my $is_project;
my $is_global;

$is_project = 0;
$is_global = 0;

while ($s = <IN>) {

if ($is_project) {

if ($s =~ /^\s*EndProject\s*$/) {
$is_project = 0;
}

} elsif ($is_global) {

if ($s =~ /^\s*EndGlobal\s*$/) {
$is_global = 0;
}

} else {

if ($s =~ s/^(\s*Project\("[^"]*"\)\s*=\s*")\Q$in_pr\E(",\s*".*)\Q$input_fname\E(",\s*"[^"]*"\s*)$/$1$out_pr$2$output_fname$3/) {
$is_project = 1;
$is_global = 0;
}

if ($s =~ /^\s*Global\s*$/) {
$is_global = 1;
$is_project = 0;
}

}

print OUT $s;

}

}

close(OUT);
close(IN);

}

exit 0;

GeneralRe: better program for renaming Pin
John M. Drescher5-Apr-04 5:46
John M. Drescher5-Apr-04 5:46 
GeneralRe: better program for renaming Pin
Carl Chipman1-Jul-08 4:48
Carl Chipman1-Jul-08 4:48 
GeneralIt cant change the project Name Pin
iffi99216-Nov-03 19:51
iffi99216-Nov-03 19:51 
QuestionRe: It cant change the project Name Pin
David Crow21-Jul-06 9:45
David Crow21-Jul-06 9:45 
GeneralBe carefull if your project is called Tom or something else... Pin
azera28-Jul-03 23:08
azera28-Jul-03 23:08 
GeneralVery neat! Pin
Fredrik Skog10-Jul-03 1:41
Fredrik Skog10-Jul-03 1:41 
GeneralError-Handling with write-protected files Pin
Anonymous13-Mar-03 3:00
Anonymous13-Mar-03 3:00 
GeneralOne small bug in V0.5 Pin
jerry0davis28-Feb-03 0:08
jerry0davis28-Feb-03 0:08 
GeneralI can't believe .... Pin
charmless5-Jun-02 5:06
charmless5-Jun-02 5:06 
GeneralRe: I can't believe .... Pin
Gero Gerber9-Jun-02 12:44
Gero Gerber9-Jun-02 12:44 
GeneralGreat program!!! Pin
22-Apr-02 2:34
suss22-Apr-02 2:34 
GeneralExcellent! Pin
Matt Gullett27-Feb-02 4:34
Matt Gullett27-Feb-02 4:34 
GeneralNew Version 1.03 Pin
29-Aug-01 21:09
suss29-Aug-01 21:09 
GeneralThat's a whole different program! Pin
30-Aug-01 22:48
suss30-Aug-01 22:48 
GeneralSuperb!! Worked first time Pin
James Spibey12-Jul-01 3:01
James Spibey12-Jul-01 3:01 
GeneralRe: Superb!! Worked first time Pin
1-Sep-01 19:59
suss1-Sep-01 19:59 
GeneralRe: Superb!! Worked first time Pin
brian scott28-Sep-01 7:32
brian scott28-Sep-01 7:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.