summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJassJam <[email protected]>2026-02-24 10:48:41 +0000
committerruki <[email protected]>2026-03-14 00:10:12 +0800
commit6fdb4e159d23995e01a676ee9bf754ad171f5afd (patch)
treedcc19c68eb88a300b663fdaa0a69d409988e8572
parent426746d3e909887b55918508b7ee3f2024466257 (diff)
feat: add dotnet verbosity option for csharp rule
-rw-r--r--xmake/core/project/policy.lua2
-rw-r--r--xmake/rules/csharp/xmake.lua46
2 files changed, 42 insertions, 6 deletions
diff --git a/xmake/core/project/policy.lua b/xmake/core/project/policy.lua
index 0cf184d91..09751ba72 100644
--- a/xmake/core/project/policy.lua
+++ b/xmake/core/project/policy.lua
@@ -125,6 +125,8 @@ function policy.policies()
["build.progress_style"] = {description = "Set the build progress output style.", type = "string", values = {"scroll", "singlerow", "multirow"}},
-- Show target name in build progress output
["build.progress_show_target"] = {description = "Show target name in build progress output.", default = true, type = "boolean"},
+ -- Set dotnet verbosity for csharp rule, e.g. quiet|minimal|normal|detailed|diagnostic
+ ["build.csharp.dotnet_verbosity"] = {description = "Set dotnet verbosity for csharp rule.", type = "string", values = {"quiet", "minimal", "normal", "detailed", "diagnostic"}},
-- Enable windows UAC and set level, e.g. invoker, admin, highest
["windows.manifest.uac"] = {description = "Enable windows manifest UAC.", type = "string"},
-- Enable ui access for windows UAC
diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua
index 6bc0eef74..88f235ae1 100644
--- a/xmake/rules/csharp/xmake.lua
+++ b/xmake/rules/csharp/xmake.lua
@@ -112,6 +112,37 @@ rule("csharp.build")
end
end
+ local function _get_dotnet_runopt(csprojfile)
+ return {
+ curdir = path.directory(csprojfile),
+ envs = {
+ DOTNET_NOLOGO = "1",
+ DOTNET_CLI_TELEMETRY_OPTOUT = "1",
+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE = "1",
+ DOTNET_GENERATE_ASPNET_CERTIFICATE = "0",
+ DOTNET_ADD_GLOBAL_TOOLS_TO_PATH = "0"
+ }
+ }
+ end
+
+ local function _get_dotnet_verbosity(target)
+ local verbosity = target:values("csharp.dotnet_verbosity")
+ if type(verbosity) == "table" then
+ verbosity = verbosity[1]
+ end
+ if not (verbosity and #verbosity > 0) then
+ verbosity = target:policy("build.csharp.dotnet_verbosity")
+ end
+ if verbosity and #verbosity > 0 then
+ verbosity = verbosity:lower()
+ if table.contains({"quiet", "minimal", "normal", "detailed", "diagnostic"}, verbosity) then
+ return verbosity
+ end
+ raise("target(%s): invalid csharp.dotnet_verbosity(%s), expected one of: quiet|minimal|normal|detailed|diagnostic", target:name(), verbosity)
+ end
+ return "quiet"
+ end
+
local function _get_dotnet_program(target)
local function _get_configured_program(toolkind)
if target:get("toolset." .. toolkind) then
@@ -177,12 +208,13 @@ rule("csharp.build")
local csprojfile = assert(_find_csproj(target), "target(%s): missing csharp .csproj file!", target:name())
local dotnet = _get_dotnet_program(target)
local configuration = _build_mode_to_configuration()
+ local verbosity = _get_dotnet_verbosity(target)
local command = target:is_binary() and "publish" or "build"
local argv = {
command, csprojfile,
"--nologo",
"--configuration", configuration,
- "--verbosity", "minimal"
+ "--verbosity", verbosity
}
local targetdir = target:targetdir()
@@ -203,7 +235,7 @@ rule("csharp.build")
batchcmds:mkdir(targetdirabs)
end
- batchcmds:vrunv(dotnet, argv, {curdir = path.directory(csprojfile)})
+ batchcmds:vrunv(dotnet, argv, _get_dotnet_runopt(csprojfile))
local targetfile = target:targetfile()
if targetfile then
@@ -233,6 +265,7 @@ rule("csharp.build")
local csprojfile = assert(_find_csproj(target), "target(%s): missing csharp .csproj file!", target:name())
local dotnet = _get_dotnet_program(target)
local configuration = _build_mode_to_configuration()
+ local verbosity = _get_dotnet_verbosity(target)
local install_path = target:installdir()
if target:is_binary() then
@@ -253,7 +286,7 @@ rule("csharp.build")
"publish", csprojfile,
"--nologo",
"--configuration", configuration,
- "--verbosity", "minimal",
+ "--verbosity", verbosity,
"--output", install_abs
}
@@ -262,7 +295,7 @@ rule("csharp.build")
end
_append_target_flags(target, argv)
- local runopt = {curdir = path.directory(csprojfile)}
+ local runopt = _get_dotnet_runopt(csprojfile)
if os.vrunv then
os.vrunv(dotnet, argv, runopt)
elseif os.runv then
@@ -303,6 +336,7 @@ rule("csharp.build")
local csprojfile = assert(_find_csproj(target), "target(%s): missing csharp .csproj file!", target:name())
local dotnet = _get_dotnet_program(target)
local configuration = _build_mode_to_configuration()
+ local verbosity = _get_dotnet_verbosity(target)
local install_path = target:installdir()
if target:is_binary() then
@@ -316,7 +350,7 @@ rule("csharp.build")
"publish", csprojfile,
"--nologo",
"--configuration", configuration,
- "--verbosity", "minimal"
+ "--verbosity", verbosity
}
if install_path and #install_path > 0 then
install_abs = path.is_absolute(install_path) and install_path or path.absolute(install_path, os.projectdir())
@@ -334,7 +368,7 @@ rule("csharp.build")
batchcmds:mkdir(install_abs)
end
- batchcmds:vrunv(dotnet, argv, {curdir = path.directory(csprojfile)})
+ batchcmds:vrunv(dotnet, argv, _get_dotnet_runopt(csprojfile))
end)
rule("csharp")