diff options
| author | ruki <[email protected]> | 2026-03-14 23:02:18 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-03-14 23:02:18 +0800 |
| commit | 22976f06349a3af4b520ae5796ab20edc95bfe0c (patch) | |
| tree | eb40e0b3395d1083802159031e79691f17676385 /xmake/modules/detect | |
| parent | a86bde866d5f65d5fbd31f1474190dcc40aa2876 (diff) | |
improve find_dotnet
Diffstat (limited to 'xmake/modules/detect')
| -rw-r--r-- | xmake/modules/detect/sdks/find_dotnet.lua | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/xmake/modules/detect/sdks/find_dotnet.lua b/xmake/modules/detect/sdks/find_dotnet.lua index 3430d2626..f64acacd3 100644 --- a/xmake/modules/detect/sdks/find_dotnet.lua +++ b/xmake/modules/detect/sdks/find_dotnet.lua @@ -28,13 +28,21 @@ import("core.project.config") import("core.cache.detectcache") -- find dotnet sdk info from dotnet cli -function _find_dotnet_cli() - local dotnet = find_tool("dotnet", {version = true}) +function _find_dotnet_cli(sdkdir) + + -- find dotnet program + local paths = {} + if sdkdir then + table.insert(paths, path.join(sdkdir, "bin")) + table.insert(paths, sdkdir) + end + local dotnet = find_tool("dotnet", {version = true, paths = #paths > 0 and paths or nil}) if not dotnet then return nil end - local result = {program = dotnet.program, version = dotnet.version} + local bindir = path.directory(dotnet.program) + local result = {bindir = bindir, version = dotnet.version} -- get sdk list, e.g. "8.0.100 [/usr/share/dotnet/sdk]" local sdklist = try { function () return os.iorunv(dotnet.program, {"--list-sdks"}) end } @@ -54,6 +62,11 @@ function _find_dotnet_cli() end end + -- set sdkdir from bindir if not found from sdk list + if not result.sdkdir then + result.sdkdir = sdkdir or path.directory(bindir) + end + -- get runtime list, e.g. "Microsoft.NETCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]" local runtimelist = try { function () return os.iorunv(dotnet.program, {"--list-runtimes"}) end } if runtimelist then @@ -129,14 +142,14 @@ function main(sdkdir, opt) opt = opt or {} -- attempt to load cache first - local key = "detect.sdks.find_dotnet." .. (sdkdir or "") + local key = "detect.sdks.find_dotnet" local cacheinfo = detectcache:get(key) or {} - if not opt.force and cacheinfo.dotnet then + if not opt.force and cacheinfo.dotnet and cacheinfo.dotnet.sdkdir and os.isdir(cacheinfo.dotnet.sdkdir) then return cacheinfo.dotnet end -- find dotnet cli sdk - local dotnet = _find_dotnet_cli() + local dotnet = _find_dotnet_cli(sdkdir or config.get("dotnet") or global.get("dotnet")) -- find .NET Framework SDK on Windows if is_host("windows") then @@ -151,6 +164,7 @@ function main(sdkdir, opt) end if dotnet then + -- save to config if dotnet.sdkdir then config.set("dotnet", dotnet.sdkdir, {force = true, readonly = true}) @@ -169,6 +183,7 @@ function main(sdkdir, opt) end end else + -- trace if opt.verbose or option.get("verbose") then cprint("checking for .NET SDK directory ... ${color.nothing}${text.nothing}") |
