MSBuild从带有通配符的文件复制任务和条件名称

时间:2012-10-23 09:07:41

标签: msbuild

我有一个FilesToExclude2.txt文件,其中包含所有类似的排除:

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

在我的任务文件中,有一个复制任务

  <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>

在复制任务中没有“condition”属性,一切正常,但我不知道如何用通配符实现条件,如果可能的话

任何形式的帮助都会非常感激:)这让我吓了几个小时......

2 个答案:

答案 0 :(得分:4)

仅使用exclude属性会不会更容易? 如在 Project xmlns =“http://schemas.microsoft.com/developer/msbuild/2003”&gt;                 

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


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

CallTarget Targets="RemoveCustomModuleConfigFiles" /-->

答案 1 :(得分:0)

以下代码

<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>

在控制台中生成此输出:

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;