Skip to content

Commit 217a8e0

Browse files
authored
Cherry pick extensions fix (#39306)
2 parents 5cde8c0 + ac59385 commit 217a8e0

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

src/RazorSdk/Tool/DiscoverCommand.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ protected override bool ValidateArguments()
9696

9797
private const string RazorCompilerFileName = "Microsoft.CodeAnalysis.Razor.Compiler.dll";
9898

99-
internal static string GetRazorCompilerPath()
100-
=> Path.Combine(Path.GetDirectoryName(typeof(Application).Assembly.Location), RazorCompilerFileName);
101-
10299
/// <summary>
103100
/// Replaces the assembly for MVC extension with the one shipped alongside SDK (as opposed to the one from NuGet).
104101
/// </summary>
@@ -144,16 +141,8 @@ protected override Task<int> ExecuteCoreAsync()
144141
return Task.FromResult(ExitCodeFailure);
145142
}
146143

147-
// Loading all of the extensions should succeed as the dependency checker will have already
148-
// loaded them.
149-
var extensions = new RazorExtension[ExtensionNames.Values.Count];
150-
for (var i = 0; i < ExtensionNames.Values.Count; i++)
151-
{
152-
extensions[i] = new AssemblyExtension(ExtensionNames.Values[i], Parent.Loader.LoadFromPath(ExtensionFilePaths.Values[i]));
153-
}
154-
155144
var version = RazorLanguageVersion.Parse(Version.Value());
156-
var configuration = RazorConfiguration.Create(version, Configuration.Value(), extensions);
145+
var configuration = new RazorConfiguration(version, Configuration.Value(), Extensions: []);
157146

158147
var result = ExecuteCore(
159148
configuration: configuration,
@@ -176,6 +165,8 @@ private int ExecuteCore(RazorConfiguration configuration, string projectDirector
176165

177166
var engine = RazorProjectEngine.Create(configuration, RazorProjectFileSystem.Empty, b =>
178167
{
168+
b.RegisterExtensions();
169+
179170
b.Features.Add(new DefaultMetadataReferenceFeature() { References = metadataReferences });
180171
b.Features.Add(new CompilationTagHelperFeature());
181172
b.Features.Add(new DefaultTagHelperDescriptorProvider());

src/RazorSdk/Tool/GenerateCommand.cs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,8 @@ protected override Task<int> ExecuteCoreAsync()
7474
return Task.FromResult(ExitCodeFailure);
7575
}
7676

77-
// Loading all of the extensions should succeed as the dependency checker will have already
78-
// loaded them.
79-
var extensions = new RazorExtension[ExtensionNames.Values.Count];
80-
string razorCompilerPath = null;
81-
for (var i = 0; i < ExtensionNames.Values.Count; i++)
82-
{
83-
// If the extension is the Razor compiler, we'll use the referenced assembly (instead of the SDK one).
84-
// Otherwise the extension's ProvideRazorExtensionInitializerAttribute would be different from the AssemblyExtension's one,
85-
// hence the extension would not be loaded properly.
86-
razorCompilerPath ??= DiscoverCommand.GetRazorCompilerPath();
87-
var assembly = string.Equals(ExtensionFilePaths.Values[i], razorCompilerPath, StringComparison.OrdinalIgnoreCase)
88-
? typeof(AssemblyExtension).Assembly
89-
: Parent.Loader.LoadFromPath(ExtensionFilePaths.Values[i]);
90-
91-
extensions[i] = new AssemblyExtension(ExtensionNames.Values[i], assembly);
92-
}
93-
9477
var version = RazorLanguageVersion.Parse(Version.Value());
95-
var configuration = RazorConfiguration.Create(version, Configuration.Value(), extensions);
78+
var configuration = new RazorConfiguration(version, Configuration.Value(), Extensions: []);
9679

9780
var sourceItems = GetSourceItems(
9881
Sources.Values, Outputs.Values, RelativePaths.Values,
@@ -203,6 +186,8 @@ private int ExecuteCore(
203186

204187
var engine = RazorProjectEngine.Create(configuration, compositeFileSystem, b =>
205188
{
189+
b.RegisterExtensions();
190+
206191
b.Features.Add(new StaticTagHelperFeature() { TagHelpers = tagHelpers, });
207192
b.Features.Add(new DefaultTypeNameFeature());
208193

0 commit comments

Comments
 (0)