diff --git a/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs b/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs
index 88e8393930..128616922f 100644
--- a/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs
+++ b/src/Microsoft.Blazor.Build/Core/RazorCompilation/Engine/BlazorIntermediateNodeWriter.cs
@@ -148,6 +148,16 @@ namespace Microsoft.Blazor.Build.Core.RazorCompilation.Engine
.WriteEndMethodInvocation();
}
+ foreach (var attribute in nextTag.Attributes)
+ {
+ context.CodeWriter
+ .WriteStartMethodInvocation($"{builderVarName}.{nameof(RenderTreeBuilder.AddAttribute)}")
+ .WriteStringLiteral(attribute.Key)
+ .WriteParameterSeparator()
+ .WriteStringLiteral(attribute.Value)
+ .WriteEndMethodInvocation();
+ }
+
if (nextToken.Type == HtmlTokenType.EndTag
|| nextTag.IsSelfClosing
|| htmlVoidElementsLookup.Contains(nextTag.Data))
diff --git a/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs b/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs
index ac7f730c4e..02e7091cce 100644
--- a/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs
+++ b/test/Microsoft.Blazor.Build.Test/RazorCompilerTest.cs
@@ -157,6 +157,19 @@ namespace Microsoft.Blazor.Build.Test
node => AssertNode.Element(node, "img", 1));
}
+ [Fact]
+ public void CanRenderAttributes()
+ {
+ // Arrange/Act
+ var component = CompileToComponent("