-
-
Notifications
You must be signed in to change notification settings - Fork 37
Description
Details
The guide for automating Husky installs has users add a per-project Target to ensure the tool is restored and installed:
<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(HUSKY)' != 0">
<Exec Command="dotnet tool restore" StandardOutputImportance="Low" StandardErrorImportance="High"/>
<Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High"
WorkingDirectory="../../" /> <!--Update this to the relative path to your project root dir -->
</Target>This means that if multiple projects add this target, the same logic will be run multiple times over the course of a build. In general, for actions that should happen once over a logical build, we encourage a couple patterns:
Use Directory.Solution.targets
A Directory.Solution.targets file is an MSBuild logic file that is loaded implicitly by a solution when the solution is used for an MSbuild command (e.g. dotnet build mysln.sln). Since the solution is the top-level orchestrator, if you added the same husky target to this file, it would only execute once, shortening your overall build cycles.
Improve the incrementality of the Target
Right now your Target executes on every build (that doesn't explicitly add -no-restore. This means that husky will drastically impact the performance of even very-incremental builds - slowing down the developer's inner loop, impacting VS builds, and so on. I strongly suggest that
- some kind of marker file be created - either by
husky installitself, or by the target that you're asking users to copy - that marker file be added to the
FileWritesItem group, so thatdotnet cleanwill remove it - that marker file be added as an
Outputto thehuskyTarget - the tool configuration for the project be added as an
Inputto thehuskyTarget
Doing this will allow MSBuild to see if your target has been run before or not, and only re-run it when
- the input files change
- the output file is out of date with the input (or doesn't exist at all)