diff options
| author | ruki <[email protected]> | 2026-03-17 22:43:06 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-03-17 22:43:06 +0800 |
| commit | 42dec9486bb56c2f08db0c30f6b2829e1b02a1a7 (patch) | |
| tree | 7fcea3a58a9b9b0495747c255a209a81dae4bc86 /tests/projects/csharp | |
| parent | 1c5607aa0da666cd244af2cab5fc7280e30742f1 (diff) | |
| parent | 2134b93d3f87d8f4ea63e0c49b2075ba056995d9 (diff) | |
Merge pull request #7398 from xmake-io/csharp
Add csharp support
Diffstat (limited to 'tests/projects/csharp')
28 files changed, 240 insertions, 0 deletions
diff --git a/tests/projects/csharp/console/.gitignore b/tests/projects/csharp/console/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/console/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/console/src/Program.cs b/tests/projects/csharp/console/src/Program.cs new file mode 100644 index 000000000..c7d5272d9 --- /dev/null +++ b/tests/projects/csharp/console/src/Program.cs @@ -0,0 +1,2 @@ +Console.WriteLine("hello xmake!"); + diff --git a/tests/projects/csharp/console/test.lua b/tests/projects/csharp/console/test.lua new file mode 100644 index 000000000..d909316b7 --- /dev/null +++ b/tests/projects/csharp/console/test.lua @@ -0,0 +1,13 @@ +import("detect.sdks.find_dotnet") + +function test_build(t) + if is_subhost("msys") then + return t:skip("csharp not supported on msys") + end + local dotnet = find_dotnet() + if dotnet and dotnet.sdkver then + t:build() + else + return t:skip("dotnet sdk not found") + end +end diff --git a/tests/projects/csharp/console/xmake.lua b/tests/projects/csharp/console/xmake.lua new file mode 100644 index 000000000..3288c96a8 --- /dev/null +++ b/tests/projects/csharp/console/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("test") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs") diff --git a/tests/projects/csharp/console_with_runtime_json/.gitignore b/tests/projects/csharp/console_with_runtime_json/.gitignore new file mode 100644 index 000000000..53e577525 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/.gitignore @@ -0,0 +1,7 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ + diff --git a/tests/projects/csharp/console_with_runtime_json/src/Program.cs b/tests/projects/csharp/console_with_runtime_json/src/Program.cs new file mode 100644 index 000000000..fd836a339 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/src/Program.cs @@ -0,0 +1,15 @@ +using System.Text.Json; + +var runtimeFile = Path.Combine(Directory.GetCurrentDirectory(), "runtime.json"); +if (!File.Exists(runtimeFile)) { + Console.WriteLine("runtime.json missing"); + return; +} + +var json = File.ReadAllText(runtimeFile); +using var doc = JsonDocument.Parse(json); +var runtime = doc.RootElement.TryGetProperty("runtime", out var value) + ? value.GetString() + : "unknown"; + +Console.WriteLine($"runtime={runtime}"); diff --git a/tests/projects/csharp/console_with_runtime_json/src/runtime.json b/tests/projects/csharp/console_with_runtime_json/src/runtime.json new file mode 100644 index 000000000..15bec810d --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/src/runtime.json @@ -0,0 +1,7 @@ +{ + "runtime": "xmake", + "featureFlags": { + "sample": true + } +} + diff --git a/tests/projects/csharp/console_with_runtime_json/test.lua b/tests/projects/csharp/console_with_runtime_json/test.lua new file mode 100644 index 000000000..d909316b7 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/test.lua @@ -0,0 +1,13 @@ +import("detect.sdks.find_dotnet") + +function test_build(t) + if is_subhost("msys") then + return t:skip("csharp not supported on msys") + end + local dotnet = find_dotnet() + if dotnet and dotnet.sdkver then + t:build() + else + return t:skip("dotnet sdk not found") + end +end diff --git a/tests/projects/csharp/console_with_runtime_json/xmake.lua b/tests/projects/csharp/console_with_runtime_json/xmake.lua new file mode 100644 index 000000000..979f74307 --- /dev/null +++ b/tests/projects/csharp/console_with_runtime_json/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("app") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs") + set_rundir("src") diff --git a/tests/projects/csharp/multiple_library/.gitignore b/tests/projects/csharp/multiple_library/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/multiple_library/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs b/tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs new file mode 100644 index 000000000..a10ed6d73 --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs @@ -0,0 +1,7 @@ +namespace LibAlpha; + +public static class Alpha { + public static string Message() { + return "alpha"; + } +} diff --git a/tests/projects/csharp/multiple_library/src/libbeta/Beta.cs b/tests/projects/csharp/multiple_library/src/libbeta/Beta.cs new file mode 100644 index 000000000..c96944dc5 --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/libbeta/Beta.cs @@ -0,0 +1,9 @@ +using LibAlpha; + +namespace LibBeta; + +public static class Beta { + public static string Message() { + return Alpha.Message() + "+beta"; + } +} diff --git a/tests/projects/csharp/multiple_library/src/sample/Program.cs b/tests/projects/csharp/multiple_library/src/sample/Program.cs new file mode 100644 index 000000000..2292a8af9 --- /dev/null +++ b/tests/projects/csharp/multiple_library/src/sample/Program.cs @@ -0,0 +1,3 @@ +using LibBeta; + +Console.WriteLine(Beta.Message());
\ No newline at end of file diff --git a/tests/projects/csharp/multiple_library/test.lua b/tests/projects/csharp/multiple_library/test.lua new file mode 100644 index 000000000..d909316b7 --- /dev/null +++ b/tests/projects/csharp/multiple_library/test.lua @@ -0,0 +1,13 @@ +import("detect.sdks.find_dotnet") + +function test_build(t) + if is_subhost("msys") then + return t:skip("csharp not supported on msys") + end + local dotnet = find_dotnet() + if dotnet and dotnet.sdkver then + t:build() + else + return t:skip("dotnet sdk not found") + end +end diff --git a/tests/projects/csharp/multiple_library/xmake.lua b/tests/projects/csharp/multiple_library/xmake.lua new file mode 100644 index 000000000..db3f65811 --- /dev/null +++ b/tests/projects/csharp/multiple_library/xmake.lua @@ -0,0 +1,18 @@ +add_rules("mode.debug", "mode.release") + +target("libalpha") + set_kind("shared") + add_rules("csharp") + add_files("src/libalpha/*.cs") + +target("libbeta") + set_kind("shared") + add_rules("csharp") + add_deps("libalpha") + add_files("src/libbeta/*.cs") + +target("sample") + set_kind("binary") + add_rules("csharp") + add_deps("libbeta") + add_files("src/sample/*.cs") diff --git a/tests/projects/csharp/nuget_package/.gitignore b/tests/projects/csharp/nuget_package/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/nuget_package/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/nuget_package/src/Program.cs b/tests/projects/csharp/nuget_package/src/Program.cs new file mode 100644 index 000000000..518015e2a --- /dev/null +++ b/tests/projects/csharp/nuget_package/src/Program.cs @@ -0,0 +1,4 @@ +using Humanizer; + +Console.WriteLine(1234.ToWords()); + diff --git a/tests/projects/csharp/nuget_package/test.lua b/tests/projects/csharp/nuget_package/test.lua new file mode 100644 index 000000000..d909316b7 --- /dev/null +++ b/tests/projects/csharp/nuget_package/test.lua @@ -0,0 +1,13 @@ +import("detect.sdks.find_dotnet") + +function test_build(t) + if is_subhost("msys") then + return t:skip("csharp not supported on msys") + end + local dotnet = find_dotnet() + if dotnet and dotnet.sdkver then + t:build() + else + return t:skip("dotnet sdk not found") + end +end diff --git a/tests/projects/csharp/nuget_package/xmake.lua b/tests/projects/csharp/nuget_package/xmake.lua new file mode 100644 index 000000000..6ec474822 --- /dev/null +++ b/tests/projects/csharp/nuget_package/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.debug", "mode.release") +add_requires("nuget::Humanizer.Core 2.14.1") + +target("app") + set_kind("binary") + add_rules("csharp") + add_files("src/Program.cs") + add_packages("nuget::Humanizer.Core") diff --git a/tests/projects/csharp/shared_library/.gitignore b/tests/projects/csharp/shared_library/.gitignore new file mode 100644 index 000000000..6b8d3af38 --- /dev/null +++ b/tests/projects/csharp/shared_library/.gitignore @@ -0,0 +1,6 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ diff --git a/tests/projects/csharp/shared_library/src/app/Program.cs b/tests/projects/csharp/shared_library/src/app/Program.cs new file mode 100644 index 000000000..3cf7cb84a --- /dev/null +++ b/tests/projects/csharp/shared_library/src/app/Program.cs @@ -0,0 +1,4 @@ +using MyLib; + +Console.WriteLine(Greeter.Greet("xmake")); + diff --git a/tests/projects/csharp/shared_library/src/lib/Greeter.cs b/tests/projects/csharp/shared_library/src/lib/Greeter.cs new file mode 100644 index 000000000..cf895138a --- /dev/null +++ b/tests/projects/csharp/shared_library/src/lib/Greeter.cs @@ -0,0 +1,7 @@ +namespace MyLib; + +public static class Greeter { + public static string Greet(string name) { + return $"hello {name}!"; + } +} diff --git a/tests/projects/csharp/shared_library/test.lua b/tests/projects/csharp/shared_library/test.lua new file mode 100644 index 000000000..d909316b7 --- /dev/null +++ b/tests/projects/csharp/shared_library/test.lua @@ -0,0 +1,13 @@ +import("detect.sdks.find_dotnet") + +function test_build(t) + if is_subhost("msys") then + return t:skip("csharp not supported on msys") + end + local dotnet = find_dotnet() + if dotnet and dotnet.sdkver then + t:build() + else + return t:skip("dotnet sdk not found") + end +end diff --git a/tests/projects/csharp/shared_library/xmake.lua b/tests/projects/csharp/shared_library/xmake.lua new file mode 100644 index 000000000..f8549444e --- /dev/null +++ b/tests/projects/csharp/shared_library/xmake.lua @@ -0,0 +1,12 @@ +add_rules("mode.debug", "mode.release") + +target("mylib") + set_kind("shared") + add_rules("csharp") + add_files("src/lib/*.cs") + +target("app") + set_kind("binary") + add_rules("csharp") + add_deps("mylib") + add_files("src/app/*.cs") diff --git a/tests/projects/csharp/web_project/.gitignore b/tests/projects/csharp/web_project/.gitignore new file mode 100644 index 000000000..53e577525 --- /dev/null +++ b/tests/projects/csharp/web_project/.gitignore @@ -0,0 +1,7 @@ +.xmake/ +build/ +bin/ +obj/ +vsxmake*/ +.vs/ + diff --git a/tests/projects/csharp/web_project/src/Program.cs b/tests/projects/csharp/web_project/src/Program.cs new file mode 100644 index 000000000..7e432aaf0 --- /dev/null +++ b/tests/projects/csharp/web_project/src/Program.cs @@ -0,0 +1,8 @@ +var builder = WebApplication.CreateBuilder(args); +var app = builder.Build(); + +app.MapGet("/", () => "hello web xmake!"); +app.MapGet("/health", () => Results.Ok(new { status = "ok" })); + +app.Run(); + diff --git a/tests/projects/csharp/web_project/test.lua b/tests/projects/csharp/web_project/test.lua new file mode 100644 index 000000000..d909316b7 --- /dev/null +++ b/tests/projects/csharp/web_project/test.lua @@ -0,0 +1,13 @@ +import("detect.sdks.find_dotnet") + +function test_build(t) + if is_subhost("msys") then + return t:skip("csharp not supported on msys") + end + local dotnet = find_dotnet() + if dotnet and dotnet.sdkver then + t:build() + else + return t:skip("dotnet sdk not found") + end +end diff --git a/tests/projects/csharp/web_project/xmake.lua b/tests/projects/csharp/web_project/xmake.lua new file mode 100644 index 000000000..56bcad79c --- /dev/null +++ b/tests/projects/csharp/web_project/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") + +target("webapp") + set_kind("binary") + add_rules("csharp") + add_values("csharp.sdk", "Microsoft.NET.Sdk.Web") + add_files("src/Program.cs") |
