Customising Visual Studios Build

Previously, the way I would hook into a projects/solutions build was to edit the .csproj file to import a build file. It always annoyed me and isn’t immediately clear to people (or me after I come back to a project) how the targets are being injected.

I recently discovered that you can follow certain naming conventions to automagically get your targets imported into the build. Now, I know some people think automagic is even less transparent than explicitly defining something, however the naming is quite straightforward and obvious.

Add a targets file named; [after|before].<SolutionName>.sln.targets to the same directory as your solution file.

The after file is added after the project files and the before file is added before the project files.

This only works for solutions.
As an example

<Target Name="RunPostBuildScripts" AfterTargets="Build">
   <!-- Do Stuff Here -->
</Target>

More Info Here

2 Replies to “Customising Visual Studios Build”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s