module Makit class DotNet def self.is_installed? File.exist?(Makit::Environment.which("dotnet")) end def self.version `dotnet --version` end def self.new_project(template, name, output) if Dir.exist? output #puts " #{output}".colorize(:green) + " exists.".colorize(:grey) #puts "Directory #{output} already exists".colorize(:yellow) else "dotnet new #{template} --name #{name} --output #{output}".run end end def find_project(project_hint) matches = [] Dir.glob("**/*.csproj").each do |project_path| project_name = File.basename(project_path, ".csproj") if project_name.include?(project_hint) matches << project_path end end if matches.length == 1 return matches.first elsif matches.length > 1 raise "Multiple projects found matching #{project_hint}".colorize(:red) end raise "No project found matching #{project_hint}".colorize(:red) end def self.add_package(project_path, package_name) if(!File.exist?(project_path)) actual_project_path = Makit::DotNet.find_project(project_path) if(!File.exist?(actual_project_path)) raise "Project #{project_path} does not exist".colorize(:red) else project_path = actual_project_path end end project_content = File.read(project_path) if (!project_content.include?("\"#{package_name}\"")) "dotnet add #{project_path} package #{package_name}".run else #puts " package ".colorize(:grey) + "#{package_name}".colorize(:yellow) + " is in ".colorize(:grey) + "#{project_path}".colorize(:yellow) end end def self.add_packages(project_path, packages) packages.each do |package| add_package(project_path, package) end end def self.add_reference(project_path, reference_path) project_content = File.read(project_path) if (project_content.include?("