Skip to content

Commit 89ce7ca

Browse files
committed
Use TargetFrameworks tag if multiple frameworks are provided by dotnetframework
1 parent 55fc4b2 commit 89ce7ca

7 files changed

Lines changed: 195 additions & 97 deletions

File tree

modules/vstudio/_preload.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
name = "dotnetframework",
137137
scope = "config",
138138
kind = "string",
139+
list = true,
139140
}
140141
p.api.alias("dotnetframework", "framework") -- for backward compatibility
141142

modules/vstudio/tests/cs2005/test_netcore.lua

Lines changed: 80 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,132 +18,132 @@ local project = p.project
1818
local wks, prj
1919

2020
function suite.setup()
21-
p.action.set("vs2005")
22-
wks, prj = test.createWorkspace()
21+
p.action.set("vs2005")
22+
wks, prj = test.createWorkspace()
2323
configurations { "Debug", "Release", "Distribution"}
24-
language "C#"
24+
language "C#"
2525
end
2626

2727
local function targetFrameworkPrepare()
28-
local cfg = test.getconfig(prj, "Debug")
29-
dn2005.netcore.targetFramework(cfg)
28+
local cfg = test.getconfig(prj, "Debug")
29+
dn2005.netcore.targetFramework(cfg)
3030
end
3131

3232
local function targetFrameworkVersionPrepare()
33-
local cfg = test.getconfig(prj, "Debug")
34-
dn2005.targetFrameworkVersion(cfg)
33+
local cfg = test.getconfig(prj, "Debug")
34+
dn2005.targetFrameworkVersion(cfg)
3535
end
3636

3737
local function projectConfigurationsPrepare()
38-
dn2005.projectConfigurations(prj)
38+
dn2005.projectConfigurations(prj)
3939
end
4040

4141
local function prepareNetcore()
42-
dn2005.projectElement(prj)
42+
dn2005.projectElement(prj)
4343
end
4444

4545
local function prepareProjectProperties()
46-
local localProj = test.getproject(wks, 1)
46+
local localProj = test.getproject(wks, 1)
4747

48-
dn2005.prepare(cs2005)
49-
dn2005.projectProperties(localProj)
48+
dn2005.prepare(cs2005)
49+
dn2005.projectProperties(localProj)
5050
end
5151

5252
function suite.targetFrameworkProperty_framework()
53-
dotnetframework "4.7.2"
54-
targetFrameworkPrepare()
55-
test.isemptycapture()
53+
dotnetframework "4.7.2"
54+
targetFrameworkPrepare()
55+
test.isemptycapture()
5656
end
5757

