Replace powershell-based resgen by dotnet C# based one
This commit is contained in:
parent
483166ea60
commit
08fda6842a
148
build.psm1
148
build.psm1
|
@ -1276,22 +1276,17 @@ function Start-ResGen
|
|||
[CmdletBinding()]
|
||||
param()
|
||||
|
||||
Get-ChildItem $PSScriptRoot/src -Directory | ? {
|
||||
Get-ChildItem (Join-Path $_.FullName 'resources') -ErrorAction SilentlyContinue} | % {
|
||||
$_. Name} | % {
|
||||
# Add .NET CLI tools to PATH
|
||||
Find-Dotnet
|
||||
|
||||
$module = $_
|
||||
Get-ChildItem "$PSScriptRoot/src/$module/resources" -Filter '*.resx' | % {
|
||||
$className = $_.Name.Replace('.resx', '')
|
||||
$xml = [xml](Get-Content -raw $_.FullName)
|
||||
|
||||
$fileName = $className
|
||||
$genSource = Get-StronglyTypeCsFileForResx -xml $xml -ModuleName $module -ClassName $className
|
||||
$outPath = "$PSScriptRoot/src/$module/gen/$fileName.cs"
|
||||
Write-Verbose "ResGen for $outPath"
|
||||
New-Item -Type Directory -ErrorAction SilentlyContinue (Split-Path $outPath) > $null
|
||||
Set-Content -Encoding Ascii -Path $outPath -Value $genSource
|
||||
}
|
||||
Push-Location "$PSScriptRoot/src/ResGen"
|
||||
try
|
||||
{
|
||||
Start-NativeExecution { dotnet run } | Write-Verbose
|
||||
}
|
||||
finally
|
||||
{
|
||||
Pop-Location
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1576,129 +1571,6 @@ function script:Start-NativeExecution([scriptblock]$sb)
|
|||
}
|
||||
}
|
||||
|
||||
function script:Get-StronglyTypeCsFileForResx
|
||||
{
|
||||
param($xml, $ModuleName, $ClassName)
|
||||
|
||||
# Example
|
||||
#
|
||||
# $ClassName = Full.Name.Of.The.ClassFoo
|
||||
# $shortClassName = ClassFoo
|
||||
# $namespaceName = Full.Name.Of.The
|
||||
|
||||
$shortClassName = $ClassName
|
||||
$namespaceName = $null
|
||||
|
||||
$lastIndexOfDot = $className.LastIndexOf(".")
|
||||
if ($lastIndexOfDot -ne -1)
|
||||
{
|
||||
$namespaceName = $className.Substring(0, $lastIndexOfDot)
|
||||
$shortClassName = $className.Substring($lastIndexOfDot + 1)
|
||||
}
|
||||
|
||||
$banner = @'
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a Start-ResGen funciton from build.psm1.
|
||||
// To add or remove a member, edit your .ResX file then rerun Start-ResGen.
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
{0}
|
||||
'@
|
||||
|
||||
$namespace = @'
|
||||
namespace {0} {{
|
||||
{1}
|
||||
}}
|
||||
'@
|
||||
|
||||
$body = @'
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
|
||||
internal class {0} {{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal {0}() {{
|
||||
}}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {{
|
||||
get {{
|
||||
if (object.ReferenceEquals(resourceMan, null)) {{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("{1}.resources.{3}", typeof({0}).GetTypeInfo().Assembly);
|
||||
resourceMan = temp;
|
||||
}}
|
||||
return resourceMan;
|
||||
}}
|
||||
}}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {{
|
||||
get {{
|
||||
return resourceCulture;
|
||||
}}
|
||||
set {{
|
||||
resourceCulture = value;
|
||||
}}
|
||||
}}
|
||||
{2}
|
||||
}}
|
||||
'@
|
||||
|
||||
$entry = @'
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to {1}
|
||||
/// </summary>
|
||||
internal static string {0} {{
|
||||
get {{
|
||||
return ResourceManager.GetString("{0}", resourceCulture);
|
||||
}}
|
||||
}}
|
||||
'@
|
||||
$entries = $xml.root.data | % {
|
||||
if ($_) {
|
||||
$val = $_.value.Replace("`n", "`n ///")
|
||||
$name = $_.name.Replace(' ', '_')
|
||||
$entry -f $name,$val
|
||||
}
|
||||
} | Out-String
|
||||
|
||||
$bodyCode = $body -f $shortClassName,$ModuleName,$entries,$ClassName
|
||||
|
||||
if ($NamespaceName)
|
||||
{
|
||||
$bodyCode = $namespace -f $NamespaceName, $bodyCode
|
||||
}
|
||||
|
||||
$resultCode = $banner -f $bodyCode
|
||||
|
||||
return $resultCode -replace "`r`n?|`n","`r`n"
|
||||
}
|
||||
|
||||
# Builds coming out of this project can have version number as 'a.b.c' OR 'a.b.c-d-f'
|
||||
# This function converts the above version into major.minor[.build[.revision]] format
|
||||
function Get-PackageVersionAsMajorMinorBuildRevision
|
||||
|
|
Loading…
Reference in a new issue