Can not hook into CopyAllFilesToSingleFolderForMsdeployDependsOn during MSBuild on my Web Application project

2.3k views Asked by At

My main goal is to add minified JS scripts to the deployment package of my ASP.NET web application using cmd.

Also my question may seem duplicate to this topic and even this and this, it's not the case. My problem is that I've tried hooking into CopyAllFilesToSingleFolderForPackageDependsOn, CopyAllFilesToSingleFolderForMsdeployDependsOn and even PipelineCollectFilesPhaseDependsOn with no luck. I used <Message Text="Inside of CustomCollectFiles" Importance="high"/> inside my custom Target as Sayed Ibrahim Hashimi proposed in his answer and /v:diag switch of msbuild.exe to verify this fact. I have no ideas how to fix it: tried to place corresponding XML snippet with different modifications from the questions above into .csproj file directly and also into a separate file .wpp.targets which is used to customize packaging.

My dev environment includes VS2010 and VS2013, I've installed Web Deployment 3.5 via Web PI, Web Deployment Tools, Windows Azure SDK. My system PATH environment var includes c:\Windows\Microsoft.NET\Framework64\v4.0.30319\;c:\Program Files\IIS\Microsoft Web Deploy V3 to be able to run MSBuild and MSDeploy from cmd. When I look into the MSBuild log I see this:

CopyAllFilesToSingleFolderForMsdeployDependsOn = 
  ;
  ;

CopyAllFilesToSingleFolderForPackageDependsOn = 
  ;

  ;
;

some stuff goes here

PipelineDeployPhaseDependsOn = 
  ;
  Package;

So my question is where to find the source of my misfunctioning packaging pipeline? What additional kind of diagnostics I missed out?

1

There are 1 answers

0
IPSUS On BEST ANSWER

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>