From 49d82207bac51db580eb960a7261f26f5b9cf46e Mon Sep 17 00:00:00 2001 From: aleksijuvani Date: Thu, 24 Mar 2016 20:48:58 +0200 Subject: [PATCH] Move some NuGet logic into its own function --- src/actions/vstudio/vs2005_csproj.lua | 50 +++++++++++++++++---------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/src/actions/vstudio/vs2005_csproj.lua b/src/actions/vstudio/vs2005_csproj.lua index 76bd6a7e..a494131f 100644 --- a/src/actions/vstudio/vs2005_csproj.lua +++ b/src/actions/vstudio/vs2005_csproj.lua @@ -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, '', 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, '%s', 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, 'True') _p(2, '') end