Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public string CreateBlazorWasmTemplateProject(string id)
if (options.ExpectRelinkDirWhenPublishing)
Assert.True(Directory.Exists(objBuildDir), $"Could not find expected {objBuildDir}, which gets created when relinking during Build. This is likely a test authoring error");
else
Assert.False(Directory.Exists(objBuildDir), $"Found unexpected {objBuildDir}, which gets created when relinking during Build");
Assert.False(File.Exists(Path.Combine(objBuildDir, "emcc-link.rsp")), $"Found unexpected files in {objBuildDir}, which gets created when relinking during Build");

return (res, logPath);
}
Expand Down
43 changes: 43 additions & 0 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,47 @@ public void DefaultTemplate_CheckFingerprinting(string config, bool expectFinger
//// publish again, no AOT
//BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked);
//}

[Theory]
[InlineData("Debug")]
[InlineData("Release")]
public void DefaultTemplate_WithResources_Publish(string config)
{
string[] cultures = ["ja-JP", "es-ES"];
string id = $"blz_resources_{config}_{GetRandomId()}";
CreateBlazorWasmTemplateProject(id);

// Ensure we have the source data we rely on
string resxSourcePath = Path.Combine(BuildEnvironment.TestAssetsPath, "resx");
foreach (string culture in cultures)
Assert.True(File.Exists(Path.Combine(resxSourcePath, $"words.{culture}.resx")));

Utils.DirectoryCopy(resxSourcePath, Path.Combine(_projectDir!, "resx"));

// Build and assert resource dlls
BlazorBuild(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack));
AssertResourcesDlls(FindBlazorBinFrameworkDir(config, false));

// Publish and assert resource dlls
if (config == "Release")
{
// relinking in publish for Release config
BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectRelinkDirWhenPublishing: true));
}
else
{
BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.FromRuntimePack, ExpectRelinkDirWhenPublishing: true));
}

AssertResourcesDlls(FindBlazorBinFrameworkDir(config, true));

void AssertResourcesDlls(string basePath)
{
foreach (string culture in cultures)
{
string resourceAssemblyPath = Path.Combine(basePath, culture, $"{id}.resources{ProjectProviderBase.WasmAssemblyExtension}");
Assert.True(File.Exists(resourceAssemblyPath), $"Expects to have a resource assembly at {resourceAssemblyPath}");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ public override bool Execute()
var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log);
webcilWriter.ConvertToWebcil();

string candicatePath = Path.Combine(OutputPath, candidate.GetMetadata("Culture"));
if (!Directory.Exists(candicatePath))
Directory.CreateDirectory(candicatePath);
string candidatePath = candidate.GetMetadata("AssetTraitName") == "Culture"
? Path.Combine(OutputPath, candidate.GetMetadata("AssetTraitValue"))
: OutputPath;

var finalWebcil = Path.Combine(candicatePath, webcilFileName);
if (!Directory.Exists(candidatePath))
Directory.CreateDirectory(candidatePath);

var finalWebcil = Path.Combine(candidatePath, webcilFileName);
if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
else
Expand Down