0

I'm trying to create an automated build for my web application project. We use a standard CMS project and have tweaked some parts of it. Only the tweaked files are part of our project, but I want to include the full CMS in the deployment package.

So I've created a custom .targets file to define a task to include the CMS files during the build:

<Target Name="GetCMSFiles">
  <ItemGroup>
    <!-- Include the CMS files into the package -->
    <_CMSFiles Include="..\packages\CMSFiles\**\*" />

    <FilesForPackagingFromProject  Include="%(_CMSFiles.Identity)">
      <DestinationRelativePath>
        %(RecursiveDir)%(Filename)%(Extension)
      </DestinationRelativePath>
    </FilesForPackagingFromProject>
  </ItemGroup>
</Target>

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
  <!-- VS2010 -->
  <CopyAllFilesToSingleFolderForPackageDependsOn>
    GetCMSFiles;
    $(CopyAllFilesToSingleFolderForPackageDependsOn);
  </CopyAllFilesToSingleFolderForPackageDependsOn>
  <!-- VS2012 -->
  <CopyAllFilesToSingleFolderForMsdeployDependsOn>
    GetCMSFiles;
    $(CopyAllFilesToSingleFolderForMsdeployDependsOn);
  </CopyAllFilesToSingleFolderForMsdeployDependsOn>
</PropertyGroup> 

This works fine, but the problem is that the files from our project do not get copied to the deployment folder. So in other words, it does not overwrite the files that already exist after I copied them with the GetCMSFiles task.

The way I see it there are two options:

  1. Force the CopyAllFilesToSingleFolder to overwrite any existing files in the deployment folder.

  2. Have a condition in the GetCMSFiles task to only include files that don't already exist in the project.

But I'm not sure whether this is possible and how to achieve this. Any ideas?

Tom van Enckevort
  • 4,170
  • 1
  • 25
  • 40
  • I'm not sure how familiar you are with MSBuild, but the code you shared doesn't make much sense. I will translate it in c# to `class MSBuild { void GetCMSFiles() { .. } List CopyAllFilesToSingleFolderForPackageDependsOn = new List().Add("GetCMSFiles").AddRange(CopyAllFilesToSingleFolderForPackageDependsOn ); }` So from your example it is not understandable where and how anything is copied, you are just showing definitions. – MikeR Jun 21 '13 at 15:30
  • It's not C#, but a custom `targets` file used by MSBuild to create the deployment package. See [here](http://blogs.msdn.com/b/webdev/archive/2010/02/09/how-to-extend-target-file-to-include-registry-settings-for-web-project-package.aspx) for more details. – Tom van Enckevort Jun 21 '13 at 15:44
  • I tried to translate your MSBuild code to C# to show you that it makes nothing except defining variables. So from your example I can't understand where your problem is. Because `CopyAllFilesToSingleFolderForMsdeployDependsOn` is no method, it is a variable. – MikeR Jun 21 '13 at 16:22
  • OK, not sure if I quite understand it, because when I run the build it does copy the files from the directory I specified. So it is getting the files in `GetCMSFiles`. – Tom van Enckevort Jun 21 '13 at 18:00
  • 1
    Ok, I checked the `FilesForPackagingFromProject` and it seems that it is a predefined ItemList from MSBuild, which is used for copying the files in internal build steps, that's why it's working.´You could add the other files to the `FilesForPackagingFromProject` ItemGroup or you can make a ItemGroup (list of variables) and call a copy task: `` to copy the files to the folder you want. – MikeR Jun 24 '13 at 06:27
  • Thanks for the suggestion to use a Copy task. That actually led me to the solution! If you wouldn't mind adding it as an answer, so I can mark it as answered. – Tom van Enckevort Jun 24 '13 at 09:22
  • @TomvanEnckevort I have a similar problem, could you post how you solved it? – Mike J Oct 09 '15 at 04:11
  • @MikeJ Sorry, this was over two years ago, I don't recall exactly what I did, nor do I have access anymore to the project I used this for. – Tom van Enckevort Oct 09 '15 at 08:09
  • @TomvanEnckevort thank you for replying. I think I figured out a solution. I'm adding a <_CMSFiles Remove="" /> after the include that removes files that our project is overriding. This appears to be working. – Mike J Oct 09 '15 at 12:44

0 Answers0