Skip to content

feat: add C# support for xmake#7338

Closed
JassJam wants to merge 13 commits intoxmake-io:devfrom
JassJam:feat/csharp-lang
Closed

feat: add C# support for xmake#7338
JassJam wants to merge 13 commits intoxmake-io:devfrom
JassJam:feat/csharp-lang

Conversation

@JassJam
Copy link
Contributor

@JassJam JassJam commented Feb 23, 2026

Note

  • This is just an initial implementation, stitched together from my old private projects, and use of my modified version of xmake, any feedback and requests are open, please feel free to test it out!
  • This was only tested on windows platform for now.

Inspiration

Motivation

Normally one could achieve it directly by just using rules + calling dotnet directly, but this was not enough for my greedy self :3, i wanted intellisense support without creating another sln file just for C#, unifying both C++ and C# into one sln file for ease of use and debugging!

Prerequisites

  • First and foremost, dotnet tool must be installed in order to use C# projects.
  • C# projects require .csproj file (contains packages, framework settings, SDK, etc...), so .csproj must be part of the source set, and should not be auto generated by xmake, to not over-complicate it (just use dotnet new ...) .

How it works

  • Adds the csharp rule with add_rules.
  • Explicitly registers .csproj and .cs files with add_files.
  • Supports cross platform (windows, linux, macos) with cross architecture (x64, x86, arm64, arm, riscv64).

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @JassJam, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly expands xmake's capabilities by adding native support for C# projects. It allows developers to seamlessly integrate C# applications and libraries into their xmake-based build systems, providing a unified build experience across C++ and C# projects. The changes include core build rules for C#, integration with the dotnet tool, and crucial updates to the VSXmake plugin to ensure proper Visual Studio project generation, enhancing developer workflow and enabling better cross-language project management.

