Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/vstudio/_preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
name = "dotnetframework",
scope = "config",
kind = "string",
list = true,
}
p.api.alias("dotnetframework", "framework") -- for backward compatibility

Expand Down
145 changes: 80 additions & 65 deletions modules/vstudio/tests/cs2005/test_netcore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,132 +18,132 @@ local project = p.project
local wks, prj

function suite.setup()
p.action.set("vs2005")
wks, prj = test.createWorkspace()
p.action.set("vs2005")
wks, prj = test.createWorkspace()
configurations { "Debug", "Release", "Distribution"}
language "C#"
language "C#"
end

local function targetFrameworkPrepare()
local cfg = test.getconfig(prj, "Debug")
dn2005.netcore.targetFramework(cfg)
local cfg = test.getconfig(prj, "Debug")
dn2005.netcore.targetFramework(cfg)
end

local function targetFrameworkVersionPrepare()
local cfg = test.getconfig(prj, "Debug")
dn2005.targetFrameworkVersion(cfg)
local cfg = test.getconfig(prj, "Debug")
dn2005.targetFrameworkVersion(cfg)
end

local function projectConfigurationsPrepare()
dn2005.projectConfigurations(prj)
dn2005.projectConfigurations(prj)
end

local function prepareNetcore()
dn2005.projectElement(prj)
dn2005.projectElement(prj)
end

local function prepareProjectProperties()
local localProj = test.getproject(wks, 1)
local localProj = test.getproject(wks, 1)

dn2005.prepare(cs2005)
dn2005.projectProperties(localProj)
dn2005.prepare(cs2005)
dn2005.projectProperties(localProj)
end

function suite.targetFrameworkProperty_framework()
dotnetframework "4.7.2"
targetFrameworkPrepare()
test.isemptycapture()
dotnetframework "4.7.2"
targetFrameworkPrepare()
test.isemptycapture()
end

function suite.targetFrameworkProperty_core()
dotnetframework "netcoreapp2.2"
targetFrameworkPrepare()
test.capture [[
dotnetframework "netcoreapp2.2"
targetFrameworkPrepare()
test.capture [[
<TargetFramework>netcoreapp2.2</TargetFramework>
]]
end

function suite.targetFrameworkProperty_standard()
dotnetframework "netstandard1.2"
targetFrameworkPrepare()
test.capture [[
dotnetframework "netstandard1.2"
targetFrameworkPrepare()
test.capture [[
<TargetFramework>netstandard1.2</TargetFramework>
]]
]]
end

function suite.targetFrameworkVersionProperty_framework()
dotnetframework "4.7.2"
targetFrameworkVersionPrepare()
test.capture [[
dotnetframework "4.7.2"
targetFrameworkVersionPrepare()
test.capture [[
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
]]
]]
end

function suite.targetFrameworkVersionProperty_core()
dotnetframework "netcoreapp2.2"
targetFrameworkVersionPrepare()
test.isemptycapture()
dotnetframework "netcoreapp2.2"
targetFrameworkVersionPrepare()
test.isemptycapture()
end

function suite.targetFrameworkVersionProperty_standard()
dotnetframework "netstandard1.2"
targetFrameworkVersionPrepare()
test.isemptycapture()
dotnetframework "netstandard1.2"
targetFrameworkVersionPrepare()
test.isemptycapture()
end

function suite.project_element_standard()
dotnetframework "netstandard1.2"
prepareNetcore()
test.capture [[
dotnetframework "netstandard1.2"
prepareNetcore()
test.capture [[
<Project Sdk="Microsoft.NET.Sdk">
]]
]]
end

function suite.project_element_core()
dotnetframework "netcoreapp1.2"
prepareNetcore()
test.capture [[
dotnetframework "netcoreapp1.2"
prepareNetcore()
test.capture [[
<Project Sdk="Microsoft.NET.Sdk">
]]
]]
end

function suite.project_element_net5()
dotnetframework "net5.0"
prepareNetcore()
test.capture [[
dotnetframework "net5.0"
prepareNetcore()
test.capture [[
<Project Sdk="Microsoft.NET.Sdk">
]]
]]
end

function suite.project_element_framework()
dotnetframework "4.7.2"
prepareNetcore()
test.capture [[
dotnetframework "4.7.2"
prepareNetcore()
test.capture [[
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
]]
]]
end

function suite.allowUnsafeProperty_core()
dotnetframework "netcoreapp2.2"
clr "Unsafe"
prepareProjectProperties()
test.capture [[
dotnetframework "netcoreapp2.2"
clr "Unsafe"
prepareProjectProperties()
test.capture [[
<PropertyGroup>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
]]
]]
end

function suite.implicitUsings_on()
p.action.set("vs2022")
dotnetframework "net10.0"
enableimplicitusings "On"
prepareProjectProperties()
test.capture [[
p.action.set("vs2022")
dotnetframework "net10.0"
enableimplicitusings "On"
prepareProjectProperties()
test.capture [[
<PropertyGroup>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
Expand All @@ -152,15 +152,15 @@ function suite.implicitUsings_on()
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>
]]
]]
end

function suite.implicitUsings_off()
p.action.set("vs2022")
dotnetframework "net10.0"
enableimplicitusings "Off"
prepareProjectProperties()
test.capture [[
p.action.set("vs2022")
dotnetframework "net10.0"
enableimplicitusings "Off"
prepareProjectProperties()
test.capture [[
<PropertyGroup>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
Expand All @@ -169,7 +169,22 @@ function suite.implicitUsings_off()
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<ImplicitUsings>false</ImplicitUsings>
</PropertyGroup>
]]
]]
end

function suite.multiple_target_dotnet_frameworks()
Comment thread
CapeGuyBen marked this conversation as resolved.
p.action.set("vs2022")
dotnetframework { "net8.0", "net10.0" }
prepareProjectProperties()
test.capture [[
<PropertyGroup>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<Configurations>Debug;Release;Distribution</Configurations>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>
]]
end

function suite.project_element_configurations()
Expand Down
15 changes: 15 additions & 0 deletions modules/vstudio/tests/vc2010/test_globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ function suite.frameworkVersionIsCorrectNetCore_onSpecificVersion()
]]
end

