Friday, March 03, 2006

Subversion ASP.NET hack - Ruby and Rake to the rescue

I recently began using Subversion to manage some Microsoft VS.NET solutions when I encountered this nasty problem with ASP.NET web projects. No one seems to know exactly why, but VS.NET has trouble loading Web projects from the server when there are folders that begin with a dot.

Tigris does offer a hack workaround that simply renames the ".svn" folders to "_svn", but it requires that you constantly change environment variables and reboot your system if you want to keep your .svn directories and remain compatible with command-line svn and other non-Windows systems.

After listening to Geoffrey Grosenbach's Ruby on Rails podcast with Jim Weirich about his most excellent build tool Rake, I thought this would be a case for the dynamic duo.

So I picked up the Batphone (you did notice it is red, no?), and a few minutes later I had a way to switch the directories to an ASP.NET compatible version any time I need to reload the Web project. It takes under a second to recurse over 2,000 folders on my Dell D600. Not bad, especially considering how long it takes that cursed laptop to reboot.

Ruby Fu! HIYAH!!

fileutils.rb:

require "ftools"

module YaYaSoft
class FileUtils
def self.rename_all(dir, from, to)
return nil unless FileTest.directory?(dir)
Dir.foreach(dir) do |e|
next if [".", ".."].include? e
fullname = dir + File::Separator + e
if FileTest.directory?(fullname) && e == from
puts "Renaming #{fullname} to #{to}"
File.move(fullname, dir + File::Separator + to)
elsif FileTest.directory?(fullname)
#puts "Checking directory: #{fullname}"
rename_all(fullname, from, to)
end
end
end
end
end


rakefile.rb:

require 'yayasoft/fileutils'

DIRS = ['../webapps/Web', '../webapps/dotNET/WebService']

desc 'Switch to ASP.NET compatible'
task :switch_aspnet do
DIRS.each do |dir|
YaYaSoft::FileUtils.rename_all(dir, '.svn', '_svn')
end
end

desc 'Switch to standard .svn'
task :switch_svn do
DIRS.each do |dir|
YaYaSoft::FileUtils.rename_all(dir, '_svn', '.svn')
end
end

0 Comments:

Post a Comment

<< Home