5858
function suite.targetFrameworkProperty_core()
59-
dotnetframework "netcoreapp2.2"
60-
targetFrameworkPrepare()
61-
test.capture [[
59+
dotnetframework "netcoreapp2.2"
60+
targetFrameworkPrepare()
61+
test.capture [[
6262
<TargetFramework>netcoreapp2.2</TargetFramework>
6363
]]
6464
end
6565

6666
function suite.targetFrameworkProperty_standard()
67-
dotnetframework "netstandard1.2"
68-
targetFrameworkPrepare()
69-
test.capture [[
67+
dotnetframework "netstandard1.2"
68+
targetFrameworkPrepare()
69+
test.capture [[
7070
<TargetFramework>netstandard1.2</TargetFramework>
71-
]]
71+
]]
7272
end
7373

7474
function suite.targetFrameworkVersionProperty_framework()
75-
dotnetframework "4.7.2"
76-
targetFrameworkVersionPrepare()
77-
test.capture [[
75+
dotnetframework "4.7.2"
76+
targetFrameworkVersionPrepare()
77+
test.capture [[
7878
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
79-
]]
79+
]]
8080
end
8181

8282
function suite.targetFrameworkVersionProperty_core()
83-
dotnetframework "netcoreapp2.2"
84-
targetFrameworkVersionPrepare()
85-
test.isemptycapture()
83+
dotnetframework "netcoreapp2.2"
84+
targetFrameworkVersionPrepare()
85+
test.isemptycapture()
8686
end
8787

8888
function suite.targetFrameworkVersionProperty_standard()
89-
dotnetframework "netstandard1.2"
90-
targetFrameworkVersionPrepare()
91-
test.isemptycapture()
89+
dotnetframework "netstandard1.2"
90+
targetFrameworkVersionPrepare()
91+
test.isemptycapture()
9292
end
9393

9494
function suite.project_element_standard()
95-
dotnetframework "netstandard1.2"
96-
prepareNetcore()
97-
test.capture [[
95+
dotnetframework "netstandard1.2"
96+
prepareNetcore()
97+
test.capture [[
9898
<Project Sdk="Microsoft.NET.Sdk">
99-
]]
99+
]]
100100
end
101101

102102
function suite.project_element_core()
103-
dotnetframework "netcoreapp1.2"
104-
prepareNetcore()
105-
test.capture [[
103+
dotnetframework "netcoreapp1.2"
104+
prepareNetcore()
105+
test.capture [[
106106
<Project Sdk="Microsoft.NET.Sdk">
107-
]]
107+
]]
108108
end
109109

110110
function suite.project_element_net5()
111-
dotnetframework "net5.0"
112-
prepareNetcore()
113-
test.capture [[
111+
dotnetframework "net5.0"
112+
prepareNetcore()
113+
test.capture [[
114114
<Project Sdk="Microsoft.NET.Sdk">
115-
]]
115+
]]
116116
end
117117

118118
function suite.project_element_framework()
119-
dotnetframework "4.7.2"
120-
prepareNetcore()
121-
test.capture [[
119+
dotnetframework "4.7.2"
120+
prepareNetcore()
121+
test.capture [[
122122
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
123-
]]
123+
]]
124124
end
125125

126126
function suite.allowUnsafeProperty_core()
127-
dotnetframework "netcoreapp2.2"
128-
clr "Unsafe"
129-
prepareProjectProperties()
130-
test.capture [[
127+
dotnetframework "netcoreapp2.2"
128+
clr "Unsafe"
129+
prepareProjectProperties()
130+
test.capture [[
131131
<PropertyGroup>
132132
<OutputType>Exe</OutputType>
133133
<AppDesignerFolder>Properties</AppDesignerFolder>
134134
<TargetFramework>netcoreapp2.2</TargetFramework>
135135
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
136136
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
137137
</PropertyGroup>
138-
]]
138+
]]
139139
end
140140

141141
function suite.implicitUsings_on()
142-
p.action.set("vs2022")
143-
dotnetframework "net10.0"
144-
enableimplicitusings "On"
145-
prepareProjectProperties()
146-
test.capture [[
142+
p.action.set("vs2022")
143+
dotnetframework "net10.0"
144+
enableimplicitusings "On"
145+
prepareProjectProperties()
146+
test.capture [[
147147
<PropertyGroup>
148148
<OutputType>Exe</OutputType>
149149
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -152,15 +152,15 @@ function suite.implicitUsings_on()
152152
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
153153
<ImplicitUsings>true</ImplicitUsings>
154154
</PropertyGroup>
155-
]]
155+
]]
156156
end
157157

158158
function suite.implicitUsings_off()
159-
p.action.set("vs2022")
160-
dotnetframework "net10.0"
161-
enableimplicitusings "Off"
162-
prepareProjectProperties()
163-
test.capture [[
159+
p.action.set("vs2022")
160+
dotnetframework "net10.0"
161+
enableimplicitusings "Off"
162+
prepareProjectProperties()
163+
test.capture [[
164164
<PropertyGroup>
165165
<OutputType>Exe</OutputType>
166166
<AppDesignerFolder>Properties</AppDesignerFolder>
@@ -169,7 +169,22 @@ function suite.implicitUsings_off()
169169
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
170170
<ImplicitUsings>false</ImplicitUsings>
171171
</PropertyGroup>
172-
]]
172+
]]
173+
end
174+
175+
function suite.multiple_target_dotnet_frameworks()
176+
p.action.set("vs2022")
177+
dotnetframework { "net8.0", "net10.0" }
178+
prepareProjectProperties()
179+
test.capture [[
180+
<PropertyGroup>
181+
<OutputType>Exe</OutputType>
182+
<AppDesignerFolder>Properties</AppDesignerFolder>
183+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
184+
<Configurations>Debug;Release;Distribution</Configurations>
185+
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
186+
</PropertyGroup>
187+
]]
173188
end
174189

175190
function suite.project_element_configurations()

modules/vstudio/tests/vc2010/test_globals.lua

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ function suite.frameworkVersionIsCorrectNetCore_onSpecificVersion()
111111
]]
112112
end
113113

114+
function suite.frameworkVersionIsCorrectNetCore_onSpecificVersions()
115+
clr "NetCore"
116+
dotnetframework { "net8.0", "net10.0" }
117+
prepare()
118+
test.capture [[
119+
<PropertyGroup Label="Globals">
120+
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
121+
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
122+
<Keyword>ManagedCProj</Keyword>
123+
<RootNamespace>MyProject</RootNamespace>
124+
</PropertyGroup>
125+
]]
126+
end
127+
128+
114129
--
115130
-- Omit Keyword and RootNamespace for non-Windows projects.
116131
--

modules/vstudio/vs2005_dotnetbase.lua

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,12 @@
454454
local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package)
455455

