Skip to content

Replat blazor on net5 #23078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 24, 2020
Merged

Replat blazor on net5 #23078

merged 15 commits into from
Jun 24, 2020

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Jun 18, 2020

Still need to get through some test issues, but the apps work now without issues and the sdk tests are passing locally.

Things pending

  • Revive gzip compression (TBD based on discussion)
  • Fix skipped tests
  • Scramble the dotnet.js file name
  • Figure out packing for blazor.webassembly.js
  • Update templates to net5

The largest issue I noticed since the sync up today is that RuntimeIdentifer is required to be specified in the project file. The Razor SDK is imported too late to set this up correctly. I'm going to talk to the SDK folks to figure out how to not have this in the project file. Ignore that for now. We had a conversation with some folks about possibly having a Blazor WASM specific SDK. This should remedy the problem. I'll hold off on this for now.

@pranavkm pranavkm requested a review from a team June 18, 2020 07:17
@Pilchie Pilchie added the area-blazor Includes: Blazor, Razor Components label Jun 18, 2020
@pranavkm pranavkm force-pushed the prkrishn/net5-sdk branch from 23f896d to 3caf917 Compare June 19, 2020 20:04
@pranavkm pranavkm requested a review from a team June 19, 2020 20:11
@@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't bring this app forward. It seems low value and requires additional work to get the loader script functioning. Let me know if you feel strongly about keeping this.

Copy link
Member

Choose a reason for hiding this comment

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

I think it's great to remove this 👍

This project (and its tests) was created before Blazor, so we had some way to make sense of how .NET code should behave on WebAssembly, and so that if the runtime behaviors around low-level basics like exception handling, boxing, etc. varied then we'd have a way to observe that objectively.

By now, .NET on WebAssembly is well enough established that we don't have to get independent proof that the low-level basics work correctly!

@@ -63,13 +63,13 @@ protected override void InitializeAsyncCore()
WaitUntilLoaded();
}

