Currently, when I run my project, it will execute my post-build commands that I have set up. However, this is only true if there was a change to the project. My ultimate goal here is to have my project run ng build each time I build it. However, what I have noticed is that if I were to change an HTML file in angular, the project does not detect any changes so it does not build again and thus it does not run my ng build command.
Is there a way to force it to always run post-build commands or maybe make it always rebuild, even if no changes are detected? Or maybe there is another way to accomplish this?
This is a .NET Core WebApp and the code to run my post build event is located inside my .csproj file
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo Building Angular App..." />
<Exec Command="cd ClientApp && ng build" />
</Target>
You could configure your post build event slightly differently in your .csproj file and set RunPostBuildEvent
to Always
as per the below:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
...
<PostBuildEvent>cd ClientApp && ng build</PostBuildEvent>
<RunPostBuildEvent>Always</RunPostBuildEvent>
</PropertyGroup>
EDIT: As I discovered after a bit more testing, the RunPostBuildEvent
does not behave as I expected it to. Therefore, a 'workaround' is to add DisableFastUpToDateCheck
as per the below:
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
<PostBuildEvent>cd ClientApp && ng build</PostBuildEvent>
</PropertyGroup>
From MSDN:
A boolean value that applies to Visual Studio only. The Visual Studio build manager uses a process called FastUpToDateCheck to determine whether a project must be rebuilt to be up to date. This process is faster than using MSBuild to determine this. Setting the
DisableFastUpToDateCheck
property totrue
lets you bypass the Visual Studio build manager and force it to use MSBuild to determine whether the project is up to date.
Clearly the downside to this is that the project will always be rebuilt, so this is not an ideal solution.