Detokenise

May 11, 2009 at 1:58 AM

Let me start by saying that I am a newbie to MSBuild and the extension pack.  I am trying to get Detokenise to work.  I have added the target below, but it does do the replacement.  I added the properties below for Token and Replacement to the command line of MSBuild.

What am I doing wrong (probably a newbie mistake)?

Thanks for your help

 

Additional MSBuild command line:

/property:token=$CompanyName /property:Replacement=replaced

 

PROJ file

  <Target Name="Detokenise">
    <Message Text="in Detokenise"/>
    <ItemGroup>
      <FileCollection Include="$(MSBuildProjectDirectory)\..\Sources\DEV\Source\ArchiveCMD\ArchiveCMD\ArchiveCMD.cs"/>
    </ItemGroup>
    <!-- 2 Detokenise the files defined in FileCollection2 and use the tokens defined by the .proj properties -->
    <MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetFiles="@(FileCollection)" DisplayFiles="true">
        <Output TaskParameter="FilesProcessed" ItemName="FilesProcessed"/>
      <Output TaskParameter="FilesDetokenised" ItemName="FilesDetokenised"/>
    </MSBuild.ExtensionPack.FileSystem.Detokenise>

    <Message Text="FilesDetokenised = @(FilesDetokenised), FilesProcessed = @(FilesProcessed)"/>
  </Target>

 

LOG File:

Target "Detokenise" in file "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\ArchiveCMD\ArchiveCMD - DEV\BuildType\TFSBuild.proj" from project "C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\ArchiveCMD\ArchiveCMD - DEV\BuildType\TFSBuild.proj":
Task "Message"
  in Detokenise
Done executing task "Message".
Using "MSBuild.ExtensionPack.FileSystem.Detokenise" task from assembly "C:\Program Files\MSBuild\ExtensionPack\MSBuild.ExtensionPack.dll".
Task "MSBuild.ExtensionPack.FileSystem.Detokenise"
  Detokenise Task Execution Started [21:05:36]
  Loading Project: C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\ArchiveCMD\ArchiveCMD - DEV\BuildType\TFSBuild.proj
  Detokenising Collection: 1 files
  Detokenising File: C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp\ArchiveCMD\ArchiveCMD - DEV\BuildType\..\Sources\DEV\Source\ArchiveCMD\ArchiveCMD\ArchiveCMD.cs
  Detokenise Task Execution Completed [21:05:36]
Done executing task "MSBuild.ExtensionPack.FileSystem.Detokenise".
Task "Message"
  FilesDetokenised = 0, FilesProcessed = 1
Done executing task "Message".
Done building target "Detokenise" in project "TFSBuild.proj".

Coordinator
May 11, 2009 at 12:09 PM

You need to pass in an ItemGroup of replacement values or (preferably) have properties defined in your MSBuild file that will be used.

e.g.

<ItemGroup>
    <TokenValues Include="CompanyName">
        <Replacement>replaced</Replacement>
    </TokenValues>
</ItemGroup>

<MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetFiles="@(FileCollection)" ReplacementValues="@(TokenValues)" DisplayFiles="true">
    <Output TaskParameter="FilesProcessed" ItemName="FilesProcessed"/>
    <Output TaskParameter="FilesDetokenised" ItemName="FilesDetokenised"/>
</MSBuild.ExtensionPack.FileSystem.Detokenise>

or

<PropertyGroup>
    <CompanyName>replaced</CompanyName>
</PropertyGroup>

<MSBuild.ExtensionPack.FileSystem.Detokenise TaskAction="Detokenise" TargetFiles="@(FileCollection)" DisplayFiles="true">
    <Output TaskParameter="FilesProcessed" ItemName="FilesProcessed"/>
    <Output TaskParameter="FilesDetokenised" ItemName="FilesDetokenised"/>
</MSBuild.ExtensionPack.FileSystem.Detokenise>

 

 

 

May 11, 2009 at 1:27 PM

Thanks for the quick reply.  Basically, I want to be able to pass the replacement value in via the MSBuild command line.  Would that be accomplished with the PropertyGroup solution?  If so, what command line do I pass in to set the company name?  I do not want to hard code the company name in the proj file as that would defeat the purpose.  I need a different replacement string for each build.

Thanks again

Coordinator
May 11, 2009 at 2:15 PM

Ah. The task doesn't support command line parameters for substitution. I'll move this to a work item.

Coordinator
May 11, 2009 at 2:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 11, 2009 at 2:46 PM

Ah - thanks for the update.  Is there any other way to accomplish what I am trying to do (basically, I want to compile the company name into the EXE)?  Obviously, each build would require a different substitution value.

I ask because I am not all that familiar with the MSBuild or the extension pack.

Also, how soon could this work item be added to a release?

Thanks

Coordinator
May 11, 2009 at 2:53 PM

You could use MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace"

A new releace is pencilled in for around the 25th, but I can't say if this update will be in it.

Mike

May 11, 2009 at 2:54 PM

Thanks - I will look in to that.

May 11, 2009 at 4:00 PM

I looked in the help file about Replace.  Can I pass in the replacement value from the command line (if so, how)?

Thanks.

Coordinator
May 12, 2009 at 8:26 PM

if you are trying to replace $(CompanyName) in a file, the following will work.

        <MSBuild.ExtensionPack.FileSystem.File TaskAction="Replace" RegexPattern="$(YourProperty)" Replacement="$(YourReplacement)" Files="@(FileCollection)"/>

Call the file using:

msbuild File.proj /p:YourProperty=\$\(CompanyName\);YourReplacement=XYZ

Mike