diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua index cd5f495b..2a742999 100644 --- a/modules/vstudio/tests/_tests.lua +++ b/modules/vstudio/tests/_tests.lua @@ -14,6 +14,7 @@ return { "cs2005/test_debug_props.lua", "cs2005/test_files.lua", "cs2005/test_icon.lua", + "cs2005/test_netcore.lua", "cs2005/test_nuget_config.lua", "cs2005/test_nuget_packages_config.lua", "cs2005/test_nuget_references.lua", diff --git a/modules/vstudio/tests/cs2005/test_netcore.lua b/modules/vstudio/tests/cs2005/test_netcore.lua new file mode 100644 index 00000000..cfa138a1 --- /dev/null +++ b/modules/vstudio/tests/cs2005/test_netcore.lua @@ -0,0 +1,103 @@ +-- +-- tests/actions/vstudio/cs2005/test_output_props.lua +-- Test the target output settings of a Visual Studio 2005+ C# project. +-- Copyright (c) 2012-2013 Jason Perkins and the Premake project +-- + +local p = premake +local suite = test.declare("vstudio_cs2005_netcore_prj") +local dn2005 = p.vstudio.dotnetbase +local project = p.project + + +-- +-- Setup and teardown +-- + +local wks, prj + +function suite.setup() + p.action.set("vs2005") + wks, prj = test.createWorkspace() + language "C#" +end + +local function targetFrameworkPrepare() + local cfg = test.getconfig(prj, "Debug") + dn2005.netcore.targetFramework(cfg) +end + +local function targetFrameworkVersionPrepare() + local cfg = test.getconfig(prj, "Debug") + dn2005.targetFrameworkVersion(cfg) +end + +local function prepareNetcore() + dn2005.projectElement(prj) +end + +function suite.targetFrameworkProperty_framework() + dotnetframework "4.7.2" + targetFrameworkPrepare() + test.isemptycapture() +end + +function suite.targetFrameworkProperty_core() + dotnetframework "netcoreapp2.2" + targetFrameworkPrepare() + test.capture [[ + netcoreapp2.2 + ]] +end + +function suite.targetFrameworkProperty_standard() + dotnetframework "netstandard1.2" + targetFrameworkPrepare() + test.capture [[ + netstandard1.2 + ]] +end + +function suite.targetFrameworkVersionProperty_framework() + dotnetframework "4.7.2" + targetFrameworkVersionPrepare() + test.capture [[ + v4.7.2 + ]] +end + +function suite.targetFrameworkVersionProperty_core() + dotnetframework "netcoreapp2.2" + targetFrameworkVersionPrepare() + test.isemptycapture() +end + +function suite.targetFrameworkVersionProperty_standard() + dotnetframework "netstandard1.2" + targetFrameworkVersionPrepare() + test.isemptycapture() +end + +function suite.project_element_standard() + dotnetframework "netstandard1.2" + prepareNetcore() + test.capture [[ + + ]] +end + +function suite.project_element_core() + dotnetframework "netcoreapp1.2" + prepareNetcore() + test.capture [[ + + ]] +end + +function suite.project_element_framework() + dotnetframework "4.7.2" + prepareNetcore() + test.capture [[ + + ]] +end diff --git a/modules/vstudio/vs2005_csproj.lua b/modules/vstudio/vs2005_csproj.lua index 816f0fc5..186cde45 100644 --- a/modules/vstudio/vs2005_csproj.lua +++ b/modules/vstudio/vs2005_csproj.lua @@ -17,36 +17,61 @@ cs2005.elements = {} - cs2005.elements.project = function () - return { - dotnetbase.xmlDeclaration, - dotnetbase.projectElement, - dotnetbase.commonProperties, - dotnetbase.projectProperties, - dotnetbase.configurations, - dotnetbase.applicationIcon, - dotnetbase.references - } + cs2005.elements.project = function (prj) + if dotnetbase.isNewFormatProject(prj) then + return { + dotnetbase.projectElement, + dotnetbase.projectProperties, + dotnetbase.configurations, + dotnetbase.applicationIcon, + dotnetbase.references + } + else + return { + dotnetbase.xmlDeclaration, + dotnetbase.projectElement, + dotnetbase.commonProperties, + dotnetbase.projectProperties, + dotnetbase.configurations, + dotnetbase.applicationIcon, + dotnetbase.references + } + end end - cs2005.elements.projectProperties = function () - return { - dotnetbase.configurationCondition, - dotnetbase.platformCondition, - dotnetbase.productVersion, - dotnetbase.schemaVersion, - dotnetbase.projectGuid, - dotnetbase.outputType, - dotnetbase.appDesignerFolder, - dotnetbase.rootNamespace, - dotnetbase.assemblyName, - dotnetbase.targetFrameworkVersion, - dotnetbase.targetFrameworkProfile, - dotnetbase.fileAlignment, - dotnetbase.bindingRedirects, - dotnetbase.projectTypeGuids, - dotnetbase.csversion - } + cs2005.elements.projectProperties = function (cfg) + if dotnetbase.isNewFormatProject(cfg) then + return { + dotnetbase.outputType, + dotnetbase.appDesignerFolder, + dotnetbase.rootNamespace, + dotnetbase.assemblyName, + dotnetbase.netcore.targetFramework, + dotnetbase.fileAlignment, + dotnetbase.bindingRedirects, + dotnetbase.netcore.useWpf, + dotnetbase.csversion, + dotnetbase.netcore.enableDefaultCompileItems, + } + else + return { + dotnetbase.configurationCondition, + dotnetbase.platformCondition, + dotnetbase.productVersion, + dotnetbase.schemaVersion, + dotnetbase.projectGuid, + dotnetbase.outputType, + dotnetbase.appDesignerFolder, + dotnetbase.rootNamespace, + dotnetbase.assemblyName, + dotnetbase.targetFrameworkVersion, + dotnetbase.targetFrameworkProfile, + dotnetbase.fileAlignment, + dotnetbase.bindingRedirects, + dotnetbase.projectTypeGuids, + dotnetbase.csversion, + } + end end cs2005.elements.configuration = function () @@ -65,13 +90,15 @@ end function cs2005.targets(prj) - local bin = iif(_ACTION <= "vs2010", "MSBuildBinPath", "MSBuildToolsPath") - _p(1,'', bin) - _p(1,'') + if not dotnetbase.isNewFormatProject(prj) then + local bin = iif(_ACTION <= "vs2010", "MSBuildBinPath", "MSBuildToolsPath") + _p(1,'', bin) + _p(1,'') + end end diff --git a/modules/vstudio/vs2005_dotnetbase.lua b/modules/vstudio/vs2005_dotnetbase.lua index 21321a31..4275e0a3 100644 --- a/modules/vstudio/vs2005_dotnetbase.lua +++ b/modules/vstudio/vs2005_dotnetbase.lua @@ -17,7 +17,7 @@ dotnetbase.elements = {} dotnetbase.langObj = {} - + dotnetbase.netcore = {} -- -- Generate a Visual Studio 200x dotnet project, with support for the new platforms API. @@ -55,12 +55,20 @@ -- function dotnetbase.projectElement(prj) - local ver = '' - local action = p.action.current() - if action.vstudio.toolsVersion then - ver = string.format(' ToolsVersion="%s"', action.vstudio.toolsVersion) + if dotnetbase.isNewFormatProject(prj) then + if prj.flags.WPF then + _p('') + else + _p('') + end + else + local ver = '' + local action = p.action.current() + if action.vstudio.toolsVersion then + ver = string.format(' ToolsVersion="%s"', action.vstudio.toolsVersion) + end + _p('', ver) end - _p('', ver) end @@ -291,7 +299,7 @@ -- Want to set BaseIntermediateOutputPath because otherwise VS will create obj/ -- anyway. But VS2008 throws up ominous warning if present. local objdir = vstudio.path(cfg, cfg.objdir) - if _ACTION > "vs2008" then + if _ACTION > "vs2008" and not dotnetbase.isNewFormatProject(cfg) then _x(2,'%s\\', objdir) _p(2,'$(BaseIntermediateOutputPath)') else @@ -476,10 +484,16 @@ -- Write the list of project dependencies. -- function dotnetbase.projectReferences(prj) - _p(1,'') + if not dotnetbase.isNewFormatProject(prj) then + _p(1,'') + end local deps = project.getdependencies(prj, 'linkOnly') if #deps > 0 then + if dotnetbase.isNewFormatProject(prj) then + _p(1,'') + end + for _, dep in ipairs(deps) do local relpath = vstudio.path(prj, vstudio.projectfile(dep)) _x(2,'', relpath) @@ -492,9 +506,15 @@ _p(2,'') end + + if dotnetbase.isNewFormatProject(prj) then + _p(1,'') + end end - _p(1,'') + if not dotnetbase.isNewFormatProject(prj) then + _p(1,'') + end end -- @@ -608,7 +628,9 @@ function dotnetbase.assemblyName(cfg) - _p(2,'%s', cfg.buildtarget.basename) + if not dotnetbase.isNewFormatProject(cfg) --[[or cfg.assemblyname]] then + _p(2,'%s', cfg.buildtarget.basename) + end end @@ -625,14 +647,14 @@ function dotnetbase.fileAlignment(cfg) - if _ACTION >= "vs2010" then + if _ACTION >= "vs2010" and not dotnetbase.isNewFormatProject(cfg) then _p(2,'512') end end function dotnetbase.bindingRedirects(cfg) - if _ACTION >= "vs2015" then + if _ACTION >= "vs2015" and not dotnetbase.isNewFormatProject(cfg) then _p(2, 'true') end end @@ -668,7 +690,9 @@ function dotnetbase.rootNamespace(cfg) - _p(2,'%s', cfg.namespace or cfg.buildtarget.basename) + if not dotnetbase.isNewFormatProject(cfg) or cfg.namespace then + _p(2,'%s', cfg.namespace or cfg.buildtarget.basename) + end end @@ -690,7 +714,7 @@ function dotnetbase.targetFrameworkVersion(cfg) local action = p.action.current() local framework = cfg.dotnetframework or action.vstudio.targetFramework - if framework then + if framework and not dotnetbase.isNewFormatProject(cfg) then _p(2,'v%s', framework) end end @@ -715,3 +739,37 @@ end end + function dotnetbase.isNewFormatProject(cfg) + local framework = cfg.dotnetframework + if not framework then + return false + end + + if framework:find('^netcoreapp') ~= nil then + return true + end + + if framework:find('^netstandard') ~= nil then + return true + 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,'%s', framework) + end + end + + function dotnetbase.netcore.enableDefaultCompileItems(cfg) + _p(2,'%s', iif(cfg.enableDefaultCompileItems, "true", "false")) + end + + function dotnetbase.netcore.useWpf(cfg) + if cfg.flags.WPF then + _p(2,'true') + end + end \ No newline at end of file diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 1546387f..8dfb1143 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -593,6 +593,13 @@ kind = "string", } + api.register { + name = "enabledefaultcompileitems", + scope = "config", + kind = "boolean", + default = false + } + api.register { name = "csversion", scope = "config",