Advanced work with Git submodules

Restore all git submodules when opening Visual Studio IDE

Before v0.12.8 you have this way. But now it can be much more easier.

Then add simple script:

#[$(moduleConari = "Conari/Conari.sln")]

#[( #[IO exists.file("$(moduleConari)")] )
    #[File scall("submodules.bat", "$(moduleConari)", 400)]
    #[File call("submodules.bat", "$(moduleConari)", 2000)]

Create in solution directory submodules.cmd:

@echo off

echo. checking submodules ...

if not exist "%1" goto restore
REM ...

goto exit


echo. We detected that you need to update git submodules.
echo. We already do it automatically. Solution of VS IDE is also should be updated after ending of this process by the action via `Sln-Opened` event. If not, please reopen .sln file again.
echo. Please wait...

git submodule update --init --recursive 2>nul || goto err_gitNotFound

goto exit


echo.  1>&2
echo. `git` was not found or something went wrong. Check your connection and env. variable `PATH`. Or get submodules manually: 1>&2
echo.     1. Use command `git submodule update --init --recursive` 1>&2
echo.     2. Or clone initially with recursive option: `git clone --recursive ...` 1>&2
echo.  1>&2


Activate action and click [Apply]

Now when user will clone your repository without --recursive or in some other case when submodule does not exist in solution directory:

  • Before first loading solution (after click on .sln) will be a black window with automatic restoring submodules.
    • 'black window' can be hidden, but it can take a long time for restoring all packages. For this case the best way to show some information.
  • And no any windows (info) when all submodules has been restored.

To support msbuild.exe, just use call submodules "Conari/Conari.sln" || goto err before build, like this:

@echo off

set msbuild=tools/msbuild

call submodules "Conari/Conari.sln" || goto err

call %msbuild% gnt.core /p:ngconfig="packages.config" /nologo /v:m /m:4
call %msbuild% "LunaRoad.sln" /verbosity:normal /l:"packages\vsSBE.CI.MSBuild\bin\CI.MSBuild.dll" /m:4 /t:Rebuild /p:Configuration=Release

goto exit


echo. Build failed. 1>&2


For more about support CI, read here