2016-03-19 16:23:28 +00:00
|
|
|
--
|
|
|
|
-- vs2010_nuget.lua
|
|
|
|
-- Generate a NuGet packages.config file.
|
|
|
|
-- Copyright (c) 2016 Jason Perkins and the Premake project
|
|
|
|
--
|
|
|
|
|
|
|
|
premake.vstudio.nuget2010 = {}
|
|
|
|
|
|
|
|
local p = premake
|
|
|
|
local vstudio = p.vstudio
|
|
|
|
local nuget2010 = p.vstudio.nuget2010
|
2016-08-11 16:12:11 +00:00
|
|
|
local cs2005 = p.vstudio.cs2005
|
2016-03-19 16:23:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- These functions take the package string as an argument and give you
|
|
|
|
-- information about it.
|
|
|
|
--
|
|
|
|
|
|
|
|
function nuget2010.packageName(package)
|
|
|
|
return package:gsub(":", ".")
|
|
|
|
end
|
|
|
|
|
|
|
|
function nuget2010.packageId(package)
|
|
|
|
return package:sub(0, package:find(":") - 1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function nuget2010.packageVersion(package)
|
|
|
|
return package:sub(package:find(":") + 1, -1)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function packageProject(wks, package)
|
|
|
|
for prj in p.workspace.eachproject(wks) do
|
2016-03-21 18:10:28 +00:00
|
|
|
for i = 1, #prj.nuget do
|
|
|
|
local projectPackage = prj.nuget[i]
|
2016-03-19 16:23:28 +00:00
|
|
|
|
2016-03-21 18:10:28 +00:00
|
|
|
if projectPackage == package then
|
|
|
|
return prj
|
2016-03-19 16:23:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function nuget2010.packageFramework(wks, package)
|
|
|
|
local prj = packageProject(wks, package)
|
|
|
|
|
2017-01-31 20:10:40 +00:00
|
|
|
if p.project.isdotnet(prj) then
|
2016-03-19 16:23:28 +00:00
|
|
|
local cfg = p.project.getfirstconfig(prj)
|
|
|
|
local action = premake.action.current()
|
|
|
|
local framework = cfg.dotnetframework or action.vstudio.targetFramework
|
2016-04-07 11:34:41 +00:00
|
|
|
return cs2005.formatNuGetFrameworkVersion(framework)
|
2017-01-31 20:10:40 +00:00
|
|
|
else
|
|
|
|
return "native"
|
2016-03-19 16:23:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Generates the packages.config file.
|
|
|
|
--
|
|
|
|
|
|
|
|
function nuget2010.generatePackagesConfig(obj)
|
|
|
|
local wks = obj.workspace
|
|
|
|
|
2016-04-11 20:06:25 +00:00
|
|
|
local done = {}
|
2016-03-19 16:23:28 +00:00
|
|
|
local packages = {}
|
|
|
|
for prj in p.workspace.eachproject(wks) do
|
2016-03-21 18:10:28 +00:00
|
|
|
for i = 1, #prj.nuget do
|
|
|
|
local package = prj.nuget[i]
|
2016-03-19 16:23:28 +00:00
|
|
|
|
2016-04-11 20:06:25 +00:00
|
|
|
if not done[package] then
|
|
|
|
done[package] = true
|
|
|
|
table.insert(packages, package)
|
2016-03-19 16:23:28 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
p.w('<?xml version="1.0" encoding="utf-8"?>')
|
|
|
|
p.push('<packages>')
|
|
|
|
|
2016-04-11 20:06:25 +00:00
|
|
|
for _, package in ipairs(packages) do
|
2016-03-19 16:23:28 +00:00
|
|
|
p.x('<package id="%s" version="%s" targetFramework="%s" />', nuget2010.packageId(package), nuget2010.packageVersion(package), nuget2010.packageFramework(wks, package))
|
|
|
|
end
|
|
|
|
|
|
|
|
p.pop('</packages>')
|
|
|
|
end
|