It seems that probably MSBuild cached build targets terribly wrong, but after Windows restart all kinds of hooking including the one from this post which finally solved my problem started to work as expected.
Also, for all who are doing automatic build stuff it might be interesting to note that web deplopy related stuff can be moved from the main {Project Name}.csproj
file to the corresponding {Project Name}.wpp.targets
file which I consider as a more elegant way of configuring build options especially if you don't want to include them in the TFS or want to customize build befaviour for different publish targets.
So, this is my final .wpp.targets
file which works for me now:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<IgnoreDeployManagedRuntimeVersion>True</IgnoreDeployManagedRuntimeVersion>
<ExcludeFilesFromDeployment>Web.config</ExcludeFilesFromDeployment>
<SkipExtraFilesOnServer>True</SkipExtraFilesOnServer>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
</PropertyGroup>
<Target Name="BeforeBuild">
<Message Text="Building our Web Deploy package using Tools path $(VSToolsPath)" Importance="high"/>
</Target>
<!-- More verbose way of doing the same as with BeforeTargets -->
<!-- <PropertyGroup>-->
<!-- <CopyAllFilesToSingleFolderForPackageDependsOn>-->
<!-- CollectJsMinFiles;-->
<!-- $(CopyAllFilesToSingleFolderForPackageDependsOn);-->
<!-- </CopyAllFilesToSingleFolderForPackageDependsOn>-->
<!-- <CopyAllFilesToSingleFolderForMsdeployDependsOn>-->
<!-- CollectJsMinFiles;-->
<!-- $(CopyAllFilesToSingleFolderForMsdeployDependsOn);-->
<!-- </CopyAllFilesToSingleFolderForMsdeployDependsOn>-->
<!-- </PropertyGroup>-->
<!-- <Target Name="CollectJsMinFiles"> -->
<Target Name="CollectJsMinFiles" BeforeTargets="CopyAllFilesToSingleFolderForPackage;CopyAllFilesToSingleFolderForMsdeploy">
<Message Text="Collecting min JS files in CollectJsMinFiles" Importance="high"/>
<ItemGroup>
<JsMinFiles Include="**\*.min.js" />
<FilesForPackagingFromProject Include="%(JsMinFiles.Identity)">
<DestinationRelativePath>%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>