Rami's solution works, but it requires another "Build" pass. While this won't actually recompile, it will still cause unnecessary delay if your solution is large.
You can't trigger the web publish via DeployOnBuild
as that's automatically disabled when building from Visual Studio.
You can, however, trigger the process as part of the same MSBuild invocation via some MSBuild trickery:
<!-- In Directory.Build.props or the csproj (before the web targets import) -->
<PropertyGroup>
<PublishProfile>Local</PublishProfile>
</PropertyGroup>
And also:
<!-- After the above, or in ProjectName.wpp.targets -->
<PropertyGroup>
<AutoPublish Condition="'$(AutoPublish)' == '' and '$(Configuration)' == 'Debug' and '$(BuildingInsideVisualStudio)' == 'true' and '$(PublishProfile)' != ''">true</AutoPublish>
<AutoPublishDependsOn Condition="'$(AutoPublish)' == 'true'">
$(AutoPublishDependsOn);
WebPublish
</AutoPublishDependsOn>
</PropertyGroup>
<Target Name="AutoPublish" AfterTargets="Build" DependsOnTargets="$(AutoPublishDependsOn)">
</Target>
If you're finding that your publish project isn't being built when you make content changes, add the following:
<!-- csproj ONLY, won't work elsewhere -->
<PropertyGroup>
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>