From cd276f8971008d1f19cf25e6a19a362884ae85d0 Mon Sep 17 00:00:00 2001 From: Bruno Cicanci Date: Tue, 28 Sep 2021 18:00:02 +0100 Subject: [PATCH] Added conditional to VS ItemGroup --- .../tests/cs2005/test_assembly_refs.lua | 148 ++++++++++++++++-- modules/vstudio/vs2005_dotnetbase.lua | 21 ++- 2 files changed, 144 insertions(+), 25 deletions(-) diff --git a/modules/vstudio/tests/cs2005/test_assembly_refs.lua b/modules/vstudio/tests/cs2005/test_assembly_refs.lua index 44d32a7c7e..161bfa0e2b 100644 --- a/modules/vstudio/tests/cs2005/test_assembly_refs.lua +++ b/modules/vstudio/tests/cs2005/test_assembly_refs.lua @@ -35,7 +35,9 @@ function suite.emptyGroup_onNoLinks() prepare() test.capture [[ - + + + ]] end @@ -49,7 +51,10 @@ links { "System" } prepare() test.capture [[ - + + + + ]] @@ -64,7 +69,12 @@ links { "../Libraries/nunit.framework" } prepare() test.capture [[ - + + + ..\Libraries\nunit.framework.dll + + + ..\Libraries\nunit.framework.dll @@ -82,10 +92,37 @@ links { "%{path.getdirectory(os.getcwd())}/Libraries/nunit.framework" } prepare() test.capture [[ - + ..\Libraries\nunit.framework.dll + + + + ..\Libraries\nunit.framework.dll + + + ]] + end + + +-- +-- Add configuration condition to VS csproj references ItemGroup +-- + + function suite.assemblyRef_onConfigurationCondition() + links { "%{path.getdirectory(os.getcwd())}/Libraries/%{cfg.buildcfg}/nunit.framework" } + prepare() + test.capture [[ + + + ..\Libraries\Debug\nunit.framework.dll + + + + + ..\Libraries\Release\nunit.framework.dll + ]] end @@ -101,7 +138,13 @@ flags { "NoCopyLocal" } prepare() test.capture [[ - + + + ..\Libraries\nunit.framework.dll + False + + + ..\Libraries\nunit.framework.dll False @@ -121,7 +164,13 @@ copylocal { "SomeOtherProject" } prepare() test.capture [[ - + + + ..\Libraries\nunit.framework.dll + False + + + ..\Libraries\nunit.framework.dll False @@ -135,7 +184,12 @@ copylocal { "../Libraries/nunit.framework" } prepare() test.capture [[ - + + + ..\Libraries\nunit.framework.dll + + + ..\Libraries\nunit.framework.dll @@ -154,7 +208,13 @@ if _OPTIONS["test-all"] then nuget { "Newtonsoft.Json:10.0.2" } prepare() test.capture [[ - + + + packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll + True + + + packages\Newtonsoft.Json.10.0.2\lib\net45\Newtonsoft.Json.dll True @@ -168,7 +228,13 @@ if _OPTIONS["test-all"] then nuget { "Newtonsoft.Json:10.0.2" } prepare() test.capture [[ - + + + packages\Newtonsoft.Json.10.0.2\lib\net20\Newtonsoft.Json.dll + True + + + packages\Newtonsoft.Json.10.0.2\lib\net20\Newtonsoft.Json.dll True @@ -190,7 +256,17 @@ if _OPTIONS["test-all"] then nuget { "NUnit:3.6.1" } prepare() test.capture [[ - + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll + True + + + packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll + True + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll True @@ -216,7 +292,17 @@ if _OPTIONS["test-all"] then flags { "NoCopyLocal" } prepare() test.capture [[ - + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll + False + + + packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll + False + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll False @@ -235,7 +321,17 @@ if _OPTIONS["test-all"] then copylocal { "SomeOtherProject" } prepare() test.capture [[ - + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll + False + + + packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll + False + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll False @@ -254,7 +350,17 @@ if _OPTIONS["test-all"] then copylocal { "NUnit:3.6.1" } prepare() test.capture [[ - + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll + True + + + packages\NUnit.3.6.1\lib\net20\NUnit.System.Linq.dll + True + + + packages\NUnit.3.6.1\lib\net20\nunit.framework.dll True @@ -280,7 +386,21 @@ if _OPTIONS["test-all"] then nuget { "MetroModernUI:1.4.0" } prepare() test.capture [[ - + + + packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.Design.dll + True + + + packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.dll + True + + + packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.Fonts.dll + True + + + packages\MetroModernUI.1.4.0.0\lib\net\MetroFramework.Design.dll True diff --git a/modules/vstudio/vs2005_dotnetbase.lua b/modules/vstudio/vs2005_dotnetbase.lua index d0b8e6a15f..e6371c8fca 100644 --- a/modules/vstudio/vs2005_dotnetbase.lua +++ b/modules/vstudio/vs2005_dotnetbase.lua @@ -328,7 +328,7 @@ -- Write out the references item group. -- - dotnetbase.elements.references = function(prj) + dotnetbase.elements.references = function(cfg) return { dotnetbase.assemblyReferences, dotnetbase.nuGetReferences, @@ -336,9 +336,11 @@ end function dotnetbase.references(prj) - _p(1,'') - p.callArray(dotnetbase.elements.references, prj) - _p(1,'') + for cfg in project.eachconfig(prj) do + _p(1,'', dotnetbase.condition(cfg)) + p.callArray(dotnetbase.elements.references, cfg) + _p(1,'') + end end @@ -346,11 +348,8 @@ -- Write the list of assembly (system, or non-sibling) references. -- - function dotnetbase.assemblyReferences(prj) - -- C# doesn't support per-configuration links (does it?) so just use - -- the settings from the first available config instead - local cfg = project.getfirstconfig(prj) - + function dotnetbase.assemblyReferences(cfg) + local prj = cfg.project config.getlinks(cfg, "system", function(original, decorated) local name = path.getname(decorated) if path.getextension(name) == ".dll" then @@ -421,13 +420,13 @@ -- Write the list of NuGet references. -- - function dotnetbase.nuGetReferences(prj) + function dotnetbase.nuGetReferences(cfg) + local prj = cfg.project if _ACTION >= "vs2010" and not vstudio.nuget2010.supportsPackageReferences(prj) then for _, package in ipairs(prj.nuget) do local id = vstudio.nuget2010.packageId(package) local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package) - local cfg = p.project.getfirstconfig(prj) local action = p.action.current() local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework