diff --git a/modules/vstudio/_preload.lua b/modules/vstudio/_preload.lua
index eae6fae82b..4769926644 100644
--- a/modules/vstudio/_preload.lua
+++ b/modules/vstudio/_preload.lua
@@ -195,6 +195,13 @@
}
}
+ p.api.register {
+ name = "vsprops",
+ scope = "config",
+ kind = "list:table",
+ tokens = true,
+ }
+
--
-- Decide when the full module should be loaded.
--
diff --git a/modules/vstudio/tests/_tests.lua b/modules/vstudio/tests/_tests.lua
index 07cd658a26..3bf71afba0 100644
--- a/modules/vstudio/tests/_tests.lua
+++ b/modules/vstudio/tests/_tests.lua
@@ -6,6 +6,7 @@ return {
"dotnet2005/test_nuget_framework_folders.lua",
-- Visual Studio 2005+ C# projects
+ "cs2005/test_additional_props.lua",
"cs2005/test_assembly_refs.lua",
"cs2005/test_build_events.lua",
"cs2005/test_common_props.lua",
diff --git a/modules/vstudio/tests/cs2005/test_additional_props.lua b/modules/vstudio/tests/cs2005/test_additional_props.lua
new file mode 100644
index 0000000000..f36a06b40a
--- /dev/null
+++ b/modules/vstudio/tests/cs2005/test_additional_props.lua
@@ -0,0 +1,84 @@
+--
+-- tests/actions/vstudio/cs2005/test_additional_props.lua
+-- Test the compiler flags of a Visual Studio 2005+ C# project.
+-- Copyright (c) 2012-2023 Jason Perkins and the Premake project
+--
+
+ local p = premake
+ local suite = test.declare("vstudio_cs2005_additional_props")
+ 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()
+ end
+
+ local function prepare()
+ local cfg = test.getconfig(prj, "Debug")
+ dn2005.additionalProps(cfg)
+ end
+
+
+--
+-- Check handling of AdditionialProps.
+-- Elements specified at a time are sorted by name before placement.
+--
+
+ function suite.propsAreSorted()
+ vsprops {
+ Zzz = "zzz",
+ Aaa = "aaa",
+ Nullable = "enable",
+ }
+ prepare()
+ test.capture [[
+ aaa
+ enable
+ zzz
+ ]]
+ end
+
+
+--
+-- Check handling of AdditionialProps.
+-- Element groups set multiple times are placed in the order in which they are set.
+--
+
+ function suite.multipleSetPropsAreNotSorted()
+ vsprops {
+ Zzz = "zzz",
+ }
+ vsprops {
+ Aaa = "aaa",
+ }
+ vsprops {
+ Nullable = "enable",
+ }
+ prepare()
+ test.capture [[
+ zzz
+ aaa
+ enable
+ ]]
+ end
+
+
+ function suite.xmlEscape()
+ vsprops {
+ ValueRequiringEscape = "if (age > 3 && age < 8)",
+ }
+ prepare()
+ test.capture [[
+ if (age > 3 && age < 8)
+ ]]
+ end
+
+
diff --git a/modules/vstudio/tests/vc2010/test_globals.lua b/modules/vstudio/tests/vc2010/test_globals.lua
index a6542567fe..24e84cc64d 100644
--- a/modules/vstudio/tests/vc2010/test_globals.lua
+++ b/modules/vstudio/tests/vc2010/test_globals.lua
@@ -477,6 +477,45 @@ end
end
+ function suite.additionalProps()
+ p.action.set("vs2022")
+
+ vsprops {
+ -- https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#2-set-agility-sdk-parameters
+ Microsoft_Direct3D_D3D12_D3D12SDKPath = "custom_path",
+ ValueRequiringEscape = "if (age > 3 && age < 8)",
+ }
+ filter "Debug"
+ vsprops {
+ CustomParam = "DebugParam",
+ }
+ filter "Release"
+ vsprops {
+ CustomParam = "ReleaseParam",
+ }
+ filter {}
+ prepare()
+ test.capture [[
+
+ {42B5DBC6-AE1F-903D-F75D-41E363076E92}
+ true
+ Win32Proj
+ MyProject
+
+
+ custom_path
+ if (age > 3 && age < 8)
+ DebugParam
+
+
+ custom_path
+ if (age > 3 && age < 8)
+ ReleaseParam
+
+ ]]
+ end
+
+
function suite.disableFastUpToDateCheck()
fastuptodate "Off"
prepare()
diff --git a/modules/vstudio/vs2005_csproj.lua b/modules/vstudio/vs2005_csproj.lua
index 83a6816319..73c252efda 100644
--- a/modules/vstudio/vs2005_csproj.lua
+++ b/modules/vstudio/vs2005_csproj.lua
@@ -81,7 +81,8 @@
dotnetbase.debugProps,
dotnetbase.outputProps,
dotnetbase.compilerProps,
- dotnetbase.NoWarn
+ dotnetbase.additionalProps,
+ dotnetbase.NoWarn,
}
end
diff --git a/modules/vstudio/vs2005_dotnetbase.lua b/modules/vstudio/vs2005_dotnetbase.lua
index e05f21e246..d0f45003ae 100644
--- a/modules/vstudio/vs2005_dotnetbase.lua
+++ b/modules/vstudio/vs2005_dotnetbase.lua
@@ -8,6 +8,7 @@
p.vstudio.dotnetbase = {}
local vstudio = p.vstudio
+ local vs2005 = p.vstudio.vs2005
local dotnetbase = p.vstudio.dotnetbase
local project = p.project
local config = p.config
@@ -241,6 +242,17 @@
end
end
+--
+-- Write out the additional props.
+--
+
+ function dotnetbase.additionalProps(cfg)
+ for i = 1, #cfg.vsprops do
+ for key, value in spairs(cfg.vsprops[i]) do
+ _p(2, '<%s>%s%s>', key, vs2005.esc(value), key)
+ end
+ end
+ end
--
-- Write the compiler flags for a particular configuration.
@@ -740,6 +752,7 @@
end
end
+
function dotnetbase.targetFrameworkProfile(cfg)
if _ACTION == "vs2010" then
_p(2,'')
diff --git a/modules/vstudio/vs2005_fsproj.lua b/modules/vstudio/vs2005_fsproj.lua
index 6c7e8a8d76..779103ccd7 100644
--- a/modules/vstudio/vs2005_fsproj.lua
+++ b/modules/vstudio/vs2005_fsproj.lua
@@ -52,6 +52,7 @@
dotnetbase.debugProps,
dotnetbase.outputProps,
dotnetbase.compilerProps,
+ dotnetbase.additionalProps,
dotnetbase.NoWarn,
fs2005.tailCalls
}
diff --git a/modules/vstudio/vs2010_vcxproj.lua b/modules/vstudio/vs2010_vcxproj.lua
index 9eec95a402..c2a80e5c86 100644
--- a/modules/vstudio/vs2010_vcxproj.lua
+++ b/modules/vstudio/vs2010_vcxproj.lua
@@ -8,6 +8,7 @@
p.vstudio.vc2010 = {}
local vstudio = p.vstudio
+ local vs2010 = p.vstudio.vs2010
local project = p.project
local config = p.config
local fileconfig = p.fileconfig
@@ -143,6 +144,7 @@
return {
m.windowsTargetPlatformVersion,
m.xpDeprecationWarning,
+ m.additionalProps,
}
end
@@ -1349,8 +1351,8 @@
if value and #value > 0 then
m.element(prop.name, m.configPair(cfg), '%s', value)
end
- end
end
+ end
if #m.conditionalElements > 0 then
m.emitConditionalElements(prj)
end
@@ -2903,6 +2905,15 @@
end
+ function m.additionalProps(prj, cfg)
+ for i = 1, #cfg.vsprops do
+ for key, value in spairs(cfg.vsprops[i]) do
+ m.element(key, nil, vs2010.esc(value))
+ end
+ end
+ end
+
+
function m.fastUpToDateCheck(prj)
if prj.fastuptodate ~= nil then
m.element("DisableFastUpToDateCheck", nil, iif(prj.fastuptodate, "false", "true"))
diff --git a/website/docs/vsprops.md b/website/docs/vsprops.md
new file mode 100644
index 0000000000..bc8366436f
--- /dev/null
+++ b/website/docs/vsprops.md
@@ -0,0 +1,51 @@
+Add any property to your visual studio project
+This allows you to set properties that premake does not support without extending it
+
+Values set at one time are sorted alphabetically
+If you want to output groups of values in any order, set multiple times.
+
+```lua
+ vsprops {
+ Name1 = "value1",
+ Name2 = "value2",
+ }
+ vsprops {
+ Name3 = "value3",
+ }
+```
+
+### Parameters ###
+
+Name and value are strings
+
+### Availability ###
+
+Premake 5.0-beta3 or later.
+
+### Applies To ###
+
+The `config` scope.
+
+### Examples ###
+
+```lua
+ language "C#"
+ vsprops {
+ -- https://devblogs.microsoft.com/visualstudio/vs-toolbox-accelerate-your-builds-of-sdk-style-net-projects/
+ AccelerateBuildsInVisualStudio = "true",
+ -- https://learn.microsoft.com/en-us/visualstudio/ide/how-to-change-the-build-output-directory?view=vs-2022
+ AppendTargetFrameworkToOutputPath = "false",
+ -- https://learn.microsoft.com/en-us/dotnet/csharp/tutorials/nullable-reference-types
+ Nullable = "enable",
+ }
+```
+```lua
+ language "C++"
+ nuget {
+ "Microsoft.Direct3D.D3D12:1.608.2"
+ }
+ vsprops {
+ -- https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#2-set-agility-sdk-parameters
+ Microsoft_Direct3D_D3D12_D3D12SDKPath = "custom_path",
+ }
+```