Visual Studio 2022 supports native Git submodule handling - but Unity's default .csproj file generation is incompatible with it.
This repo contains a Unity Editor script that works around this issue by restructuring .csproj and .sln files so Visual Studio 2022 can load and use them properly, while remaining fully compatible with Unity and Git.
Visual Studio 2022 requires all referenced .csproj files to exist within the same Git submodule directory tree in order to work with its native Git UI and project system. However, Unity generates all .csproj files in the root of the main project, which breaks this assumption and prevents Visual Studio from seeing them correctly within submodules.
This script:
- Uses
AssetPostprocessor.OnGeneratedSlnSolutionandOnGeneratedCSProjectto hook into Unity's project file generation. - Creates hard links to Unity-generated
.csprojfiles from the directories containing their corresponding.asmdeffiles. - Rewrites the
.slnfile to use these hard links instead of the originals. - Ensures paths in the
.csprojfiles are shown relative to the submodule project file, not the Unity project root - improving Visual Studio’s Solution Explorer layout.
This keeps Unity happy, Git clean, and Visual Studio organised.
This repo contains its own .asmdef file and can be placed somewhere under /Assets.
You can use this repo as a Git submodule too!
Assemblies that are part of imported Unity packages - such as those found under Library/PackageCache/ - are ignored. The script only rewrites .csproj files generated for source assemblies in your actual Unity project and submodules.
Hard links ensure the .csproj file appears in the submodule’s directory without duplicating content. Visual Studio sees a project file within the submodule, and Unity continues to manage the original. Since hard links point to the same data, there's no risk of desync or duplication.
No. You shouldn't be tracking .csproj or .sln files in Git with Unity anyway as they are automatically generated, so this script will have no effect on anything that is tracked or used by other developers.
This script only affects how solution and project files are generated locally. It does not affect runtime behavior, game logic, or the Unity project itself.
Be sure to test your development and build pipelines after enabling this setup. Please raise an issue if anything breaks!
Do not track the .sln and .csproj files. Let Unity regenerate them on each developer machine as needed.