3
votes

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.

1
You could have a postbuild event which stores the current git hash and/or commit date in a file, and a prebuild event which compares that file (if any) against the 'new' current git hash/date. Then do a clean build if the new one is from an earlier commit than the old one.stijn

1 Answers

3
votes

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.