项目文件和解决方案文件都是文本文件。项目文件不知道他们的解决方案,所以我们必须查看他们项目的解决方案。
解决方案文件中的项目条目如下所示:
Project("{9AC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ProjectName", "ProjectDirectory\ProjectFileName.vcproj","{9A95F635-B74F-4640-BBCF-E324D0972CA9}"
EndProject
所以你可以看到,我们可以抓取项目名称和项目文件的相对路径。
使用您最喜欢的脚本语言,您可以执行以下操作。(红宝石示例)
require 'find'
def project_name(string)
string =~ /= "(.+?)"/
$1
end
#the script doesn't use this method but you may want it
def project_path(string)
string =~ /, "(.+?)"/
$1
end
def find_projects(path)
puts "#{path} contains the following projects:"
open(path).read.gsub(/Project\(.+?EndProject/m) do |match|
puts project_name(match)
end
puts ""
end
#change File.dirname(__FILE__)) to the name of the directory you want to search.
Find.find(File.dirname(__FILE__)) do |path|
if FileTest.directory?(path)
if File.basename(path) =~ /^\../ # Directory name starts with .
Find.prune # Don't look any further into this directory.
else
next
end
elsif path =~ /\.sln$/
find_projects(path)
end
end