Highlights

  • C# Language Support: Introduced initial support for building C# projects within xmake, allowing users to define and manage C# applications and libraries using xmake.lua.
  • Dotnet CLI Integration: Integrated the dotnet command-line interface for building, publishing, and cleaning C# projects, supporting various build configurations (Debug/Release) and runtime identifiers.
  • VSXmake Plugin Enhancements: Updated the VSXmake plugin to correctly generate Visual Studio solution (.sln) and project (.vcxproj) files for C# targets, including proper project type GUIDs and platform configurations (e.g., 'Any CPU').
  • Comprehensive Test Cases: Added a suite of test projects demonstrating various C# scenarios, including console applications, projects with local libraries, NuGet package references, multiple library dependencies, and web projects.
  • Cross-Platform and Cross-Architecture Support: Enabled C# projects to be built for different platforms (Windows, Linux, macOS) and architectures (x64, x86, arm64, arm, riscv64) by mapping xmake's architecture definitions to .NET runtime identifiers.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • tests/projects/csharp/console/.gitignore
    • Added standard .NET build output directories to the gitignore file.
  • tests/projects/csharp/console/src/Program.cs
    • Added a basic 'hello xmake!' C# console application source file.
  • tests/projects/csharp/console/src/test.csproj
    • Added a .NET 8.0 console application project file.
  • tests/projects/csharp/console/test.lua
    • Added a Lua test script to verify the build process for the C# console application.
  • tests/projects/csharp/console/xmake.lua
    • Added xmake configuration for the C# console application, defining it as a binary target with the 'csharp' rule.
  • tests/projects/csharp/console_with_runtime_json/.gitignore
    • Added standard .NET build output directories to the gitignore file.
  • tests/projects/csharp/console_with_runtime_json/src/Program.cs
    • Added a C# program that reads and displays a 'runtime.json' file.
  • tests/projects/csharp/console_with_runtime_json/src/app.csproj
    • Added a .NET 8.0 console project configured to copy 'runtime.json' to the output directory.
  • tests/projects/csharp/console_with_runtime_json/src/runtime.json
    • Added a sample 'runtime.json' file for testing purposes.
  • tests/projects/csharp/console_with_runtime_json/test.lua
    • Added a Lua test script for the C# console application that uses 'runtime.json'.
  • tests/projects/csharp/console_with_runtime_json/xmake.lua
    • Added xmake configuration for the C# console application with 'runtime.json' support.
  • tests/projects/csharp/exe_with_library/.gitignore
    • Added standard .NET build output directories to the gitignore file.
  • tests/projects/csharp/exe_with_library/src/app/Program.cs
    • Added a C# program that utilizes a local library.
  • tests/projects/csharp/exe_with_library/src/app/app.csproj
    • Added a C# console project that references a local library project.
  • tests/projects/csharp/exe_with_library/src/lib/Greeter.cs
    • Added a C# class for a local library providing a greeting function.
  • tests/projects/csharp/exe_with_library/src/lib/lib.csproj
    • Added a C# library project file.
  • tests/projects/csharp/exe_with_library/test.lua
    • Added a Lua test script for the C# application with a local library dependency.
  • tests/projects/csharp/exe_with_library/xmake.lua
    • Added xmake configuration for a C# application and its dependent local library.
  • tests/projects/csharp/exe_with_package/.gitignore
    • Added standard .NET build output directories to the gitignore file.
  • tests/projects/csharp/exe_with_package/src/Program.cs
    • Added a C# program that uses the 'Humanizer' NuGet package.
  • tests/projects/csharp/exe_with_package/src/app.csproj
    • Added a C# console project that includes a NuGet package reference.
  • tests/projects/csharp/exe_with_package/test.lua
    • Added a Lua test script for the C# application with a NuGet package dependency.
  • tests/projects/csharp/exe_with_package/xmake.lua
    • Added xmake configuration for a C# application with a NuGet package dependency.
  • tests/projects/csharp/multiple_library/.gitignore
    • Added standard .NET build output directories to the gitignore file.
  • tests/projects/csharp/multiple_library/src/libalpha/Alpha.cs
    • Added a C# class for the 'LibAlpha' library.
  • tests/projects/csharp/multiple_library/src/libalpha/libalpha.csproj
    • Added a C# project file for 'LibAlpha'.
  • tests/projects/csharp/multiple_library/src/libbeta/Beta.cs
    • Added a C# class for the 'LibBeta' library, which depends on 'LibAlpha'.
  • tests/projects/csharp/multiple_library/src/libbeta/libbeta.csproj
    • Added a C# project file for 'LibBeta', referencing 'LibAlpha'.
  • tests/projects/csharp/multiple_library/src/sample/Program.cs
    • Added a C# program that uses the 'LibBeta' library.
  • tests/projects/csharp/multiple_library/src/sample/sample.csproj
    • Added a C# console project that references 'LibBeta'.
  • tests/projects/csharp/multiple_library/test.lua
    • Added a Lua test script for the C# application with multiple library dependencies.
  • tests/projects/csharp/multiple_library/xmake.lua
    • Added xmake configuration for a C# application with a chain of library dependencies.
  • tests/projects/csharp/web_project/.gitignore
    • Added standard .NET build output directories to the gitignore file.
  • tests/projects/csharp/web_project/src/Program.cs
    • Added a basic C# web application source file using ASP.NET Core Minimal APIs.
  • tests/projects/csharp/web_project/src/webapp.csproj
    • Added a .NET 8.0 web application project file.
  • tests/projects/csharp/web_project/test.lua
    • Added a Lua test script for the C# web application.
  • tests/projects/csharp/web_project/xmake.lua
    • Added xmake configuration for the C# web application.
  • xmake/languages/csharp/load.lua
    • Added API definitions for C# compiler and linker flags, and link directories.
  • xmake/languages/csharp/xmake.lua
    • Defined the 'csharp' language within xmake, specifying source kinds, flags, target kinds, and menu configurations.
  • xmake/plugins/project/vsxmake/getinfo.lua
    • Added helper functions to detect C# targets and determine appropriate Visual Studio project platforms.
    • Modified target information generation to handle C# specific project types and platforms.
    • Updated subsystem detection to exclude C# targets.
  • xmake/plugins/project/vsxmake/vsxmake.lua
    • Added filtering for C# source files (.cs) and project files (.csproj) during VSXmake generation.
  • xmake/rules/csharp/xmake.lua
    • Added the core 'csharp.build' rule to handle C# project compilation, publishing, cleaning, and installation using the 'dotnet' CLI.
    • Implemented logic to find and cache the .csproj file for each C# target.
    • Included functions to map xmake build modes and architectures to .NET configurations and runtime identifiers.
  • xmake/scripts/vsxmake/vsproj/templates/sln/ProjConfig(target,mode,arch)
    • Modified the solution configuration template to use the dynamically determined sln_project_platform for C# projects.
  • xmake/scripts/vsxmake/vsproj/templates/sln/Project(target)
    • Modified the solution project template to use dynamic project type GUIDs and file paths, enabling C# project recognition in Visual Studio.
  • xmake/scripts/vsxmake/vsproj/templates/vcxproj.filters/#target#.vcxproj.filters
    • Modified the project filter template to include C# source (.cs) and project (.csproj) files.
  • xmake/scripts/vsxmake/vsproj/templates/vcxproj.filters/File.cs(filecs)
    • Added a template for including C# source files in Visual Studio filter files.
  • xmake/scripts/vsxmake/vsproj/templates/vcxproj.filters/File.csproj(filecsproj)
    • Added a template for including C# project files in Visual Studio filter files.
  • xmake/scripts/vsxmake/vsproj/templates/vcxproj/#target#.vcxproj
    • Modified the project file template to include C# source (.cs) and project (.csproj) files.
  • xmake/scripts/vsxmake/vsproj/templates/vcxproj/File.cs(filecs)
    • Added a template for including C# source files in Visual Studio project files.
  • xmake/scripts/vsxmake/vsproj/templates/vcxproj/File.csproj(filecsproj)
    • Added a template for including C# project files in Visual Studio project files.
