From db5bdf257b5278c139b2eaf0bfd3e96e57953a4f Mon Sep 17 00:00:00 2001
From: "dotnet-maestro[bot]"
<42748379+dotnet-maestro[bot]@users.noreply.github.com>
Date: Sat, 24 Feb 2024 06:10:43 +0000
Subject: [PATCH] [main] Update dependencies from dotnet/razor (#38936)
[main] Update dependencies from dotnet/razor
- Use merged Razor compiler DLL
- Exempt ObjectPool dependency of the Razor compiler
- Fix extension loading
---
eng/Version.Details.xml | 16 ++++++------
eng/Versions.props | 6 ++---
...rosoft.NET.Sdk.Razor.Configuration.targets | 4 +--
.../Tool/DefaultExtensionDependencyChecker.cs | 1 +
src/RazorSdk/Tool/DiscoverCommand.cs | 25 ++++++++++---------
src/RazorSdk/Tool/GenerateCommand.cs | 11 +++++++-
.../ScopedCssIntegrationTests.cs | 4 +--
7 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index b5fe24a4d646..040a17e91fcc 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -316,22 +316,22 @@
cc5bc6b56dc0a6e6f1ca103acff5afd9c71973ba
-
+
https://github.com/dotnet/razor
- 67bd8253e308d06bf249a02911d06317d5d7b5b9
+ dbb0fb5c0b742887931ba5e78ebf49998096a748
-
+
https://github.com/dotnet/razor
- 67bd8253e308d06bf249a02911d06317d5d7b5b9
+ dbb0fb5c0b742887931ba5e78ebf49998096a748
-
+
https://github.com/dotnet/razor
- 67bd8253e308d06bf249a02911d06317d5d7b5b9
+ dbb0fb5c0b742887931ba5e78ebf49998096a748
-
+
https://github.com/dotnet/razor
- 67bd8253e308d06bf249a02911d06317d5d7b5b9
+ dbb0fb5c0b742887931ba5e78ebf49998096a748
diff --git a/eng/Versions.props b/eng/Versions.props
index d49d723e8709..6e5a4e356ee9 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -160,9 +160,9 @@
- 7.0.0-preview.24120.8
- 7.0.0-preview.24120.8
- 7.0.0-preview.24120.8
+ 7.0.0-preview.24123.5
+ 7.0.0-preview.24123.5
+ 7.0.0-preview.24123.5
diff --git a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Configuration.targets b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Configuration.targets
index 8f0fa59ba967..29f55239ee41 100644
--- a/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Configuration.targets
+++ b/src/RazorSdk/Targets/Microsoft.NET.Sdk.Razor.Configuration.targets
@@ -93,8 +93,8 @@ Copyright (c) .NET Foundation. All rights reserved.
- Microsoft.CodeAnalysis.Razor.Compiler.Mvc
- $(RazorSdkDirectoryRoot)tools\Microsoft.CodeAnalysis.Razor.Compiler.Mvc.dll
+ Microsoft.CodeAnalysis.Razor.Compiler
+ $(RazorSdkDirectoryRoot)tools\Microsoft.CodeAnalysis.Razor.Compiler.dll
diff --git a/src/RazorSdk/Tool/DefaultExtensionDependencyChecker.cs b/src/RazorSdk/Tool/DefaultExtensionDependencyChecker.cs
index d47f0cb0e7ab..774c3caadc58 100644
--- a/src/RazorSdk/Tool/DefaultExtensionDependencyChecker.cs
+++ b/src/RazorSdk/Tool/DefaultExtensionDependencyChecker.cs
@@ -18,6 +18,7 @@ internal class DefaultExtensionDependencyChecker : ExtensionDependencyChecker
"System",
"Microsoft.CodeAnalysis",
"Microsoft.AspNetCore.Razor",
+ "Microsoft.Extensions.ObjectPool"
};
private readonly ExtensionAssemblyLoader _loader;
diff --git a/src/RazorSdk/Tool/DiscoverCommand.cs b/src/RazorSdk/Tool/DiscoverCommand.cs
index fd67bdabc4bb..41b6248bec5f 100644
--- a/src/RazorSdk/Tool/DiscoverCommand.cs
+++ b/src/RazorSdk/Tool/DiscoverCommand.cs
@@ -94,8 +94,13 @@ protected override bool ValidateArguments()
return true;
}
+ private const string RazorCompilerFileName = "Microsoft.CodeAnalysis.Razor.Compiler.dll";
+
+ internal static string GetRazorCompilerPath()
+ => Path.Combine(Path.GetDirectoryName(typeof(Application).Assembly.Location), RazorCompilerFileName);
+
///
- /// Replaces the assembly for MVC extension v1 or v2 with the one shipped alongside SDK (as opposed to the one from NuGet).
+ /// Replaces the assembly for MVC extension with the one shipped alongside SDK (as opposed to the one from NuGet).
///
///
/// Needed so the Razor compiler can change its APIs without breaking legacy MVC scenarios.
@@ -107,32 +112,28 @@ internal static void PatchExtensions(CommandOption extensionNames, CommandOption
for (int i = 0; i < extensionNames.Values.Count; i++)
{
var extensionName = extensionNames.Values[i];
- var replacementFileName = extensionName switch
+
+ string expectedOriginalPath = extensionName switch
{
- "MVC-1.0" or "MVC-1.1" => "Microsoft.CodeAnalysis.Razor.Compiler.Mvc.Version1_X.dll",
- "MVC-2.0" or "MVC-2.1" => "Microsoft.CodeAnalysis.Razor.Compiler.Mvc.Version2_X.dll",
+ "MVC-1.0" or "MVC-1.1" or "MVC-2.0" or "MVC-2.1" => "Microsoft.AspNetCore.Mvc.Razor.Extensions",
+ "MVC-3.0" => "Microsoft.CodeAnalysis.Razor.Compiler",
_ => null,
};
- if (replacementFileName != null)
+ if (expectedOriginalPath is not null)
{
var extensionFilePath = extensionFilePaths.Values[i];
- if (!HasExpectedFileName(extensionFilePath))
+ if (!string.Equals(expectedOriginalPath, Path.GetFileNameWithoutExtension(extensionFilePath), StringComparison.OrdinalIgnoreCase))
{
error.WriteLine($"Extension '{extensionName}' has unexpected path '{extensionFilePath}'.");
}
else
{
currentDirectory ??= Path.GetDirectoryName(typeof(Application).Assembly.Location);
- extensionFilePaths.Values[i] = Path.Combine(currentDirectory, replacementFileName);
+ extensionFilePaths.Values[i] = Path.Combine(currentDirectory, RazorCompilerFileName);
}
}
}
-
- static bool HasExpectedFileName(string filePath)
- {
- return "Microsoft.AspNetCore.Mvc.Razor.Extensions".Equals(Path.GetFileNameWithoutExtension(filePath), StringComparison.OrdinalIgnoreCase);
- }
}
protected override Task ExecuteCoreAsync()
diff --git a/src/RazorSdk/Tool/GenerateCommand.cs b/src/RazorSdk/Tool/GenerateCommand.cs
index f3399f5d9d29..a138cdb0370c 100644
--- a/src/RazorSdk/Tool/GenerateCommand.cs
+++ b/src/RazorSdk/Tool/GenerateCommand.cs
@@ -77,9 +77,18 @@ protected override Task ExecuteCoreAsync()
// Loading all of the extensions should succeed as the dependency checker will have already
// loaded them.
var extensions = new RazorExtension[ExtensionNames.Values.Count];
+ string razorCompilerPath = null;
for (var i = 0; i < ExtensionNames.Values.Count; i++)
{
- extensions[i] = new AssemblyExtension(ExtensionNames.Values[i], Parent.Loader.LoadFromPath(ExtensionFilePaths.Values[i]));
+ // If the extension is the Razor compiler, we'll use the referenced assembly (instead of the SDK one).
+ // Otherwise the extension's ProvideRazorExtensionInitializerAttribute would be different from the AssemblyExtension's one,
+ // hence the extension would not be loaded properly.
+ razorCompilerPath ??= DiscoverCommand.GetRazorCompilerPath();
+ var assembly = string.Equals(ExtensionFilePaths.Values[i], razorCompilerPath, StringComparison.OrdinalIgnoreCase)
+ ? typeof(AssemblyExtension).Assembly
+ : Parent.Loader.LoadFromPath(ExtensionFilePaths.Values[i]);
+
+ extensions[i] = new AssemblyExtension(ExtensionNames.Values[i], assembly);
}
var version = RazorLanguageVersion.Parse(Version.Value());
diff --git a/test/Microsoft.NET.Sdk.Razor.Tests/ScopedCssIntegrationTests.cs b/test/Microsoft.NET.Sdk.Razor.Tests/ScopedCssIntegrationTests.cs
index 8469b0a9f7d5..b68fd5bb46d1 100644
--- a/test/Microsoft.NET.Sdk.Razor.Tests/ScopedCssIntegrationTests.cs
+++ b/test/Microsoft.NET.Sdk.Razor.Tests/ScopedCssIntegrationTests.cs
@@ -90,7 +90,7 @@ public void CanOverrideScopeIdentifiers()
var scoped = Path.Combine(intermediateOutputPath, "scopedcss", "Styles", "Pages", "Counter.rz.scp.css");
new FileInfo(scoped).Should().Exist();
new FileInfo(scoped).Should().Contain("b-overriden");
- var generated = Path.Combine(intermediateOutputPath, "generated", "Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators", "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator", "Components_Pages_Counter_razor.g.cs");
+ var generated = Path.Combine(intermediateOutputPath, "generated", "Microsoft.CodeAnalysis.Razor.Compiler", "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator", "Components_Pages_Counter_razor.g.cs");
new FileInfo(generated).Should().Exist();
new FileInfo(generated).Should().Contain("b-overriden");
new FileInfo(Path.Combine(intermediateOutputPath, "scopedcss", "Components", "Pages", "Index.razor.rz.scp.css")).Should().NotExist();
@@ -319,7 +319,7 @@ public void Build_RemovingScopedCssAndBuilding_UpdatesGeneratedCodeAndBundle()
new FileInfo(generatedBundle).Should().Exist();
var generatedProjectBundle = Path.Combine(intermediateOutputPath, "scopedcss", "projectbundle", "ComponentApp.bundle.scp.css");
new FileInfo(generatedProjectBundle).Should().Exist();
- var generatedCounter = Path.Combine(intermediateOutputPath, "generated", "Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators", "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator", "Components_Pages_Counter_razor.g.cs");
+ var generatedCounter = Path.Combine(intermediateOutputPath, "generated", "Microsoft.CodeAnalysis.Razor.Compiler", "Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator", "Components_Pages_Counter_razor.g.cs");
new FileInfo(generatedCounter).Should().Exist();
var componentThumbprint = FileThumbPrint.Create(generatedCounter);