Sha256: ec52d50c169d5c73364ac2b75bc2c5ebd0cd1e0e0e056cf399c4c0f5d1103453

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module Rake
  module Funnel
    module Support
      module MSBuild
        class BuildTool
          class << self
            def find
              return 'xbuild'.freeze unless Rake::Win32.windows?

              from_registry.compact.first
            end

            private

            KEY = 'SOFTWARE\Microsoft\MSBuild\ToolsVersions'.freeze

            def from_registry
              return nil unless require_registry

              versions.map do |version|
                version_key(version) do |reg|
                  candidate = File.join(reg['MSBuildToolsPath'] || '', 'msbuild.exe')
                  next candidate if File.exist?(candidate)
                end
              end
            end

            def versions
              %w(14.0 12.0 4.0 3.5 2.0)
            end

            def require_registry
              require 'win32/registry'
              true
            rescue LoadError
              false
            end

            def version_key(version)
              key = KEY + '\\' + version

              ::Win32::Registry::HKEY_LOCAL_MACHINE.open(key) do |reg|
                yield(reg) if block_given?
              end
            rescue ::Win32::Registry::Error
              nil
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rake-funnel-0.19.0 lib/rake/funnel/support/msbuild/build_tool.rb