Move some NuGet logic into its own function

This commit is contained in:
aleksijuvani 2016-03-24 20:48:58 +02:00
parent 0592e36829
commit 49d82207ba

View File

@ -321,19 +321,48 @@
end)
end
--
-- Builds a list of all .NET Framework versions up to and including the
-- project's framework version.
--
function cs2005.identifyFrameworkVersions(prj)
local frameworks = {}
local cfg = p.project.getfirstconfig(prj)
local action = premake.action.current()
local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework
targetFramework = "net" .. targetFramework:gsub("%.", "")
for k, frameworkVersion in ipairs(vstudio.frameworkVersions) do
if k == #vstudio.frameworkVersions then
break
end
local nextFrameworkVersion = vstudio.frameworkVersions[k + 1]
-- Compare the versions with the "net" prefix stripped.
if tonumber(targetFramework:sub(4)) >= tonumber(nextFrameworkVersion:sub(4)) then
table.insert(frameworks, frameworkVersion)
end
end
table.insert(frameworks, targetFramework)
return frameworks
end
function cs2005.nuGetReferences(prj)
if _ACTION >= "vs2010" then
for i = 1, #prj.nuget do
local package = prj.nuget[i]
_x(2, '<Reference Include="%s">', vstudio.nuget2010.packageId(package))
local targetFramework = vstudio.nuget2010.packageFramework(prj.solution, package)
-- We need to write HintPaths for all supported framework
-- versions. The last HintPath will override any previous
-- HintPaths (if the condition is met that is).
local function writeHintPath(frameworkVersion)
for _, frameworkVersion in ipairs(cs2005.identifyFrameworkVersions(prj)) do
local assembly = vstudio.path(
prj,
p.filename(
@ -350,21 +379,6 @@
_x(3, '<HintPath Condition="Exists(\'%s\')">%s</HintPath>', assembly, assembly)
end
for k, frameworkVersion in ipairs(vstudio.frameworkVersions) do
if k == #vstudio.frameworkVersions then
break
end
local nextFrameworkVersion = vstudio.frameworkVersions[k + 1]
-- Compare the versions with the "net" prefix stripped.
if tonumber(targetFramework:sub(4)) >= tonumber(nextFrameworkVersion:sub(4)) then
writeHintPath(frameworkVersion)
end
end
writeHintPath(targetFramework)
_p(3, '<Private>True</Private>')
_p(2, '</Reference>')
end