Skip to content

Instantly share code, notes, and snippets.

@Matthew-Davey
Created May 31, 2018 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Matthew-Davey/ff30139e4b6a0628c32901d5acaf0cab to your computer and use it in GitHub Desktop.
Save Matthew-Davey/ff30139e4b6a0628c32901d5acaf0cab to your computer and use it in GitHub Desktop.
.NET Core Semver Rake
require 'rubygems'
require 'bundler/setup'
require 'semver'
@build_configuration = ENV['CONFIGURATION'] || 'Debug'
@verbosity = ENV["VERBOSITY"] || "detailed"
@semver = SemVer.find
desc 'Writes the semantic version of the project to stdout'
task :semver do
puts(@semver.to_s)
end
desc 'Clean up the working folder, deletes bin and obj'
task :clean do
sh "dotnet clean --verbosity #{@verbosity} --configuration #{@build_configuration}"
end
desc 'Restores missing nuget packages'
task :package_restore do
sh "dotnet restore --verbosity #{@verbosity}"
end
desc 'Executes dotnet build in the project root folder'
task :build => [:clean, :package_restore] do
sh "dotnet build --verbosity #{@verbosity} --configuration #{@build_configuration} --no-restore /p:Version=#{@semver.format "%M.%m.%p"}"
end
desc 'Runs any unit tests in the solution (any project which name ends with ".Tests")'
task :test => [:build] do
Dir.glob('**/*.Tests.*proj') do |test_project|
sh "dotnet test #{test_project} --configuration #{@build_configuration} --no-build --no-restore --verbosity #{@verbosity}"
end
end
desc 'Builds nuget packages for any project which is configured to generate a nuget package'
task :package => [:test] do
Dir.mkdir('artifacts') unless Dir.exist?('artifacts')
sh "dotnet pack --configuration #{@build_configuration} --no-build --no-restore --verbosity #{@verbosity} /p:Version=#{@semver.format "%M.%m.%p"} --output ../artifacts"
end
desc 'Publishes the Nuget package(s) to the Nuget repository'
task :publish => [:package] do
sh "dotnet nuget push ./artifacts/*.nupkg --source #{ENV['NUGET_FEED_URL']} --api-key #{ENV['NUGET_API_KEY']}"
end
task :default => [:build]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment