diff options
| author | ruki <[email protected]> | 2026-03-14 23:59:57 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2026-03-14 23:59:57 +0800 |
| commit | ca72dbcfd8c45f194b9770f63c91ebd00412fa39 (patch) | |
| tree | 55b8bedf7da0a11be16c0ff026db3a8bdcf844b6 | |
| parent | 894833ab4ed9cc930c60ab7b9dec889ab1a67277 (diff) | |
improve csproj rules
| -rw-r--r-- | tests/projects/csharp/existing_csproj/.gitignore | 6 | ||||
| -rw-r--r-- | tests/projects/csharp/existing_csproj/Program.cs | 2 | ||||
| -rw-r--r-- | tests/projects/csharp/existing_csproj/existing_csproj.csproj | 10 | ||||
| -rw-r--r-- | tests/projects/csharp/existing_csproj/test.lua | 10 | ||||
| -rw-r--r-- | tests/projects/csharp/existing_csproj/xmake.lua | 6 | ||||
| -rw-r--r-- | xmake/rules/csharp/build/target.lua | 16 | ||||
| -rw-r--r-- | xmake/rules/csharp/xmake.lua | 17 |
7 files changed, 15 insertions, 52 deletions
diff --git a/tests/projects/csharp/existing_csproj/.gitignore b/tests/projects/csharp/existing_csproj/.gitignore deleted file mode 100644 index 6b8d3af38..000000000 --- a/tests/projects/csharp/existing_csproj/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.xmake/ -build/ -bin/ -obj/ -vsxmake*/ -.vs/ diff --git a/tests/projects/csharp/existing_csproj/Program.cs b/tests/projects/csharp/existing_csproj/Program.cs deleted file mode 100644 index 3751555cb..000000000 --- a/tests/projects/csharp/existing_csproj/Program.cs +++ /dev/null @@ -1,2 +0,0 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); diff --git a/tests/projects/csharp/existing_csproj/existing_csproj.csproj b/tests/projects/csharp/existing_csproj/existing_csproj.csproj deleted file mode 100644 index ed9781c22..000000000 --- a/tests/projects/csharp/existing_csproj/existing_csproj.csproj +++ /dev/null @@ -1,10 +0,0 @@ -<Project Sdk="Microsoft.NET.Sdk"> - - <PropertyGroup> - <OutputType>Exe</OutputType> - <TargetFramework>net10.0</TargetFramework> - <ImplicitUsings>enable</ImplicitUsings> - <Nullable>enable</Nullable> - </PropertyGroup> - -</Project> diff --git a/tests/projects/csharp/existing_csproj/test.lua b/tests/projects/csharp/existing_csproj/test.lua deleted file mode 100644 index 5ab8adc69..000000000 --- a/tests/projects/csharp/existing_csproj/test.lua +++ /dev/null @@ -1,10 +0,0 @@ -import("lib.detect.find_tool") - -function test_build(t) - local dotnet = find_tool("dotnet") - if dotnet then - t:build() - else - return t:skip("dotnet not found") - end -end diff --git a/tests/projects/csharp/existing_csproj/xmake.lua b/tests/projects/csharp/existing_csproj/xmake.lua deleted file mode 100644 index 95e5e45d9..000000000 --- a/tests/projects/csharp/existing_csproj/xmake.lua +++ /dev/null @@ -1,6 +0,0 @@ -add_rules("mode.debug", "mode.release") - -target("test") - set_kind("binary") - add_rules("csharp") - add_files("existing_csproj.csproj") diff --git a/xmake/rules/csharp/build/target.lua b/xmake/rules/csharp/build/target.lua index 60b26602f..a193b2f8b 100644 --- a/xmake/rules/csharp/build/target.lua +++ b/xmake/rules/csharp/build/target.lua @@ -23,6 +23,20 @@ import("core.base.option") import("core.tool.compiler") import("core.project.depend") import("utils.progress") +import("modules.csharp_common", {rootdir = path.directory(os.scriptdir()), alias = "csharp_common"}) + +-- find or generate .csproj file +function _get_csprojfile(target) + local csprojfile = target:data("csharp.csproj") + if csprojfile then + return csprojfile + end + csprojfile = csharp_common.find_or_generate_csproj(target) + if csprojfile then + target:data_set("csharp.csproj", csprojfile) + end + return csprojfile +end -- build the source files function build_sourcefiles(target, sourcebatch, opt) @@ -35,7 +49,7 @@ function build_sourcefiles(target, sourcebatch, opt) local sourcekind = sourcebatch.sourcekind -- prepend .csproj file so dotnet tool can find it - local csprojfile = target:data("csharp.csproj") + local csprojfile = _get_csprojfile(target) if csprojfile then table.insert(sourcefiles, 1, csprojfile) end diff --git a/xmake/rules/csharp/xmake.lua b/xmake/rules/csharp/xmake.lua index 56772a0e8..3b6e3bf94 100644 --- a/xmake/rules/csharp/xmake.lua +++ b/xmake/rules/csharp/xmake.lua @@ -18,25 +18,8 @@ -- @file xmake.lua -- --- handle .csproj project file -rule("csharp.csproj") - set_extensions(".csproj") - on_config(function (target) - import("modules.csharp_common", {rootdir = os.scriptdir(), alias = "csharp_common"}) - - -- find .csproj from source files or generate one - local csprojfile = csharp_common.find_or_generate_csproj(target, {skip_deps = true}) - if csprojfile then - target:data_set("csharp.csproj", csprojfile) - if not target:get("filename") and not target:get("basename") then - target:set("basename", path.basename(csprojfile)) - end - end - end) - rule("csharp.build") set_sourcekinds("cs") - add_deps("csharp.csproj") on_load(function (target) -- set target extension and prefix if target:is_shared() then |
