1

我有一个 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>

如果没有复制任务的“条件”属性,一切正常,但我不知道如何使用通配符实现条件以及是否可能

任何形式的帮助将不胜感激:)这让我吓坏了几个小时......

4

2 回答 2

5

改用 exclude 属性不是更容易吗?如项目 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" /-->

于 2012-10-23T20:20:08.310 回答
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;
于 2012-10-24T13:26:37.090 回答