Downgrade Visual Studio project


/ Published in: Perl
Save to your folder(s)

Some (all?) Visual Studio projects can be opened with older versions without problems once their version numbers have been reduced. The following Perl script does this; it also recurses over the projects contained in a project folder (.sln) file. It saves you upgrading all your installations.


Copy this code and paste it in your HTML
  1. #!/usr/bin/perl -w
  2.  
  3. use strict;
  4.  
  5. my $targetver= 9;
  6. my %veryear= ( 8 => 2003, 9 => 2005, 10 => 2008 );
  7. my $year= $veryear{$targetver};
  8. my $projver= $targetver - 1;
  9.  
  10. sub downsln
  11. {
  12. my ($fname)= @_;
  13.  
  14. if( ! open IN, "<$fname" ) {
  15. print STDERR "Could not open $fname: $!\n";
  16. }
  17. local $/;
  18. my $data= <IN>;
  19. close IN;
  20. print "Downgrading $fname...\n";
  21. $data =~ s/((?:^|\n).*\bVisual Studio\b.*\bFormat Version\b.*?)\d+\.\d+/$1$tar
  22. getver.00/
  23. or print STDERR "Could not replace version number in $fname\n";
  24. $data =~ s/\n\#\s+Visual .*20\d\d/\n\# Visual Studio $year/
  25. or print STDERR "Could not replace release year in $fname\n";
  26. if( rename($fname, "$fname.down") && open(OUT, ">$fname") ) {
  27. print OUT $data;
  28. close OUT;
  29. }
  30. else {
  31. print STDERR "Could not rename / write $fname.\n";
  32. }
  33. my @projs= $data =~ /\nProject.*?=.*?,\s*\"([^"]+)\"/g;
  34. my $basedir= $fname;
  35. $basedir =~ s![^/]*$!!;
  36. for (@projs) {
  37. downproj($basedir . $_, $fname);
  38. }
  39. }
  40.  
  41.  
  42. sub downproj
  43. {
  44. my ($fname, $slnname)= @_;
  45.  
  46. if( ! open IN, "<$fname" ) {
  47. print STDERR "Could not open $fname: $!\n";
  48. }
  49. local $/;
  50. my $data= <IN>;
  51. close IN;
  52. print "Downgrading $fname...\n";
  53. $data =~ s/\n(\s*Version\s*=\s*\")\d+([,.])\d+\"/\n$1$projver${2}00\"/
  54. or print STDERR "Could not replace version number in $fname\n";
  55. if( rename($fname, "$fname.down") && open(OUT, ">$fname") ) {
  56. print OUT $data;
  57. close OUT;
  58. }
  59. else {
  60. print STDERR "Could not rename / write $fname.\n";
  61. }
  62. }
  63.  
  64.  
  65. for my $arg (@ARGV)
  66. {
  67. $arg =~ s/\\/\//g;
  68. $arg =~ s/^([a-z]):\//\/cygdrive\/$1\//i;
  69. if( $arg =~ /\.sln$/ ) {
  70. downsln($arg);
  71. }
  72. else {
  73. downproj($arg);
  74. }
  75. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.