Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>06d7179e0a2ad184610fb9659ea35c7da8f47305</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" Version="4.8.0-3.23475.1">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>06d7179e0a2ad184610fb9659ea35c7da8f47305</Sha>
</Dependency>
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="4.8.0-3.23475.1">
<Uri>https://github.com/dotnet/roslyn</Uri>
<Sha>06d7179e0a2ad184610fb9659ea35c7da8f47305</Sha>
Expand Down
1 change: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<MicrosoftNetCompilersToolsetPackageVersion>4.8.0-3.23475.1</MicrosoftNetCompilersToolsetPackageVersion>
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>4.8.0-3.23475.1</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>4.8.0-3.23475.1</MicrosoftCodeAnalysisExternalAccessRazorPackageVersion>
<MicrosoftCodeAnalysisExternalAccessRazorCompilerPackageVersion>4.8.0-3.23475.1</MicrosoftCodeAnalysisExternalAccessRazorCompilerPackageVersion>
<MicrosoftCodeAnalysisCommonPackageVersion>4.8.0-3.23475.1</MicrosoftCodeAnalysisCommonPackageVersion>
<MicrosoftCodeAnalysisCSharpPackageVersion>4.8.0-3.23475.1</MicrosoftCodeAnalysisCSharpPackageVersion>
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>4.8.0-3.23475.1</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
Expand Down
1 change: 0 additions & 1 deletion src/Compiler/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="$(MicrosoftCodeAnalysisCommonPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="$(MicrosoftCodeAnalysisCSharpPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="$(MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" Version="$(MicrosoftCodeAnalysisExternalAccessRazorCompilerPackageVersion)" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion)" />
<PackageVersion Include="Microsoft.CSharp" Version="$(MicrosoftCSharpVersion)" />
<PackageVersion Include="Microsoft.Css.Parser" Version="$(MicrosoftCssParserVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@
<ExcludeFromSourceBuild>false</ExcludeFromSourceBuild>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" ExcludeAssets="all" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.csproj" />
<ProjectReference Include="..\tools\Microsoft.CodeAnalysis.Razor.Tooling.Internal\Microsoft.CodeAnalysis.Razor.Tooling.Internal.csproj" />
</ItemGroup>

<Target Name="PackLayout" BeforeTargets="$(GenerateNuspecDependsOn)">
<ItemGroup>
<Content Include="$(PkgMicrosoft_CodeAnalysis_ExternalAccess_RazorCompiler)\lib\netstandard2.0\*.dll" PackagePath="\source-generators" />
<Content Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators\$(Configuration)\netstandard2.0\*.*" Exclude="$(ArtifactsBinDir)**\*.pdb" PackagePath="\source-generators" />
<Content Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Razor.Tooling.Internal\$(Configuration)\netstandard2.0\Microsoft.Extensions.ObjectPool.dll" PackagePath="\source-generators" />
<Content Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Razor.Tooling.Internal\$(Configuration)\netstandard2.0\System.Collections.Immutable.dll" PackagePath="\source-generators" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />

<!-- IMPORTANT: Ensure all dependencies are embedded in the transport and toolset package. -->
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
.WithLambdaComparer((old, @new) => old.Left.Equals(@new.Left) && old.Right.SequenceEqual(@new.Right))
.Combine(razorSourceGeneratorOptions);

// Currently unused. See https://github.com/dotnet/roslyn/issues/71024.
var razorHostOutputsEnabled = analyzerConfigOptions.CheckGlobalFlagSet("EnableRazorHostOutputs");
var withOptionsDesignTime = withOptions.EmptyWhen(razorHostOutputsEnabled, false);

Expand Down Expand Up @@ -302,16 +303,6 @@ public void Initialize(IncrementalGeneratorInitializationContext context)

context.AddSource(hintName, csharpDocument.GeneratedCode);
});

// ExternalAccess.RazorCompiler does not have IVT to the new assembly.
// https://github.com/dotnet/razor/issues/8400
// context.RegisterHostOutput(processed(designTime: true), static (context, pair, _) =>
// {
// var (filePath, document) = pair;
// var hintName = GetIdentifierFromPath(filePath);
// context.AddOutput(hintName + ".rsg.cs", document.CodeDocument.GetCSharpDocument().GeneratedCode);
// context.AddOutput(hintName + ".rsg.html", document.CodeDocument.GetHtmlDocument().GeneratedCode);
// });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
</PackageDescription>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler" ExcludeAssets="all" GeneratePathProperty="true" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.csproj" PrivateAssets="all" />
<ProjectReference Include="..\tools\Microsoft.CodeAnalysis.Razor.Tooling.Internal\Microsoft.CodeAnalysis.Razor.Tooling.Internal.csproj" PrivateAssets="all"/>
Expand All @@ -38,7 +34,6 @@

<Target Name="PackLayout" BeforeTargets="$(GenerateNuspecDependsOn)">
<ItemGroup>
<Content Include="$(PkgMicrosoft_CodeAnalysis_ExternalAccess_RazorCompiler)\lib\netstandard2.0\*.dll" PackagePath="\source-generators" />
<Content Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators\$(Configuration)\$(TargetFramework)\*.dll" PackagePath="\source-generators" />
<Content Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Razor.Tooling.Internal\$(Configuration)\$(TargetFramework)\Microsoft.Extensions.ObjectPool.dll" PackagePath="\source-generators" />
<Content Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Razor.Tooling.Internal\$(Configuration)\$(TargetFramework)\System.Collections.Immutable.dll" PackagePath="\source-generators" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,99 +131,6 @@ public class MyModel { }
Assert.Equal(2, result.GeneratedSources.Length);
}

