diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
index c610f34c1b689..3d48cf2d7cf0f 100644
--- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
+++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets
@@ -40,6 +40,7 @@ Copyright (c) .NET Foundation. All rights reserved.
+
true
@@ -168,6 +169,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<_WasmInvariantGlobalization Condition="'$(_WasmInvariantGlobalization)' == ''">true
<_WasmCopyOutputSymbolsToOutputDirectory>$(CopyOutputSymbolsToOutputDirectory)
<_WasmCopyOutputSymbolsToOutputDirectory Condition="'$(_WasmCopyOutputSymbolsToOutputDirectory)'==''">true
+ <_WasmEnableWebcil>$(WasmEnableWebcil)
+ <_WasmEnableWebcil Condition="'$(_WasmEnableWebcil)' == ''">false
<_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache)
<_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter)
<_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions)
@@ -205,8 +208,17 @@ Copyright (c) .NET Foundation. All rights reserved.
+
+ <_WasmBuildWebCilPath>$(IntermediateOutputPath)webcil
+
+
+
+
+
+
+
+
+ <_WasmPublishWebCilPath>$(IntermediateOutputPath)webcil\publish
+
+
+
+
+
+
+
-
+
ComputeUpdatedAssemblies(
{
var asset = kvp.Value;
var fileName = Path.GetFileName(asset.GetMetadata("RelativePath"));
+ if (IsWebCilEnabled)
+ fileName = Path.ChangeExtension(fileName, ".dll");
+
if (resolvedAssembliesToPublish.TryGetValue(fileName, out var existing))
{
// We found the assembly, so it'll have to be updated.
@@ -550,7 +555,7 @@ private void GroupResolvedFilesToPublish(
}
var extension = candidate.GetMetadata("Extension");
- if (string.Equals(extension, ".dll", StringComparison.Ordinal))
+ if (string.Equals(extension, ".dll", StringComparison.Ordinal) || string.Equals(extension, ".webcil", StringComparison.Ordinal))
{
var culture = candidate.GetMetadata("Culture");
var inferredCulture = candidate.GetMetadata("DestinationSubDirectory").Replace("\\", "/").Trim('/');
diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs
new file mode 100644
index 0000000000000..fc8136525bd68
--- /dev/null
+++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ConvertDllsToWebCil.cs
@@ -0,0 +1,90 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.Serialization;
+using System.Runtime.Serialization.Json;
+using System.Text;
+using System.Xml;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+using ResourceHashesByNameDictionary = System.Collections.Generic.Dictionary;
+
+namespace Microsoft.NET.Sdk.WebAssembly;
+
+public class ConvertDllsToWebCil : Task
+{
+ [Required]
+ public ITaskItem[] Candidates { get; set; }
+
+ [Required]
+ public string OutputPath { get; set; }
+
+ [Required]
+ public bool IsEnabled { get; set; }
+
+ [Output]
+ public ITaskItem[] WebCilCandidates { get; set; }
+
+ protected readonly List _fileWrites = new();
+
+ [Output]
+ public string[]? FileWrites => _fileWrites.ToArray();
+
+ public override bool Execute()
+ {
+ var webCilCandidates = new List();
+
+ if (!IsEnabled)
+ {
+ WebCilCandidates = Candidates;
+ return true;
+ }
+
+ for (int i = 0; i < Candidates.Length; i++)
+ {
+ var candidate = Candidates[i];
+
+ var extension = candidate.GetMetadata("Extension");
+ var filePath = candidate.ItemSpec;
+
+ if (!Directory.Exists(OutputPath))
+ Directory.CreateDirectory(OutputPath);
+
+ if (extension == ".dll")
+ {
+ var tmpWebcil = Path.GetTempFileName();
+ var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: filePath, outputPath: tmpWebcil, logger: Log);
+ webcilWriter.ConvertToWebcil();
+
+ var finalWebcil = Path.Combine(OutputPath, Path.GetFileNameWithoutExtension(filePath) + ".webcil");
+ if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true))
+ Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} .");
+ else
+ Log.LogMessage(MessageImportance.Low, $"Skipped generating {finalWebcil} as the contents are unchanged.");
+
+ _fileWrites.Add(finalWebcil);
+
+ var webcilItem = new TaskItem(finalWebcil, candidate.CloneCustomMetadata());
+ webcilItem.SetMetadata("RelativePath", Path.ChangeExtension(candidate.GetMetadata("RelativePath"), ".webcil"));
+ webcilItem.SetMetadata("AssetTraitName", "WasmResource");
+ webcilItem.SetMetadata("AssetTraitValue", "runtime");
+ webcilItem.SetMetadata("OriginalItemSpec", finalWebcil);
+
+ webCilCandidates.Add(webcilItem);
+ }
+ else
+ {
+ webCilCandidates.Add(candidate);
+ }
+ }
+
+ WebCilCandidates = webCilCandidates.ToArray();
+ return true;
+ }
+}
diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj
index e56ee68e46a5e..747e216bfb46e 100644
--- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj
+++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj
@@ -6,6 +6,7 @@
Microsoft.NET.Sdk.WebAssembly
true
true
+ $(NoWarn);CS8632
@@ -16,8 +17,13 @@
+
+
+
+
+