Detokenise Class

MSBuild Extension Pack

Detokenise Class MSBuild Extension Pack Help 4.0.12.0
Valid TaskActions are:

Analyse (Required: TargetFiles or TargetPath Optional: CommandLineValues, DisplayFiles, TextEncoding, ForceWrite, ReplacementValues, Separator, TokenPattern, TokenExtractionPattern Output: FilesProcessed)

Detokenise (Required: TargetFiles or TargetPath Optional: SearchAllStores, IgnoreUnknownTokens, CommandLineValues, DisplayFiles, TextEncoding, ForceWrite, ReplacementValues, Separator, TokenPattern, TokenExtractionPattern Output: FilesProcessed, FilesDetokenised)

Report (Required: TargetFiles or TargetPath Optional: DisplayFiles, TokenPattern, ReportUnusedTokens Output: FilesProcessed, TokenReport, UnusedTokens)

Remote Execution Support: No

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.FileSystemDetokenise

Namespace: MSBuild.ExtensionPack.FileSystem
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The Detokenise type exposes the following members.

Constructors

  NameDescription
Public methodDetokenise
Top
Properties

  NameDescription
Public propertyCommandLineValues
Sets the replacement values provided via the command line. The format is token1=value1#~#token2=value2 etc.
Public propertyDisplayFiles
Set to true for files being processed to be output to the console.
Public propertyFilesDetokenised
Gets the files detokenised count. [Output]
Public propertyFilesProcessed
Gets the files processed count. [Output]
Public propertyForceWrite
If this is set to true, then the file is re-written, even if no tokens are matched. this may be used in the case when the user wants to ensure all file are written with the same encoding.
Public propertyIgnoreUnknownTokens
Specifies whether to ignore tokens which are not matched. Default is false.
Public propertyProjectFile
Sets the MSBuild file to load for token matching. Defaults to BuildEngine.ProjectFileOfTaskNode
Public propertyReplacementValues
Sets the replacement values.
Public propertyReportUnusedTokens
Set to true when running a Report to see which tokens are not used in any files scanned. Default is false.
Public propertySearchAllStores
Specifies whether to search in the ReplacementValues, CommandLineValues and the ProjectFile for token values. Default is false.
Public propertySeparator
Sets the separator to use to split the CommandLineValues. The default is #~#
Public propertyTargetFiles
Sets the TargetFiles.
Public propertyTargetPath
Sets the TargetPath.
Public propertyTextEncoding
The file encoding to write the new file in. The task will attempt to default to the current file encoding. If TargetFiles is specified, individual encodings can be specified by providing an Encoding metadata value.
Public propertyTokenExtractionPattern
Specifies the regular expression to use to extract the token name from the TokenPattern provided. The default pattern is (?<=\$\()[0-9a-zA-Z-._]+(?=\)), i.e it will extract token from $(token)
Public propertyTokenPattern
Specifies the regular expression format of the token to look for. The default pattern is \$\([0-9a-zA-Z-._]+\) which equates to $(token)
Public propertyTokenReport
ItemGroup containing the Tokens (Identity) and Files metadata containing all the files in which the token can be found.
Public propertyUnusedTokens
Itemgroup containing the tokens which have been provided but not found in the files scanned. ReportUnusedTokens must be set to true to use this.
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default;Report" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <PropertyGroup>
        <PathToDetokenise>C:\Demo\*</PathToDetokenise>
        <CPHome>http://www.msbuildextensionpack.com</CPHome>
        <Title>A New Title</Title>
        <clv>hello=hello#~#hello1=how#~#hello2=are#~#Configuration=debug</clv>
        <Configuration>debug</Configuration>
        <Platform>x86</Platform>
        <HiImAnUnsedToken>TheReportWillFindMe</HiImAnUnsedToken>
    </PropertyGroup>
    <Target Name="Default">
        <ItemGroup>
            <FileCollection Include="C:\Demo1\TestFile.txt"/>
            <FileCollection2 Include="C:\Demo1\TestFile2.txt"/>
            <FileCollection3 Include="C:\Demo1\TestFile3.txt"/>
        </ItemGroup>
        <ItemGroup>
            <TokenValues Include="Title">
                <Replacement>ANewTextString</Replacement>
            </TokenValues >
            <TokenValues Include="ProjectHome">
                <Replacement>http://www.msbuildextensionpack.com</Replacement>
            </TokenValues >
        </ItemGroup>
        <!-- Analyse a collection of files. This can be used to ensure that all tokens are known. -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Analyse" TargetFiles="@(FileCollection)" ReplacementValues="@(TokenValues)"/>
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Analyse" TargetFiles="@(FileCollection2)"/>
        <!-- 1 Detokenise the files defined in FileCollection and use the TokenValues collection for substitution. -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetFiles="@(FileCollection)" ReplacementValues="@(TokenValues)"/>
        <!-- 2 Detokenise the files defined in FileCollection2 and use the tokens defined by the .proj properties -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetFiles="@(FileCollection2)"/>
        <!-- 3 Detokenise the files at the given TargetPath and perform a recursive search -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetPath="$(PathToDetokenise)"/>
        <!-- 4 This will produce the same result as #3, but no file processing will be logged to the console. Because ForceWrite has been specified, all files will be re-written -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetPath="$(PathToDetokenise)" DisplayFiles="false" ForceWrite="true"/>
        <!-- 5 This will produce the same result as 4, though ForceWrite is false by default so the difference can be displayed using the output parameters -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetPath="$(PathToDetokenise)" DisplayFiles="false">
            <Output TaskParameter="FilesProcessed" ItemName="FilesProcessed"/>
            <Output TaskParameter="FilesDetokenised" ItemName="FilesDetokenised"/>
        </MSBuild.ExtensionPack.FileSystem.Detokenise>
        <Message Text="FilesDetokenised = @(FilesDetokenised), FilesProcessed = @(FilesProcessed)"/>
        <!-- 6 Detokenise using values that can be passed in via the command line -->
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetFiles="@(FileCollection3)" CommandLineValues="$(clv)"/>
    </Target>
    <!--- Generate a report of files showing which tokens are used in files -->
    <Target Name="Report" DependsOnTargets="GetFiles">
        <CallTarget Targets="List"/>
    </Target>
    <Target Name="List" Inputs="@(Report1)" Outputs="%(Identity)">
        <Message Text="Token: @(Report1)"/>
        <Message Text="%(Report1.Files)"/>
    </Target>
    <Target Name="GetFiles">
        <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Report" TargetPath="C:\Demo1*"  DisplayFiles="true" ReportUnusedTokens="true">
            <Output TaskParameter="TokenReport" ItemName="Report1"/>
            <Output TaskParameter="UnusedTokens" ItemName="Unused"/>
        </MSBuild.ExtensionPack.FileSystem.Detokenise>
        <Message Text="Unused Token - %(Unused.Identity)"/>
    </Target>
</Project>
See Also

Reference