[Fact(Skip = "Host outputs disabled - https://github.com/dotnet/razor/issues/8400")]
public async Task SourceGenerator_RazorFiles_DesignTime()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we deleting these tests? I get that we're going to switch to reflection, but we still want the underlying functionality, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code's been disabled since we renamed the DLLs. It seems like it's going to remain off until the tooling team fixes the in process loading code and that wont' land until very late 17.9. As such we thought just delete the behavior entirely for 17.9 and bring back in 17.10 once we're in same process, the EA DLL saga is behind us and we're ready to move forward with actuallyusing this.

Copy link
Member Author

@jjonescz jjonescz Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code cannot stay since the reference is removed, so it doesn't compile (even the test uses the EA DLL to verify the expected host outputs). When we want to bring back the test, we can dig it from Git history.

{
// Arrange
var project = CreateTestProject(new()
{
["Pages/Index.razor"] = "<h1>Hello world</h1>",
});

var compilation = await project.GetCompilationAsync();
var (driver, additionalTexts, optionsProvider) = await GetDriverWithAdditionalTextAndProviderAsync(project, hostOutputs: true);

// Enable design-time.
var options = optionsProvider.Clone();
options.TestGlobalOptions["build_property.RazorDesignTime"] = "true";
options.TestGlobalOptions["build_property.EnableRazorHostOutputs"] = "true";
var driver2 = driver.WithUpdatedAnalyzerConfigOptions(options);

var result = RunGenerator(compilation!, ref driver2);

var pageOutput =
@"#pragma checksum ""Pages/Index.razor"" ""{ff1816ec-aa5e-4d10-87f7-6f4963833460}"" ""6b5db227a6aa2228c777b0771108b184b1fc5df3""
// <auto-generated/>
#pragma warning disable 1591
namespace MyApp.Pages
{
#line hidden
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
public partial class Index : global::Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.AddMarkupContent(0, ""<h1>Hello world</h1>"");
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
";
result.VerifyPageOutput(pageOutput);

result.VerifyHostOutput(
(@"Pages_Index_razor.rsg.cs", @"// <auto-generated/>
#pragma warning disable 1591
namespace MyApp.Pages
{
#line hidden
using global::System;
using global::System.Collections.Generic;
using global::System.Linq;
using global::System.Threading.Tasks;
using global::Microsoft.AspNetCore.Components;
public partial class Index : global::Microsoft.AspNetCore.Components.ComponentBase
{
#pragma warning disable 219
private void __RazorDirectiveTokenHelpers__() {
}
#pragma warning restore 219
#pragma warning disable 0414
private static object __o = null;
#pragma warning restore 0414
#pragma warning disable 1998
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
}
#pragma warning restore 1998
}
}
#pragma warning restore 1591
"),
(@"Pages_Index_razor.rsg.html", @"<h1>Hello world</h1>"));

Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedSources);

// Enable design-time without host outputs.
options = optionsProvider.Clone();
options.TestGlobalOptions["build_property.RazorDesignTime"] = "true";
driver2 = driver.WithUpdatedAnalyzerConfigOptions(options);

result = RunGenerator(compilation!, ref driver2);
result.VerifyPageOutput(pageOutput);
result.VerifyHostOutput();

Assert.Empty(result.Diagnostics);
Assert.Single(result.GeneratedSources);
}

[Fact]
public async Task SourceGeneratorEvents_RazorFiles_Works()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.ExternalAccess.RazorCompiler;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyModel;
Expand Down Expand Up @@ -421,29 +420,6 @@ public static GeneratorRunResult VerifyPageOutput(this GeneratorRunResult result
return result;
}

public static GeneratorRunResult VerifyHostOutput(this GeneratorRunResult result, params (string hintName, string text)[] expectedOutputs)
{
if (expectedOutputs.Length == 1 && string.IsNullOrWhiteSpace(expectedOutputs[0].text))
{
Assert.True(false, GenerateExpectedHostOutput(result));
}
else
{
var hostOutputs = result.GetHostOutputs();
Assert.Equal(expectedOutputs.Length, hostOutputs.Length);
for (int i = 0; i < hostOutputs.Length; i++)
{
var expectedOutput = expectedOutputs[i];
var actualOutput = hostOutputs[i];

Assert.Equal(expectedOutput.hintName, actualOutput.Key);
Assert.Equal(expectedOutput.text, actualOutput.Value, ignoreWhiteSpaceDifferences: true);
}
}

return result;
}

private static string CreateBaselineDirectory(string testPath, string testName)
{
var baselineDirectory = Path.Join(
Expand Down Expand Up @@ -524,22 +500,6 @@ private static string GenerateExpectedPageOutput(GeneratorRunResult result)
return sb.ToString();
}

private static string GenerateExpectedHostOutput(GeneratorRunResult result)
{
StringBuilder sb = new StringBuilder("Generated Host Output:").AppendLine().AppendLine();
var hostOutputs = result.GetHostOutputs();
for (int i = 0; i < hostOutputs.Length; i++)
{
if (i > 0)
{
sb.AppendLine(",");
}
sb.Append("(@\"").Append(hostOutputs[i].Key.Replace("\"", "\"\"")).Append("\", ");
sb.Append("@\"").Append(hostOutputs[i].Value.Replace("\"", "\"\"")).Append("\")");
}
return sb.ToString();
}

public static GeneratorRunResult VerifyOutputsMatch(this GeneratorRunResult actual, GeneratorRunResult expected, params (int index, string replacement)[] diffs)
{
Assert.Equal(actual.GeneratedSources.Length, expected.GeneratedSources.Length);
Expand Down