diff options
| author | Arthur Vasseur <[email protected]> | 2026-04-15 20:21:52 +0200 |
|---|---|---|
| committer | Arthur Vasseur <[email protected]> | 2026-04-16 14:33:56 +0200 |
| commit | a0fd08ab27edb0bf518a409b8aae9ce6f1aaf51b (patch) | |
| tree | 8667148350438173eba3959e5da389fa4afbc221 /tests/plugins/project/test.lua | |
| parent | fabb25749492d6b26887da0217486bfbfd104bdd (diff) | |
vsxmake: generate .csproj for C# targets
Detect targets whose source kinds are entirely "cs" and emit a .csproj
Diffstat (limited to 'tests/plugins/project/test.lua')
| -rw-r--r-- | tests/plugins/project/test.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/plugins/project/test.lua b/tests/plugins/project/test.lua index 168e71f1a..7de8835f1 100644 --- a/tests/plugins/project/test.lua +++ b/tests/plugins/project/test.lua @@ -2,6 +2,7 @@ import("core.project.config") import("core.platform.platform") import("core.tool.toolchain") import("lib.detect.find_tool") +import("detect.sdks.find_dotnet") function test_vsxmake(t) @@ -56,6 +57,58 @@ function test_vsxmake(t) os.tryrm(tempdir) end +function test_vsxmake_csharp(t) + + if not is_subhost("windows") then + return t:skip("wrong host platform") + end + + local dotnet = find_dotnet() + if not dotnet or not dotnet.sdkver then + return t:skip("dotnet sdk not found") + end + + local projname = "testcsproj" + local tempdir = os.tmpfile() + os.mkdir(tempdir) + os.cd(tempdir) + + -- create a C# console project using xmake create + os.vrunv("xmake", {"create", "-l", "csharp", "console", projname}) + os.cd(projname) + + -- create sln & csproj + local arch = os.getenv("platform") or "x64" + local vs = config.get("vs") + local vstype = "vsxmake" .. vs + os.execv("xmake", {"project", "-k", vstype, "-a", arch}) + os.cd(vstype) + + -- verify a .csproj was generated (not .vcxproj) + local csproj_path = path.join(projname, projname .. ".csproj") + assert(os.isfile(csproj_path), "expected .csproj to be generated at " .. csproj_path) + assert(not os.isfile(path.join(projname, projname .. ".vcxproj")), + "unexpected .vcxproj generated for C# target") + + -- verify .sln references the .csproj with the C# project type GUID + local sln_text = io.readfile(projname .. ".sln") + assert(sln_text:find("FAE04EC0-301F-11D3-BF4B-00C04F79EFBC", 1, true), + "C# project type GUID missing from .sln") + assert(sln_text:find(projname .. ".csproj", 1, true), + ".csproj reference missing from .sln") + + -- verify the .csproj imports Xmake.CSharp.targets and has a Compile item + local csproj_text = io.readfile(csproj_path) + assert(csproj_text:find("Xmake.CSharp.targets", 1, true), + "Xmake.CSharp.targets import missing from .csproj") + assert(csproj_text:find("<Compile Include=", 1, true), + "<Compile> item missing from .csproj") + + -- clean up + os.cd(os.scriptdir()) + os.tryrm(tempdir) +end + function test_compile_commands(t) local projname = "testproj" local tempdir = os.tmpfile() |