function suite.frameworkVersionIsCorrectNetCore_onSpecificVersions()
clr "NetCore"
dotnetframework { "net8.0", "net10.0" }
prepare()
test.capture [[
<PropertyGroup Label="Globals">
<ProjectGuid>{42B5DBC6-AE1F-903D-F75D-41E363076E92}</ProjectGuid>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<Keyword>ManagedCProj</Keyword>
<RootNamespace>MyProject</RootNamespace>
</PropertyGroup>
]]
end


--
-- Omit Keyword and RootNamespace for non-Windows projects.
--
Expand Down
51 changes: 39 additions & 12 deletions modules/vstudio/vs2005_dotnetbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,12 @@
local packageAPIInfo = vstudio.nuget2010.packageAPIInfo(prj, package)

local action = p.action.current()
local targetFramework = cfg.dotnetframework or action.vstudio.targetFramework
local targetFramework = nil
if #cfg.dotnetframework > 0 then
targetFramework = cfg.dotnetframework[#cfg.dotnetframework]
else
targetFramework = action.vstudio.targetFramework
end

local targetVersion = dotnetbase.makeVersionComparable(targetFramework)

Expand Down Expand Up @@ -754,7 +759,14 @@

function dotnetbase.targetFrameworkVersion(cfg)
local action = p.action.current()
local framework = cfg.dotnetframework or action.vstudio.targetFramework

local framework = nil
if #cfg.dotnetframework > 0 then
framework = cfg.dotnetframework[#cfg.dotnetframework]
else
framework = action.vstudio.targetFramework
end

if framework and not dotnetbase.isNewFormatProject(cfg) then
_p(2,'<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', framework)
end
Expand Down Expand Up @@ -793,23 +805,38 @@
end

function dotnetbase.isNewFormatProject(cfg)
local framework = cfg.dotnetframework
if not framework then
return false
end

if framework:find('^net') ~= nil then
return true
local frameworks = cfg.dotnetframework
for _, currFramework in ipairs(frameworks) do
if currFramework:find('^net') ~= nil then
return true
end
end

return false
end

function dotnetbase.netcore.targetFramework(cfg)
local action = p.action.current()
local framework = cfg.dotnetframework or action.vstudio.targetFramework
if framework and dotnetbase.isNewFormatProject(cfg) then
_p(2,'<TargetFramework>%s</TargetFramework>', framework)

local frameworks = nil
if #cfg.dotnetframework > 0 then
frameworks = cfg.dotnetframework
else
targetFramework = action.vstudio.targetFramework
if targetFramework ~= nil then
frameworks = { [1] = targetFramework }
end

end

if frameworks ~= nil then
if dotnetbase.isNewFormatProject(cfg) then
if #frameworks > 1 then
_p(2, '<TargetFrameworks>%s</TargetFrameworks>', table.concat(frameworks, ";"))
else
_p(2, '<TargetFramework>%s</TargetFramework>', frameworks[1])
end
end
end
end

Expand Down
7 changes: 6 additions & 1 deletion modules/vstudio/vs2010_nuget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@
if p.project.isdotnet(prj) then
local cfg = p.project.getfirstconfig(prj)
local action = p.action.current()
local framework = cfg.dotnetframework or action.vstudio.targetFramework
local framework = nil
if #cfg.dotnetframework > 0 then
framework = cfg.dotnetframework[#cfg.dotnetframework]
else
framework = action.vstudio.targetFramework
end
return dn2005.formatNuGetFrameworkVersion(framework)
else
return "native"
Expand Down
26 changes: 20 additions & 6 deletions modules/vstudio/vs2010_vcxproj.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,30 @@

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

local framework = prj.dotnetframework or action.vstudio.targetFramework or "4.0"
if framework and dotnetbase.isNewFormatProject(prj) then
p.w('<TargetFramework>%s</TargetFramework>', framework)
local frameworks = nil
if #prj.dotnetframework > 0 then
frameworks = prj.dotnetframework
else
p.w('<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', framework)
targetFramework = action.vstudio.targetFramework or "4.0"
frameworks = { [1] = targetFramework }

end
end

if frameworks ~= nil then
if dotnetbase.isNewFormatProject(prj) then
if #frameworks > 1 then
p.w('<TargetFrameworks>%s</TargetFrameworks>', table.concat(frameworks, ";"))
else
p.w('<TargetFramework>%s</TargetFramework>', frameworks[1])
end
else
if #frameworks >= 1 then
p.w('<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', frameworks[#frameworks])
end
end
end
end


--
Expand Down
Loading
Loading