Include files in MSBuild that are not part of proj

2019-09-06 19:28发布

问题:

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?