Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: How to do incremental builds with MSBuild and Git

I have created a Target and specified Inputs and Outputs described in this tutorial to build CSS files from SASS files. This generally works except when I switch to an older Git branch that have older file timestamps. In this case, I want MSBuild to execute my target to rebuild my files but MSBuild skips it because the timestamps on my Inputs are older than my Outputs so MSBuild thinks my Outputs are up to date.

How do I get Visual Studio to incrementally build my SASS files and also clean/ignore my Outputs when I switch Git branches? I want to avoid manually cleaning my compiled CSS files to force a build.

like image 762
burnt1ce Avatar asked Nov 29 '25 15:11

burnt1ce


1 Answers

You could use a Post Checkout Hook. (See also official Git docs.)

Put your clean command in the file .git/hooks/post-checkout. E.g.:

msbuild myproj.csproj /t:clean

And that command should run whenever you switch branches.

This will cause a full rebuild to occur, which is probably what you want, since it would be hard to tell what files have changed between branches.

AFAIK, all Git hooks are local to the repo, and can't be checked in. To share your hook with other users, you could save it somewhere in the repo and either tell the users to copy it manually to the correct place, or add a build event to copy it there if needed.

like image 178
Scott Weldon Avatar answered Dec 01 '25 16:12

Scott Weldon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!