456456
local action = p.action.current()
457-
local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework
457+
local targetFramework = nil
458+
if #cfg.dotnetframework > 0 then
459+
targetFramework = cfg.dotnetframework[#cfg.dotnetframework]
460+
else
461+
targetFramework = action.vstudio.targetFramework
462+
end
458463

459464
local targetVersion = dotnetbase.makeVersionComparable(targetFramework)
460465

@@ -754,7 +759,14 @@
754759

755760
function dotnetbase.targetFrameworkVersion(cfg)
756761
local action = p.action.current()
757-
local framework = cfg.dotnetframework or action.vstudio.targetFramework
762+
763+
local framework = nil
764+
if #cfg.dotnetframework > 0 then
765+
framework = cfg.dotnetframework[#cfg.dotnetframework]
766+
else
767+
framework = action.vstudio.targetFramework
768+
end
769+
758770
if framework and not dotnetbase.isNewFormatProject(cfg) then
759771
_p(2,'<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', framework)
760772
end
@@ -793,23 +805,38 @@
793805
end
794806

795807
function dotnetbase.isNewFormatProject(cfg)
796-
local framework = cfg.dotnetframework
797-
if not framework then
798-
return false
799-
end
800-
801-
if framework:find('^net') ~= nil then
802-
return true
808+
local frameworks = cfg.dotnetframework
809+
for _, currFramework in ipairs(frameworks) do
810+
if currFramework:find('^net') ~= nil then
811+
return true
812+
end
803813
end
804814

805815
return false
806816
end
807817

808818
function dotnetbase.netcore.targetFramework(cfg)
809819
local action = p.action.current()
810-
local framework = cfg.dotnetframework or action.vstudio.targetFramework
811-
if framework and dotnetbase.isNewFormatProject(cfg) then
812-
_p(2,'<TargetFramework>%s</TargetFramework>', framework)
820+
821+
local frameworks = nil
822+
if #cfg.dotnetframework > 0 then
823+
frameworks = cfg.dotnetframework
824+
else
825+
targetFramework = action.vstudio.targetFramework
826+
if targetFramework ~= nil then
827+
frameworks = { [1] = targetFramework }
828+
end
829+
830+
end
831+
832+
if frameworks ~= nil then
833+
if dotnetbase.isNewFormatProject(cfg) then
834+
if #frameworks > 1 then
835+
_p(2, '<TargetFrameworks>%s</TargetFrameworks>', table.concat(frameworks, ";"))
836+
else
837+
_p(2, '<TargetFramework>%s</TargetFramework>', frameworks[1])
838+
end
839+
end
813840
end
814841
end
815842

modules/vstudio/vs2010_nuget.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@
3131
if p.project.isdotnet(prj) then
3232
local cfg = p.project.getfirstconfig(prj)
3333
local action = p.action.current()
34-
local framework = cfg.dotnetframework or action.vstudio.targetFramework
34+
local framework = nil
35+
if #cfg.dotnetframework > 0 then
36+
framework = cfg.dotnetframework[#cfg.dotnetframework]
37+
else
38+
framework = action.vstudio.targetFramework
39+
end
3540
return dn2005.formatNuGetFrameworkVersion(framework)
3641
else
3742
return "native"

modules/vstudio/vs2010_vcxproj.lua

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,30 @@
114114

115115
function m.targetFramework(prj)
116116
local action = p.action.current()
117-
local tools = string.format(' ToolsVersion="%s"', action.vstudio.toolsVersion)
118117

119-
local framework = prj.dotnetframework or action.vstudio.targetFramework or "4.0"
120-
if framework and dotnetbase.isNewFormatProject(prj) then
121-
p.w('<TargetFramework>%s</TargetFramework>', framework)
118+
local frameworks = nil
119+
if #prj.dotnetframework > 0 then
120+
frameworks = prj.dotnetframework
122121
else
123-
p.w('<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', framework)
122+
targetFramework = action.vstudio.targetFramework or "4.0"
123+
frameworks = { [1] = targetFramework }
124+
124125
end
125-
end
126126

127+
if frameworks ~= nil then
128+
if dotnetbase.isNewFormatProject(prj) then
129+
if #frameworks > 1 then
130+
p.w('<TargetFrameworks>%s</TargetFrameworks>', table.concat(frameworks, ";"))
131+
else
132+
p.w('<TargetFramework>%s</TargetFramework>', frameworks[1])
133+
end
134+
else
135+
if #frameworks >= 1 then
136+
p.w('<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', frameworks[#frameworks])
137+
end
138+
end
139+
end
140+
end
127141

128142

129143
--

0 commit comments

Comments
 (0)