diff --git a/modules/vstudio/_preload.lua b/modules/vstudio/_preload.lua index 7a1a5b0de..5a7cdb8e0 100644 --- a/modules/vstudio/_preload.lua +++ b/modules/vstudio/_preload.lua @@ -608,6 +608,33 @@ tokens = "true", } + p.api.register { + name = "dotnetsdk", + scope = "project", + kind = "string", + allowed = { + "Default", + "Web", + "Razor", + "Worker", + "Blazor", + "WindowsDesktop", + "MSTest", + function (value) + -- value is expected to be in the format / + local parts = value:explode("/", true, 1) + + if parts and #parts == 2 then + if p.api.checkValue(p.field.get("dotnetsdk"), parts[1], "string") then + return value + end + end + + return nil + end + } + } + p.api.register { name = "mfc", scope = "config", diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua index f35d4d5f4..2540ddc19 100644 --- a/modules/vstudio/tests/_tests.lua +++ b/modules/vstudio/tests/_tests.lua @@ -15,6 +15,7 @@ return { "cs2005/test_debug_props.lua", "cs2005/test_debug_props_2019.lua", "cs2005/test_documentation_file.lua", + "cs2005/test_dotnetsdk.lua", "cs2005/test_files.lua", "cs2005/test_icon.lua", "cs2005/test_netcore.lua", diff --git a/modules/vstudio/tests/cs2005/test_dotnetsdk.lua b/modules/vstudio/tests/cs2005/test_dotnetsdk.lua new file mode 100644 index 000000000..18e9dfab6 --- /dev/null +++ b/modules/vstudio/tests/cs2005/test_dotnetsdk.lua @@ -0,0 +1,182 @@ +-- +-- tests/actions/vstudio/cs2005/test_dotnetsdk.lua +-- Test DotnetSDK feature Visual Studio 2005+ C# project. +-- Copyright (c) 2012-2025 Jason Perkins and the Premake project +-- + local p = premake + local suite = test.declare("vstudio_cs2005_dotnetsdk") + local dn2005 = p.vstudio.dotnetbase +-- +-- Setup +-- + + local wks, prj + +-- +-- Setup and teardown +-- + function suite.setup() + p.action.set("vs2010") + wks = test.createWorkspace() + configurations { "Debug", "Release" } + language "C#" + dotnetframework "net8.0" + end + + local function setConfig() + local cfg = test.getconfig(prj, "Debug") + dn2005.projectElement(cfg); + end + + local function prepare() + prj = test.getproject(wks, 1) + end + + function suite.testNone() + prepare() + setConfig() + + test.capture [[ + + ]] + end + + function suite.testDefault() + prepare() + setConfig() + dotnetsdk "Default" + test.capture [[ + + ]] + end + + function suite.testWeb() + prepare() + dotnetsdk "Web" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testRazor() + prepare() + dotnetsdk "Razor" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testWorker() + prepare() + dotnetsdk "Worker" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testBlazor() + prepare() + dotnetsdk "Blazor" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testWindowsDesktop() + prepare() + dotnetsdk "WindowsDesktop" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testMSTest() + prepare() + dotnetsdk "MSTest/3.4.0" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testWPFFlag() + prepare() + flags { "WPF" } + setConfig() + + test.capture [[ + + ]] + end + + function suite.testWebVersion() + prepare() + dotnetsdk "Web/3.4.0" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testRazorVersion() + prepare() + dotnetsdk "Razor/3.4.0" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testWorkerVersion() + prepare() + dotnetsdk "Worker/3.4.0" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testBlazorVersion() + prepare() + dotnetsdk "Blazor/3.4.0" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testWindowsDesktopVersion() + prepare() + dotnetsdk "WindowsDesktop/3.4.0" + setConfig() + + test.capture [[ + + ]] + end + + function suite.testCustomSDKVersion() + prepare() + premake.api.addAllowed("dotnetsdk", "CustomSdk") + dotnetsdk "CustomSdk/3.4.0" + setConfig() + + test.capture [[ + + ]] + end diff --git a/modules/vstudio/vs2005_csproj.lua b/modules/vstudio/vs2005_csproj.lua index 9d2f0517e..0c8d9cd0e 100644 --- a/modules/vstudio/vs2005_csproj.lua +++ b/modules/vstudio/vs2005_csproj.lua @@ -54,6 +54,7 @@ dotnetbase.csversion, dotnetbase.projectConfigurations, dotnetbase.netcore.enableDefaultCompileItems, + dotnetbase.netcore.dotnetsdk } else return { diff --git a/modules/vstudio/vs2005_dotnetbase.lua b/modules/vstudio/vs2005_dotnetbase.lua index 689286750..0c8ad69c7 100644 --- a/modules/vstudio/vs2005_dotnetbase.lua +++ b/modules/vstudio/vs2005_dotnetbase.lua @@ -57,11 +57,7 @@ function dotnetbase.projectElement(prj) if dotnetbase.isNewFormatProject(prj) then - if prj.flags.WPF then - _p('') - else - _p('') - end + _p('', dotnetbase.netcore.getsdk(prj)) else local ver = '' local action = p.action.current() @@ -827,6 +823,33 @@ end end + function dotnetbase.netcore.getsdk(cfg) + local map = { + ["Default"] = "Microsoft.NET.Sdk", + ["Web"] = "Microsoft.NET.Sdk.Web", + ["Razor"] = "Microsoft.NET.Sdk.Razor", + ["Worker"] = "Microsoft.NET.Sdk.Worker", + ["Blazor"] = "Microsoft.NET.Sdk.BlazorWebAssembly", + ["WindowsDesktop"] = "Microsoft.NET.Sdk.WindowsDesktop", + ["MSTest"] = "MSTest.Sdk", + } + + local parts = nil + + if cfg.dotnetsdk then + parts = cfg.dotnetsdk:explode("/", true, 1) + end + + local sdk = (parts and #parts > 0 and parts[1]) or cfg.dotnetsdk + if not parts or #parts < 2 then + return map[sdk or "Default"] + elseif parts and #parts == 2 then + return string.format("%s/%s", map[parts[1]] or parts[1], parts[2]) + end + + return map["Default"] + end + function dotnetbase.allowUnsafeBlocks(cfg) if cfg.clr == "Unsafe" then _p(2,'true') diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 69f05fc9f..dd13bd24f 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -1120,6 +1120,7 @@ } } + --27 November 2024 api.deprecateValue("flags", "LinkTimeOptimization", "Use `linktimeoptimization` instead.", function(value) linktimeoptimization("On") @@ -1128,6 +1129,14 @@ linktimeoptimization("Default") end) + --25 November 2024 + api.deprecateValue("flags", "WPF", 'Use `dotnetsdk "WindowsDesktop"` instead.', + function(value) + dotnetsdk "WindowsDesktop" + end, + function(value) + dotnetsdk "Default" + end) api.deprecateValue("flags", "FatalWarnings", "Use `fatalwarnings { \"All\" }` instead.", function(value) fatalwarnings({ "All" }) diff --git a/src/base/api.lua b/src/base/api.lua index 75e8a4f9c..ff04a382f 100755 --- a/src/base/api.lua +++ b/src/base/api.lua @@ -265,7 +265,9 @@ if type(field.allowed) == "table" then for i, item in ipairs(field.allowed) do - field.allowed[item:lower()] = item + if type(item) == "string" then + field.allowed[item:lower()] = item + end end end diff --git a/website/docs/dotnetsdk.md b/website/docs/dotnetsdk.md new file mode 100644 index 000000000..ad75b386f --- /dev/null +++ b/website/docs/dotnetsdk.md @@ -0,0 +1,45 @@ +Selects a .NET SDK + +```lua +dotnetsdk "SDK" +``` + +For more information see the MSDN documentation [here](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview) + +## Parameters ## +`SDK` is one of: + + * [Default](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props) + * [Web](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/web-sdk?toc=%2Fdotnet%2Fnavigate%2Ftools-diagnostics%2Ftoc.json&bc=%2Fdotnet%2Fbreadcrumb%2Ftoc.json) + * [Razor](https://learn.microsoft.com/en-us/aspnet/core/razor-pages/sdk?toc=%2Fdotnet%2Fnavigate%2Ftools-diagnostics%2Ftoc.json&bc=%2Fdotnet%2Fbreadcrumb%2Ftoc.json) + * [Worker](https://learn.microsoft.com/en-us/dotnet/core/extensions/workers) + * [Blazor](https://learn.microsoft.com/en-us/aspnet/core/blazor/) + * [WindowsDesktop](https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props-desktop?view=aspnetcore-8.0) + * [MSTest](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-mstest-sdk): Requires a version be specified. + +### Applies To ### + +Project configurations. + +### Availability ### + +Premake 5.0 beta5 or later. + +Visual studio is the only toolset currently supported. + +### Examples ### +```lua +dotnetsdk "Web" +``` + +```lua +dotnetsdk "Web/3.4.0" +``` + +A custom SDK can be specified using the following: +```lua +premake.api.addAllowed("dotnetsdk", "CustomSDK") -- add the custom SDK to allowed values for dotnetsdk +dotnetsdk "CustomSDK" + +dotnetsdk "CustomSDK/3.4.0" -- Specifying a version with a custom SDK is also supported +``` diff --git a/website/sidebars.js b/website/sidebars.js index 418024a91..37633bddd 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -122,6 +122,7 @@ module.exports = { 'display', 'documentationfile', 'dotnetframework', + 'dotnetsdk', 'dpiawareness', 'editandcontinue', 'editorintegration',