Search 如何搜索包含特定文本字符串的文件?
如何使用MSBuild搜索包含特定文本字符串的文件?您可以在CodePlex上的项目中找到“grep”任务。不过我自己还没用过。你可以在CodePlex上的项目中找到一个“grep”任务。不过我自己还没有用过。不清楚是要在名称中搜索文本,还是在文件本身中搜索文本 如果您只是想要一个文件列表,其名称符合特定(简单)标准,我建议您使用Search 如何搜索包含特定文本字符串的文件?,search,msbuild,Search,Msbuild,如何使用MSBuild搜索包含特定文本字符串的文件?您可以在CodePlex上的项目中找到“grep”任务。不过我自己还没用过。你可以在CodePlex上的项目中找到一个“grep”任务。不过我自己还没有用过。不清楚是要在名称中搜索文本,还是在文件本身中搜索文本 如果您只是想要一个文件列表,其名称符合特定(简单)标准,我建议您使用ItemGroup如下: MSBuild Contrib项目中的Greptak如下所示 <PropertyGroup> <MSBuildCon
ItemGroup
如下:
MSBuild Contrib项目中的Grep
tak如下所示
<PropertyGroup>
<MSBuildContribCommonTasksAssembly>$(MSBuildExtensionsPath)\MSBuildContrib\MSBuildContrib.Tasks.dll</MSBuildContribCommonTasksAssembly>
</PropertyGroup>
<UsingTask TaskName="MSBuildContrib.Tasks.Grep" AssemblyFile="$(MSBuildContribCommonTasksAssembly)" Condition="Exists('$(MSBuildContribCommonTasksAssembly)')" />
<ItemGroup>
<FilesToSearch Include="**\*.cs" />
</ItemGroup>
<!-- very simple search -->
<Grep InputFiles="@(FilesToSearch )" OutputFile="out.xml" Pattern="Error" />
<!-- slightly more complicated search (search and extract info) -->
<Grep InputFiles="@(FilesToSearch )"
OutputFile="out.xml"
Pattern="// (?'Type'TODO|UNDONE|HACK): (\[(?'Author'\w*),(?'Date'.*)\])? (?'Text'[^\n\r]*)" />
$(MSBuildExtensionsPath)\MSBuildContrib\MSBuildContrib.Tasks.dll
Grep任务将生成out.xml文件,该文件随后可用于从中读取信息并在生成过程中使用。不清楚是要在名称中搜索文本还是在文件本身中搜索文本 如果您只是想要一个文件列表,其名称符合特定(简单)标准,我建议您使用
ItemGroup
如下:
MSBuild Contrib项目中的Grep
tak如下所示
<PropertyGroup>
<MSBuildContribCommonTasksAssembly>$(MSBuildExtensionsPath)\MSBuildContrib\MSBuildContrib.Tasks.dll</MSBuildContribCommonTasksAssembly>
</PropertyGroup>
<UsingTask TaskName="MSBuildContrib.Tasks.Grep" AssemblyFile="$(MSBuildContribCommonTasksAssembly)" Condition="Exists('$(MSBuildContribCommonTasksAssembly)')" />
<ItemGroup>
<FilesToSearch Include="**\*.cs" />
</ItemGroup>
<!-- very simple search -->
<Grep InputFiles="@(FilesToSearch )" OutputFile="out.xml" Pattern="Error" />
<!-- slightly more complicated search (search and extract info) -->
<Grep InputFiles="@(FilesToSearch )"
OutputFile="out.xml"
Pattern="// (?'Type'TODO|UNDONE|HACK): (\[(?'Author'\w*),(?'Date'.*)\])? (?'Text'[^\n\r]*)" />
$(MSBuildExtensionsPath)\MSBuildContrib\MSBuildContrib.Tasks.dll
Grep任务将生成out.xml文件,该文件随后可用于从中读取信息并在构建过程中使用。谢谢大家!非常感谢您的快速回复! 我尝试过Grep,但我需要读取xml文件才能看到结果 我刚刚发现,我们可以在MSBuild扩展包中使用TaskFilterByContent,它可以直接生成属性和项。如果你需要的话,我想把它还给你。用法示例如下所示:
<Target Name="ttt">
<ItemGroup>
<files Include="d:\temp\test\**" />
</ItemGroup>
<MSBuild.ExtensionPack.FileSystem.File TaskAction="FilterByContent" RegexPattern="abbcc" Files="@(files)" >
<Output TaskParameter="IncludedFileCount" PropertyName="out"/>
</MSBuild.ExtensionPack.FileSystem.File>
<Message Text="ttt:$(out)" />
</Target>
Nam.谢谢大家!非常感谢您的快速回复! 我尝试过Grep,但我需要读取xml文件才能看到结果 我刚刚发现,我们可以在MSBuild扩展包中使用TaskFilterByContent,它可以直接生成属性和项。如果你需要的话,我想把它还给你。用法示例如下所示:
<Target Name="ttt">
<ItemGroup>
<files Include="d:\temp\test\**" />
</ItemGroup>
<MSBuild.ExtensionPack.FileSystem.File TaskAction="FilterByContent" RegexPattern="abbcc" Files="@(files)" >
<Output TaskParameter="IncludedFileCount" PropertyName="out"/>
</MSBuild.ExtensionPack.FileSystem.File>
<Message Text="ttt:$(out)" />
</Target>
Nam。请不要在标题中添加[MSBuild]。标记中已包含该文件。请不要将[MSBuild]放入标题中。标签上已经有了。