• Lexical
Show / Hide Table of Contents
  • Lexical.FileSystem
    • Introduction
    • Abstractions
      • IFileSystem
        • IFileSystem
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpen
      • IEvent
      • IEntry
      • IOption
      • IToken
    • FileSystem
    • VirtualFileSystem
    • MemoryFileSystem
    • EmbeddedFileSystem
    • HttpFileSystem
    • Decoration
    • IFileProvider
    • Utility
      • DisposeList
      • FileScanner
      • VisitTree
      • File Operation
  • Lexical.FileProvider
    • Introduction
    • Package
    • Package.Abstractions
    • Root
    • Zip
    • Dll
    • SharpCompress
    • SharpZipLib
    • FileScanner
    • Utils
  • Lexical.Localization
    • Introduction
    • Tutorial
    • Asset
      • IAsset
      • IStringAsset
    • Line
      • ILine
      • ILineFactory
      • ILineRoot
      • ILineFormat
      • ILineLogger
      • LineComparer
    • File
      • ILineReader
      • ILineWriter
      • Ini
      • Json
      • Xml
      • Resx
      • Resources
    • Miscellaneous
      • Plurality
      • ICulturePolicy
      • IStringFormat
      • Dependency Injection
    • Practices
      • Class Library
      • Class Library DI
      • Class Library DI opt.
  • Lexical.Utilities
    • Introduction
    • UnicodeString
    • FileScanner
    • Permutation
    • Tuples
    • StructList

MSBuild Task

MSBuild Task automatically updates the localization files as code evolves.


Download Lexical.Localization.Tool.exe and add it into the C# project folder.


mstask1


Open .csproj file. This option is visible for .NET Core and Standard projects. For framework projects, edit with text editor.

mstask2


Add the following into the <Project> node.

  <!-- Select property depending on MSBuild environment -->
  <PropertyGroup>
    <LocalizationToolAssembly Condition=" '$(MSBuildRuntimeType)' == 'Core'">Lexical.Localization.Tool.dll</LocalizationToolAssembly>
    <LocalizationToolAssembly Condition=" '$(MSBuildRuntimeType)' != 'Core'">Lexical.Localization.Tool.exe</LocalizationToolAssembly>
  </PropertyGroup>
  <!-- Import tool -->
  <UsingTask AssemblyFile="$(ProjectDir)$(LocalizationToolAssembly)" TaskName="LocalizationToolTask" />
  <!-- Run tool -->
  <Target Name="LocalizationToolTask" AfterTargets="Build">
    <ItemGroup>
      <!-- Scan the current target .dll or .exe -->
      <ScanFile Include="$(TargetPath)" />

      <!-- Include file -->
      <InputFile Include="some_localization.ini" />
    </ItemGroup>
    <Delete Files="localization.log" />
    <LocalizationToolTask InlineScans="@(ScanFile)" Inputs="@(InputFile)" Outputs="localization.ini" Verbose="True" IncludePartial="True" LogFiles="localization.log" />
  </Target>

mstask3


Rebuild the project, and the msbuild should have now rewritten the localization.ini file.
The configuration can be modified to output to other formats, to split into culture specific files and to group categories differently. See Outputs parameter.

LocalizationToolTask Parameters:

Parameter Description Example Value
Configs Config files to include. scanjob.json
LogFiles Files to append log messages. log.txt
ErrorFiles Files to append error messages. log.txt
Verbose Whether use verbose log messages. True/False
Inputs Localization files to input. **.dll/**.resources
**.xml
InlineScans Files to scan for inline strings. **.dll
IncludePartial Whether inline scan should add partially recognized keys. True/False
Excludes Files to exclude. Affects "Includes" and "InlineScans" properties. **.zip/**
Outputs Files to write localization files to. localization{-culture}.xml
localization{-culture}.xml,{anysection_0.}{anysection_1.}{key_0}{.key_1}
KeyExtend Extend all keys to all cultures. True/False
Cultures List of cultures to include en-UK,de-DE
CulturesExclude List of cultures to exclude fi-FI



Back to top Copyright © 2015-2020 Toni Kalajainen