Activity
  • JassJam initiated this pull request to introduce C# support to xmake.
  • The author provided a detailed description outlining the initial implementation, its inspiration from existing issues and personal projects, and its motivation to unify C++ and C# builds with IntelliSense support.
  • The PR description highlighted prerequisites, such as the dotnet tool and the necessity of .csproj files, and explained the usage of the new csharp rule.
  • The author noted that the current implementation was primarily tested on Windows and encouraged feedback and testing from the community.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a great contribution that adds C# support to xmake, a long-requested feature. The implementation covers the build lifecycle (build, clean, install) and integrates with the Visual Studio project generator (vsxmake) to provide a seamless developer experience. The test projects are comprehensive and cover various scenarios like console apps, libraries, package dependencies, and web projects.

My review focuses on a few areas for improvement, mainly concerning the installation logic for correctness and efficiency, and some minor style issues in the test files. Overall, the core implementation is solid.

Comment on lines +245 to +250
if target:is_binary() then
local targetdir = target:targetdir()
if targetdir and os.isdir(targetdir) then
os.cp(path.join(targetdir, "**"), install_abs, {rootdir = targetdir})
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This os.cp operation for binary targets appears to be redundant. The dotnet publish command, which is executed earlier in this on_install hook, should already place all necessary files into the installation directory (install_abs). This block can likely be removed.

For better performance, consider refactoring the install logic. For binary targets, on_buildcmd already runs dotnet publish. The on_install hook could simply copy the artifacts from the build directory instead of running publish again.

@waruqi
Copy link
Member

waruqi commented Feb 23, 2026

This patch is too large, and I don't have much time to review and test it. Please split several smaller patches if possible. like this:

  • Support basic CLI build, (rules, language and tests)
  • Support vsxmake generator
  • Support vs generator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants