Skip to content

Commit

Permalink
[main] Update dependencies from dotnet/razor (#38936)
Browse files Browse the repository at this point in the history
[main] Update dependencies from dotnet/razor


 - Use merged Razor compiler DLL

 - Exempt ObjectPool dependency of the Razor compiler

 - Fix extension loading
  • Loading branch information
dotnet-maestro[bot] authored Feb 24, 2024
1 parent e453f37 commit db5bdf2
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 28 deletions.
16 changes: 8 additions & 8 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,22 @@
<Sha>cc5bc6b56dc0a6e6f1ca103acff5afd9c71973ba</Sha>
<SourceBuild RepoName="aspnetcore" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Razor.Tooling.Internal" Version="7.0.0-preview.24120.8">
<Dependency Name="Microsoft.CodeAnalysis.Razor.Tooling.Internal" Version="7.0.0-preview.24123.5">
<Uri>https://github.com/dotnet/razor</Uri>
<Sha>67bd8253e308d06bf249a02911d06317d5d7b5b9</Sha>
<Sha>dbb0fb5c0b742887931ba5e78ebf49998096a748</Sha>
</Dependency>
<Dependency Name="Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal" Version="7.0.0-preview.24120.8">
<Dependency Name="Microsoft.AspNetCore.Mvc.Razor.Extensions.Tooling.Internal" Version="7.0.0-preview.24123.5">
<Uri>https://github.com/dotnet/razor</Uri>
<Sha>67bd8253e308d06bf249a02911d06317d5d7b5b9</Sha>
<Sha>dbb0fb5c0b742887931ba5e78ebf49998096a748</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Sdk.Razor.SourceGenerators.Transport" Version="7.0.0-preview.24120.8">
<Dependency Name="Microsoft.NET.Sdk.Razor.SourceGenerators.Transport" Version="7.0.0-preview.24123.5">
<Uri>https://github.com/dotnet/razor</Uri>
<Sha>67bd8253e308d06bf249a02911d06317d5d7b5b9</Sha>
<Sha>dbb0fb5c0b742887931ba5e78ebf49998096a748</Sha>
</Dependency>
<!-- Intermediate is necessary for source build. -->
<Dependency Name="Microsoft.SourceBuild.Intermediate.razor" Version="7.0.0-preview.24120.8">
<Dependency Name="Microsoft.SourceBuild.Intermediate.razor" Version="7.0.0-preview.24123.5">
<Uri>https://github.com/dotnet/razor</Uri>
<Sha>67bd8253e308d06bf249a02911d06317d5d7b5b9</Sha>
<Sha>dbb0fb5c0b742887931ba5e78ebf49998096a748</Sha>
<SourceBuild RepoName="razor" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.Extensions.FileProviders.Embedded" Version="9.0.0-preview.2.24121.1">
Expand Down
6 changes: 3 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@
</PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/razor -->
<PropertyGroup>
<MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>7.0.0-preview.24120.8</MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>
<MicrosoftCodeAnalysisRazorToolingInternalVersion>7.0.0-preview.24120.8</MicrosoftCodeAnalysisRazorToolingInternalVersion>
<MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>7.0.0-preview.24120.8</MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>
<MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>7.0.0-preview.24123.5</MicrosoftAspNetCoreMvcRazorExtensionsToolingInternalPackageVersion>
<MicrosoftCodeAnalysisRazorToolingInternalVersion>7.0.0-preview.24123.5</MicrosoftCodeAnalysisRazorToolingInternalVersion>
<MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>7.0.0-preview.24123.5</MicrosoftNETSdkRazorSourceGeneratorsTransportPackageVersion>
</PropertyGroup>
<PropertyGroup>
<!-- Dependencies from https://github.com/dotnet/wpf -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ Copyright (c) .NET Foundation. All rights reserved.

<ItemGroup>
<RazorExtension Include="MVC-3.0">
<AssemblyName>Microsoft.CodeAnalysis.Razor.Compiler.Mvc</AssemblyName>
<AssemblyFilePath>$(RazorSdkDirectoryRoot)tools\Microsoft.CodeAnalysis.Razor.Compiler.Mvc.dll</AssemblyFilePath>
<AssemblyName>Microsoft.CodeAnalysis.Razor.Compiler</AssemblyName>
<AssemblyFilePath>$(RazorSdkDirectoryRoot)tools\Microsoft.CodeAnalysis.Razor.Compiler.dll</AssemblyFilePath>
</RazorExtension>
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions src/RazorSdk/Tool/DefaultExtensionDependencyChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal class DefaultExtensionDependencyChecker : ExtensionDependencyChecker
"System",
"Microsoft.CodeAnalysis",
"Microsoft.AspNetCore.Razor",
"Microsoft.Extensions.ObjectPool"
};

private readonly ExtensionAssemblyLoader _loader;
Expand Down
25 changes: 13 additions & 12 deletions src/RazorSdk/Tool/DiscoverCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/// <summary>
/// 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).
/// </summary>
/// <remarks>
/// Needed so the Razor compiler can change its APIs without breaking legacy MVC scenarios.
Expand All @@ -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<int> ExecuteCoreAsync()
Expand Down
11 changes: 10 additions & 1 deletion src/RazorSdk/Tool/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ protected override Task<int> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit db5bdf2

Please sign in to comment.