Pouki
Pouki

Reputation: 1664

MSBuild copy task and condition name from file with wildcards

I have a FilesToExclude2.txt file which contains all excludes like this :

*.settings
*#*
*.vbproj*
*.csproj*
*\Errors\*
*\Errors
*\_vti_*\*
*\_vti_*
*\CVS\*

In my tasks file, there is a copy task

  <Target Name="CustomModuleCopy">
    <ItemGroup>
      <ModuleFiles Include="$(SolutionModuleName)\$(ProjectModuleName)\**\*.*" />
      <FileToExclude Include="$(BasePath)\$(SolutionModuleName)\FilesToExclude2.txt" />
    </ItemGroup>
    <ReadLinesFromFile File="@(FileToExclude)">
      <Output TaskParameter="Lines" ItemName="FileContents" />
    </ReadLinesFromFile>

    <Copy SourceFiles="@(ModuleFiles)" DestinationFiles="@(ModuleFiles->'$(DestFolder)\$(ProjectModuleName)\%(RecursiveDir)%(Filename)%(Extension)')" Condition="'%(ModuleFiles.Identity)' != @(FileContents)" ContinueOnError="false" />

    <!--CallTarget Targets="RemoveCustomModuleConfigFiles" /-->
  </Target>

Without the "condition" attribute on the copy task, everything's works fine, but I do not know how to implement the condition with wildcard and if it is possible

Any kind of help would be greatly appreciated :) this is freaking me out for few hours...

Upvotes: 1

Views: 7626

Answers (2)

Pouki
Pouki

Reputation: 1664

the following code

<Target Name="CustomModuleCopy">
  <ItemGroup>
      <FileToExclude Include="$(BasePath)\$(SolutionModuleName)\FilesToExclude.txt" />
  </ItemGroup>
  <ReadLinesFromFile File="@(FileToExclude)">
    <Output TaskParameter="Lines" ItemName="FileContents" />
  </ReadLinesFromFile>
  <ItemGroup>
    <ModuleFiles Include="$(SolutionModuleName)\$(ProjectModuleName)\**\*.*" Exclude="@(FileContents)" />
  </ItemGroup>
  <Copy SourceFiles="@(ModuleFiles)" DestinationFiles="@(ModuleFiles->'$(DestFolder)\$(ProjectModuleName)\%(RecursiveDir)%(Filename)%(Extension)')" ContinueOnError="false" />
  <Message Text="Exclude = @(FileContents)" />
  <!--CallTarget Targets="RemoveCustomModuleConfigFiles" /-->
</Target>

produce this output in console :

copy /y "CPBMessaging\CPBMessagingWeb_NotificationMessage\Web.Debug.config" "C:\__CPB\CPBSite\CPBMessagingWeb_NotificationMessage\Web.Debug.config"
Copying file from "CPBMessaging\CPBMessagingWeb_NotificationMessage\Web.Release.config" to "C:\__CPB\CPBSite\CPBMessagingWeb_NotificationMessage\Web.Release.config"
copy /y "CPBMessaging\CPBMessagingWeb_NotificationMessage\Web.Release.config" "C:\__CPB\CPBSite\CPBMessagingWeb_NotificationMessage\Web.Release.config"
Exclude = *.cab;*.config;*.vb;*.cs;*.resx;*.xsx;*.bak;*.myapp;*.settings;*#*;
*.vbproj*;*.csproj*;*\Errors\*;*\Errors;*\_vti_*\*;*\_vti_*;*\CVS\*;*\CVS;

Upvotes: 0

James Woolfenden
James Woolfenden

Reputation: 6681

Would it not be easier to just use the exclude property instead? as in Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<ItemGroup>
  <ModuleFiles Include="c:\code\**\*.*"
               Exclude="@(FileContents)" />
</ItemGroup>


<!--<Copy SourceFiles="@(ModuleFiles)" DestinationFolder="Some|Destination" Condition="'%(ModuleFiles.Identity)' != @(FileContents)" ContinueOnError="false" />

CallTarget Targets="RemoveCustomModuleConfigFiles" /-->

Upvotes: 6

Related Questions