Module: SolutionGenerator
- Defined in:
- lib/solution-generator.rb
Class Method Summary collapse
- .create_project(path, name, guid) ⇒ Object
- .generate(solution_name, projects) ⇒ Object
- .get_referenced_projects(project, projects = nil) ⇒ Object
- .write_solution_file(path, projects) ⇒ Object
Class Method Details
.create_project(path, name, guid) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/solution-generator.rb', line 30 def self.create_project(path, name, guid) project = OpenStruct.new project.name = name project.path = path project.guid = guid project end |
.generate(solution_name, projects) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/solution-generator.rb', line 6 def self.generate(solution_name, projects) all_projects = projects.map do |project| get_referenced_projects(project) end all_projects.flatten! all_projects.uniq! { |p| p.name } write_solution_file(solution_name, all_projects) end |
.get_referenced_projects(project, projects = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/solution-generator.rb', line 15 def self.get_referenced_projects(project, projects=nil) projects = [] if projects == nil project = project.gsub('\\', '/') contents = File.read(project).gsub(' xmlns="http://schemas.microsoft.com/developer/msbuild/2003"', "") xml = Nokogiri::XML(contents) projects << create_project(project, File.basename(project), xml.xpath('//Project/PropertyGroup/ProjectGuid').first.text) project = projects.last xml.xpath('//Project/ItemGroup/ProjectReference').each do |project_reference| referenced_project = File.(project_reference['Include'], File.dirname(project.path)) projects = get_referenced_projects(referenced_project, projects) end projects end |
.write_solution_file(path, projects) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/solution-generator.rb', line 38 def self.write_solution_file(path, projects) solution_guid = '{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}' configurations = ['Debug|Any CPU', 'Release|Any CPU'] File.open(path, 'w') do |file| file.puts 'Microsoft Visual Studio Solution File, Format Version 10.00' file.puts '# Visual Studio 2008' projects.each do |project| file.puts "Project(\"#{solution_guid}\") = \"#{project.name}\", \"#{project.path}\", \"#{project.guid}\"" file.puts "EndProject" end file.puts 'Global' file.puts ' GlobalSection(SolutionConfigurationPlatforms) = preSolution' configurations.each do |configuration| file.puts " #{configuration} = #{configuration}" end file.puts ' EndGlobalSection' file.puts ' GlobalSection(ProjectConfigurationPlatforms) = postSolution' projects.each do |project| configurations.each do |configuration| file.puts " #{project.guid}.#{configuration}.ActiveCfg = #{configuration}" file.puts " #{project.guid}.#{configuration}.Build.0 = #{configuration}" end end file.puts ' EndGlobalSection' file.puts ' GlobalSection(SolutionProperties) = preSolution' file.puts ' HideSolutionNode = FALSE' file.puts ' EndGlobalSection' file.puts 'EndGlobal' end end |