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.
Open .csproj file. This option is visible for .NET Core and Standard projects. For framework projects, edit with text editor.
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>
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 |