[Fact]
[Fact(Skip = "https://github.com/dotnet/runtime/issues/38098")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Async JSInterop code paths are busted because TCS.SetResult throws


namespace Microsoft.AspNetCore.Razor.Tasks
{
public partial class GenerateServiceWorkerAssetsManifest : Task
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to boot.json, we operate on a different set of inputs during build and publish. This task has been modified to do what was previously done across multiple msbuild targets. I need to spend a little bit of time to verify, but it should be just as incremental as before.

Copy link
Member

Choose a reason for hiding this comment

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

That's great. Do you feel the test coverage we have for this is adequate? We've had multiple regressions related to SWAM and build/publish/incrementalism, perhaps because it's pretty hard to tell whether it's right just by casually running an app.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I retained all the tests from before. My plan's to go over these again and see if there are gaps and see if we could have more combination of tests (VS-style publish + build incrementalism for instance)

@@ -513,7 +513,7 @@ Copyright (c) .NET Foundation. All rights reserved.
-->
<_ExternalPublishStaticWebAsset
Include="%(StaticWebAsset.FullPath)"
Condition="'%(SourceType)' != ''">
Condition="'%(SourceType)' != '' AND '%(StaticWebAsset.CopyToPublishDirectory)' != 'Never'">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want assets such as the boot.json produced during build to be copied to the publish directory. There was a bug in these targets where it wouldn't honor the CopyToPublishDirectory setting.

Copy link
Member

@javiercn javiercn Jun 23, 2020

Choose a reason for hiding this comment

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

We shouldn't leave random stuff in the SWA definition. What problem are we trying to solve here? I'm not sure what boot.json you are referring to, blazor.boot.json? How is that not going to be an SWA?

@@ -14,4 +14,5 @@ Copyright (c) .NET Foundation. All rights reserved.
<RazorSdkCurrentVersionProps>$(MSBuildThisFileDirectory)Sdk.Razor.CurrentVersion.props</RazorSdkCurrentVersionProps>
<RazorSdkCurrentVersionTargets>$(MSBuildThisFileDirectory)Sdk.Razor.CurrentVersion.targets</RazorSdkCurrentVersionTargets>
</PropertyGroup>
</Project>

</Project>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will undo

@@ -354,6 +356,8 @@ Copyright (c) .NET Foundation. All rights reserved.

<Import Project="Microsoft.NET.Sdk.Razor.MvcApplicationPartsDiscovery.targets" Condition="'$(_TargetingNETCoreApp30OrLater)' == 'true'" />

<Import Project="Microsoft.NET.Sdk.Razor.Components.Wasm.targets" Condition="'$(_TargetingNET50OrLater)' == 'true' AND '$(UseBlazorWebAssembly)' == 'true'" />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This target gets imported far too late to set up useful defaults such as RuntimeIdentifier or the flag that tells the SDK not to append the rid to the output path. We are able to do other things such as tell it to not reference M.AspNetCore.App or do trimmed publish. One way to remedy the evaluation order issue is to add a blazor-wasm specific SDK.

@pranavkm pranavkm force-pushed the prkrishn/net5-sdk branch from 3caf917 to 5cbfd78 Compare June 19, 2020 23:44
@pranavkm pranavkm marked this pull request as ready for review June 20, 2020 00:06
@Pilchie
Copy link
Member

Pilchie commented Jun 20, 2020

👀

@pranavkm pranavkm added this to the 5.0.0-preview7 milestone Jun 21, 2020
@pranavkm pranavkm force-pushed the prkrishn/net5-sdk branch from 775b2b2 to f6a0514 Compare June 22, 2020 23:44
@pranavkm pranavkm requested a review from dougbu as a code owner June 22, 2020 23:44
@pranavkm pranavkm changed the base branch from master to release/5.0-preview7 June 22, 2020 23:44
@@ -66,69 +66,69 @@
<!-- Packages from dotnet/roslyn -->
<MicrosoftNetCompilersToolsetPackageVersion>3.7.0-4.20319.6</MicrosoftNetCompilersToolsetPackageVersion>
<!-- Packages from dotnet/runtime -->
<MicrosoftExtensionsDependencyModelPackageVersion>5.0.0-preview.7.20321.2</MicrosoftExtensionsDependencyModelPackageVersion>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please ignore. I'll rebase this once darc updates this file. Using this to verify that the latest build resolves outstanding issues with the wasm runtime.

@dougbu
Copy link
Contributor

dougbu commented Jun 23, 2020

@pranavkm I got added as a reviewer due to code ownership I believe. And, you're going to revert the changes to the file I kinda own. Is there anything here you'd like me to review?

Curiosity only: Does this help move us any closer to archiving the dotnet/blazor repo?

<FixupWebAssemblyHttpHandlerReference>true</FixupWebAssemblyHttpHandlerReference>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore.Components.WebAssembly" />
<Reference Include="System.Net.Http.Json" />

<FrameworkReference Remove="Microsoft.AspNetCore.App" />
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain what this <FrameworkReference> is for? Since StandaloneApp runs on WebAssembly, I wouldn't expect there to be references to anything from server-side ASP.NET Core.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This could be removed from the project file since the SDK removes this for you. The project targets the WebSDK and net5.0, you get an implicit reference to this framework. I filed #23259 to figure out a better way to do this.

{
Sources = Option("-s", ".cshtml files to compile", CommandOptionType.MultipleValue);
Outputs = Option("-o", "Generated output file path", CommandOptionType.MultipleValue);
CompressionLevelOption = Option("-c", "Compression level", CommandOptionType.SingleValue);
Copy link
Member

Choose a reason for hiding this comment

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

I don't really feel strongly about removing this, but I'm not aware we have any use case for having an option. We always want to use max AFAIK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They get turned down in the Razor integration tests. It makes the tests take far too long if they perform maximal compression every time.

Assert.Null(bootJsonData.resources.satelliteResources);
}

[Fact(Skip = "https://github.com/dotnet/aspnetcore/issues/22975")]
Copy link
Member

Choose a reason for hiding this comment

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

To be tracked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one's our issue.

@@ -19,6 +13,8 @@
<type fullname="System.ComponentModel.TimeSpanConverter" />
</assembly>

<assembly fullname="System.Runtime.InteropServices.JavaScript" preserve="all" />

<assembly fullname="System.Text.Json">
Copy link
Member

Choose a reason for hiding this comment

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

We might be able to drop this now (as it was working around an issue in STJ that might be fixed). Perfectly fine if you don't want to mess with extra stuff in this PR of course though!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I filed #23262 to see if we can get these resolved by the BCL.

@@ -0,0 +1,482 @@
<!--
Copy link
Member

Choose a reason for hiding this comment

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

Since there's no diff associated with this file, it's pretty hard to CR and reason about what's changing.

Do you think you'd be able to summarize the high-level points about what's being done differently here now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "Build" part of the pipeline is pretty close to what we had in Blazor.MonoRuntime.targets. We gather inputs, generate a blazor.boot.json, optionally a server worker manifest, add things to StaticWebAssets, and copy files to $(OutputPath)wwwroot. We no longer run the linker or compression during, so those parts of the pipeline are removed.

When publishing standalone, the linker operates on ResolvedFileToPublish. These files are inputs to compression, published PWA manifest, and the published blazor.boot.json. It's pretty much like build, but with different inputs. To make our lives easier, rather than the targets calculating values (such as BootManifestResourceType), the tasks do it. This saves us from duplicating a lot of MSBuild code between the build and publish targets.

Publishing P2P is a bit more interesting. A dotnet publish on a hosted server project, only results in a dotnet build on the referenced client project. This is how MSBuild works. But we want this to produce a "published" WASM app. There is an escape hatch though. MSBuild also calls GetCopyToPublishDirectoryItems on referenced projects to get files to copy to the server's outputs. We use this to do a publish on the client project and copy them over to the server.

{
[Fact]
[Fact(Skip = "TODO fix this")]
Copy link
Member

Choose a reason for hiding this comment

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

Not sure if you're planning to handle this as part of the PR or later. If later, could you add it to the list of things to be tracked for follow-up? Presumably we could have one big issue listing them all.

@@ -26,6 +27,9 @@

<!-- Working around an issue in XDT transforms -->
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

<!-- Turn down the compression level for brotli -->
<_BlazorBrotliCompressionLevel>NoCompression</_BlazorBrotliCompressionLevel>
Copy link
Member

@SteveSandersonMS SteveSandersonMS Jun 23, 2020

Choose a reason for hiding this comment

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

Why? To make CI builds faster? Does it make enough of a difference to be worthwhile?

Also, our benchmarking relies on getting realistic brotli-compressed sizes. Just want to check this isn't going to interfere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is specifically for the integration tests. It takes kinda long: #21382

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

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

This is looking really great! Thanks for figuring out all these details. It's cool to see things getting simpler as part of this process.

Not sure how close you are to considering this PR done so I'll await a further ping when you're ready for sign-off.

<!-- Disable compression in this project so that we can validate that it can be disabled -->
<BlazorEnableCompression>false</BlazorEnableCompression>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
Copy link
Member

Choose a reason for hiding this comment

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

Did we get around the publish hosted bit by forcing the RID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought I'd tried this, but there's an issue where dotnet publish -r [rid] doesn't work. The restore that runs as part of publish messes things up. I'll talk to SDK folks about this and see what they recommend doing here.

var razorSDKarg = string.IsNullOrEmpty(RazorSdkDirectoryRoot) ? string.Empty : $"/p:RazorSdkDirectoryRoot={RazorSdkDirectoryRoot}";

using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {razorSDKarg} {additionalArgs}", packageOptions);
using var result = ProcessEx.Run(Output, TemplateOutputDir, DotNetMuxer.MuxerPathOrDefault(), $"build --no-restore -c Debug /bl {additionalArgs}", packageOptions);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need the rid now here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Further up? WASM produces outputs in a RID based directory. There's a flag to turn it off, but does not work: dotnet/sdk#12114

@@ -39,6 +39,7 @@ internal class Application : CommandLineApplication
Commands.Add(new ShutdownCommand(this));
Commands.Add(new DiscoverCommand(this));
Commands.Add(new GenerateCommand(this));
Commands.Add(new BrotliCompressCommand(this));
Copy link
Member

Choose a reason for hiding this comment

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

Does this ties compression to the Razor compiler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To the rzc tool, but it does not remote calls to the server process. It doesn't seem problematic as yet, but we can come back to this if there are side-effects to it.

@@ -269,7 +269,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<ItemGroup>
<StaticWebAsset
Include="@(_ReferencedProjectStaticWebAssets)"
KeepMetadata="ContentRoot;BasePath;RelativePath;SourceId;SourceType" />
KeepMetadata="ContentRoot;BasePath;RelativePath;SourceId;SourceType;CopyToPublishDirectory" />
Copy link
Member

Choose a reason for hiding this comment

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

SWAs should only have ContentRoot;BasePath;RelativePath;SourceId;SourceType I want to avoid them becoming a random bag of properties.

Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

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

Looks great!

I want us to discuss the issue with SWA, but other than that looks fine.

@dougbu dougbu added the tell-mode Indicates a PR which is being merged during tell-mode label Jun 23, 2020
@pranavkm pranavkm force-pushed the prkrishn/net5-sdk branch from f6a0514 to e7c1ced Compare June 23, 2020 18:49
pranavkm and others added 2 commits June 23, 2020 11:53
…0622.6

System.ComponentModel.Annotations , System.Diagnostics.DiagnosticSource , System.Diagnostics.EventLog , Microsoft.Extensions.Logging.Configuration , Microsoft.Extensions.Logging.Console , Microsoft.Extensions.Logging.Debug , Microsoft.Extensions.Logging.EventLog , Microsoft.Extensions.Logging.EventSource , Microsoft.Extensions.Logging.TraceSource , Microsoft.Extensions.Options , Microsoft.Extensions.Options.ConfigurationExtensions , Microsoft.Extensions.Options.DataAnnotations , Microsoft.Extensions.Primitives , Microsoft.Extensions.Logging.Abstractions , Microsoft.Extensions.Logging , Microsoft.Extensions.Internal.Transport , Microsoft.Extensions.Http , Microsoft.Extensions.Caching.Abstractions , Microsoft.Extensions.Caching.Memory , Microsoft.Extensions.Configuration , Microsoft.Extensions.Configuration.Abstractions , Microsoft.Extensions.Configuration.Binder , Microsoft.Extensions.Configuration.CommandLine , Microsoft.Extensions.Configuration.EnvironmentVariables , Microsoft.Extensions.Configuration.FileExtensions , Microsoft.Extensions.Configuration.Ini , Microsoft.Extensions.Configuration.Json , Microsoft.Extensions.Configuration.UserSecrets , Microsoft.Extensions.DependencyInjection , Microsoft.Extensions.DependencyInjection.Abstractions , Microsoft.Extensions.DependencyModel , Microsoft.Extensions.FileProviders.Abstractions , Microsoft.Extensions.FileProviders.Composite , Microsoft.Extensions.FileProviders.Physical , Microsoft.Extensions.FileSystemGlobbing , Microsoft.Extensions.HostFactoryResolver.Sources , Microsoft.Extensions.Hosting , Microsoft.Extensions.Hosting.Abstractions , Microsoft.Extensions.Configuration.Xml , Microsoft.NETCore.App.Runtime.win-x64 , Microsoft.NETCore.Platforms , Microsoft.Win32.Registry , Microsoft.Win32.SystemEvents , Microsoft.NETCore.App.Internal , Microsoft.NETCore.App.Ref , System.Drawing.Common , System.ServiceProcess.ServiceController , System.Text.Encodings.Web , System.Text.Json , System.Threading.Channels , System.Windows.Extensions , System.Security.Principal.Windows , System.Security.Permissions , System.Security.Cryptography.Xml , System.IO.Pipelines , System.Net.Http.Json , System.Net.Http.WinHttpHandler , System.Net.WebSockets.WebSocketProtocol , System.Reflection.Metadata , System.Runtime.CompilerServices.Unsafe , System.Security.Cryptography.Cng , System.Security.Cryptography.Pkcs
 From Version 5.0.0-preview.7.20321.2 -> To Version 5.0.0-preview.7.20322.6
@pranavkm pranavkm force-pushed the prkrishn/net5-sdk branch from e7c1ced to b7161e3 Compare June 23, 2020 18:53
Copy link
Contributor

@mkArtakMSFT mkArtakMSFT left a comment

Choose a reason for hiding this comment

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

Let's get this merged so we can unblock our partners.
Please address any follow-up feedback through separate PRs, as this is pretty large already.

@mkArtakMSFT mkArtakMSFT merged commit f6a6e4b into release/5.0-preview7 Jun 24, 2020
@mkArtakMSFT mkArtakMSFT deleted the prkrishn/net5-sdk branch June 24, 2020 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components tell-mode Indicates a PR which is being merged during tell-mode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants