Class: MSBuild

Inherits:
Hash
  • Object
show all
Defined in:
lib/msbuild.rb

Overview

Visual Studio 2008 version 9.0, solution format version 10.00 Visual Studio 2010 version 10.0, solution format version 11.00 Visual Studio 2012 version 11.0, solution format version 12.00 Visual Studio 2013 version 12.0, solution format version 12.00 Visual Studio 2015 version 14.0, solution format version 12.00

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Hash

#execute, #to_html

Constructor Details

#initializeMSBuild

Returns a new instance of MSBuild.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/msbuild.rb', line 8

def initialize
  #self[:vs14]="C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\msbuild.exe" 
  if(File.exists?("C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\msbuild.exe"))
    self[:vs14]="C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\msbuild.exe" 
  else
    puts "C:\\Program Files (x86)\\MSBuild\\14.0\\bin\\msbuild.exe was not found." 
    puts "MSBUILD[:vs14]='PATH_TO_MSBUILD' may be used to specify msbuild path."
  end
  self[:vs9]="C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe"  if(File.exists?("C:\\Windows\\Microsoft.NET\\Framework\\v3.5\\msbuild.exe"))
  self[:vs10]="C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe" if(File.exists?("C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\msbuild.exe"))
  self[:vs12]="C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\msbuild.exe" if(File.exists?("C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\msbuild.exe"))
end

Class Method Details

.get_build_commands(sln_filename) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/msbuild.rb', line 68

def self.get_build_commands sln_filename
  build_commands=nil
  vs_version=MSBuild.get_vs_version(sln_filename)
  if(MSBuild.has_version?(vs_version))
    MSBuild.get_configurations(sln_filename).each{ |configuration|
      MSBuild.get_platforms(sln_filename).each{|platform|
        build_commands=Array.new if build_commands.nil?
        build_commands << "\"#{MSBuild.get_version(vs_version)}\" \"#{sln_filename}\" /nologo /p:Configuration=#{configuration} /p:Platform=\"#{platform}\""
      }
    }
  end
  build_commands
end

.get_configurations(sln_filename) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/msbuild.rb', line 48

def self.get_configurations(sln_filename)
 	configs=Array.new
	sln_text=File.read(sln_filename,:encoding=>'UTF-8')
 	sln_text.scan( /= ([\w]+)\|/ ).each{|m|
	c=m.first.to_s
	configs << c if !configs.include?(c)
		}
		return configs
end

.get_platforms(sln_filename) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/msbuild.rb', line 58

def self.get_platforms(sln_filename)
 	platforms=Array.new
	sln_text=File.read(sln_filename,:encoding=>"UTF-8")
 	sln_text.scan( /= [\w]+\|([\w ]+)/ ).each{|m|
  	p=m.first.to_s
  	platforms << p if !platforms.include?(p)
	}
 return platforms
end

.get_version(version) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/msbuild.rb', line 30

def self.get_version version
  if(defined?(MSBUILD))
    MSBUILD[version]
  else
    msb=MSBuild.new
    return msb[version]
  end
end

.get_vs_version(sln_filename) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/msbuild.rb', line 39

def self.get_vs_version(sln_filename)
		sln_text=File.read(sln_filename,:encoding=>'UTF-8')
 	return :vs9 if sln_text.include?('Format Version 10.00')
 	return :vs12 if sln_text.include?('12.0.30723.0')
   return :vs12 if sln_text.include?('Visual Studio 2013')
   return :vs12 if sln_text.include?('12.0.31101.0')
   return :vs14
end

.has_version?(version) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/msbuild.rb', line 21

def self.has_version? version
  if(defined?(MSBUILD))
    MSBUILD.has_key?(version)
  else
    msb=MSBuild.new
    return msb.has_key? version
  end
end