-
Notifications
You must be signed in to change notification settings - Fork 10.4k
More cleaning up Blazor.Build package #17157
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
Conversation
pranavkm
commented
Nov 15, 2019
- Clean up MonoRuntime targets
- Convert executables in to tasks
- Add tests
f6a3578
to
ae63f2b
Compare
src/Components/Blazor/Build/src/Microsoft.AspNetCore.Blazor.Build.csproj
Outdated
Show resolved
Hide resolved
src/Components/Blazor/Build/src/Microsoft.AspNetCore.Blazor.Build.csproj
Outdated
Show resolved
Hide resolved
</ItemGroup> | ||
|
||
<Target Name="CopyBuildTask" BeforeTargets="Build" AfterTargets="PrepareForRun"> | ||
<!-- If you see a build warning here and you mean to update the tasks dll when building in VS, manually stop MSBuild.exe processes. --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unfortunate, but we reference this task from other samples \ apps in this project. MSBuild locks up the file. This "mitigates" it by copying the task to a different location and using that in the reference-from-source. Failures to copy are ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that while MSBuild has it locked, it's possible to build this project, but any changes to the codez won't update the running instance of MSBuild?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to let the build fail if it's not possible to update, assuming that only happens in the scenario where you did change something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assuming that only happens in the scenario where you did change something
Unfortunately that's not true. If you build the sln, which causes the tasks to lock up, and then attempt to "Rebuild", you're borked at that point. I generally don't want users to have to deal with killing the MSBuild process unless they actually happen to modifying the tasks (which should be rare).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, makes sense. It would still be great to expand the comment in the sources a bit more to capture more of the reasoning here, otherwise I think we're going to keep asking why this works like it does.
public class BuildIntegrationTest | ||
{ | ||
[Fact] | ||
public async Task Build_WithDefaultSettings_Works() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test!
src/Components/Blazor/Build/test/BuildIntegrationTests/MSBuildProcessManager.cs
Show resolved
Hide resolved
src/Components/Blazor/Build/test/BuildIntegrationTests/ProjectDirectory.cs
Show resolved
Hide resolved
public class PublishIntegrationTest | ||
{ | ||
[Fact] | ||
public async Task Publish_WithDefaultSettings_Works() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran out of emoticons to express my appreciation for this improvement.
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that this app isn't meant to run. It's got enough things in here (targeting the 3.0 release) to build and publish. But that's enough to verify that the build targets execute and do linking etc.
|
||
namespace Microsoft.AspNetCore.Blazor.Build | ||
{ | ||
internal class BootJsonWriter | ||
public class GenerateBlazorBootJson : Task |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏 👏 👏 👏 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we XML-comment this kind of public class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so.
{ | ||
var assemblyReferences = References.Select(c => Path.GetFileName(c.ItemSpec)).ToArray(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't Msbuild give you this already for ITaskItem
? Isn't that better to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We get an ItemSpec
which in our case is a path to the assembly. We could query using GetMetadata
to get the file name and extension which is what we want here, but this is just as effective.
LinkerEnabled); | ||
|
||
var bootJsonText = JsonSerializer.Serialize(data, JsonSerializerOptionsProvider.Options); | ||
File.WriteAllText(OutputPath, bootJsonText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we'll have to figure this part out 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we simply "emit" the json by hand? Given the context this is used in, it seems reasonable (specially if kept simple)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched this to DataContractJsonSerializer. My concern with handwriting this is that we now have to worry about the risk of producing bad json (due to escaping etc).
|
||
<PropertyGroup> | ||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<TargetName>Microsoft.AspNetCore.Blazor.Build.Tasks</TargetName> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it OK that the assembly name and project/dir name don't match? I mean, I understand it works technically, but this might confuse people as it doesn't match our normal conventions. Could we rename the dir and project to Microsoft.AspNetCore.Blazor.Build.Tasks
?
Update: never mind, I realise TargetName
is not the assembly name now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do something similar with the Razor.SDK. We want to keep the package name Microsoft.AspNetCore.Blazor.Build
, but by convention most task assemblies are named 'Something.Tasks`. The task assembly is generally not referenced by any code so it might not be incredibly confusing. Let me know if you feel strongly and we can figure out other options to organize this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with whatever here
src/Components/Blazor/Build/src/Microsoft.AspNetCore.Blazor.Build.csproj
Show resolved
Hide resolved
src/Components/Blazor/Build/src/Tasks/ResolveBlazorRuntimeDependencies.cs
Outdated
Show resolved
Hide resolved
@@ -6,8 +6,8 @@ | |||
</PropertyGroup> | |||
|
|||
<PropertyGroup> | |||
<BlazorToolsDir Condition="'$(BlazorToolsDir)' == ''">$(MSBuildThisFileDirectory)../tools/</BlazorToolsDir> | |||
<BlazorBuildExe>dotnet "$(BlazorToolsDir)Microsoft.AspNetCore.Blazor.Build.dll"</BlazorBuildExe> | |||
<BlazorToolsDir Condition="'$(BlazorToolsDir)' == ''">$(MSBuildThisFileDirectory)..\tools\</BlazorToolsDir> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some possibility we needed the /
due to passing the path into some Mono tooling that only understood those characters. Hopefully that's not the case and the MSBuild standardization is OK.
But if the build starts failing with this change, I hope this is a useful clue why!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far things look fine. 🤷♀
<BlazorBootJsonName>blazor.boot.json</BlazorBootJsonName> | ||
<BlazorBootJsonOutputPath>$(BaseBlazorRuntimeOutputPath)$(BlazorBootJsonName)</BlazorBootJsonOutputPath> | ||
<_BlazorBuiltInBclLinkerDescriptor>$(MSBuildThisFileDirectory)BuiltInBclLinkerDescriptor.xml</_BlazorBuiltInBclLinkerDescriptor> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to say you don't want to deal with this question, since it's a bit tangential, but I'll ask now since you're thinking about stuff in this area.
We've had a request from Mono to make it easier to build Blazor apps against a Mono build in a custom directory, instead of the Mono build bundled into our Microsoft.AspNetCore.Blazor.Mono.nupkg
.
Given an artifact like https://jenkins.mono-project.com/job/test-mono-mainline-wasm/4237/label=ubuntu-1804-amd64/Azure/processDownloadRequest/4237/ubuntu-1804-amd64/sdks/wasm/mono-wasm-b8fe43da3ed.zip extracted into a folder, could a third-party add some properties to their Blazor application (not in our repo) to set paths that would cause the build to pull in mono.js/wasm
and the Mono BCL from that external location?
They want this because it will make it far easier for them to test the effects of Mono changes on Blazor, without having to build Blazor itself from sources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ultimate ideal would be adding something like this to your csproj:
<PropertyGroup>
<DotNetWebAssemblySDKRoot>c:\me\blah\mono-wasm-b8fe43da3ed\</DotNetWebAssemblySDKRoot>
</PropertyGroup>
... and having that alone be sufficient to use this custom build of Mono WebAssembly.
Do you think that's a separate future feature, or is it easy to inline with the work you're doing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Named it DotNetWebAssemblyArtifactsRoot
. But yes that's pretty easy to do.
<_BlazorGCTPDIDistFiles Include="@(BlazorItemOutput->'%(TargetOutputPath)')" /> | ||
<_BlazorGCTPDI Include="@(_BlazorGCTPDIDistFiles)"> | ||
<TargetPath>$(BlazorPublishDistDir)$([MSBuild]::MakeRelative('$(TargetDir)dist\', %(Identity)))</TargetPath> | ||
<_BlazorGCTPDI Include="%(BlazorOutputWithTargetPath.Identity)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_BlazorGCTPDI
is an extremely obscure name. Could this be renamed to something meaningful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe he is following an obscure convention to improve msbuild performance, its Get Copy To Publish Directory Item which is the item without the associated metadata.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, as @javiercn pointed out, these are named so in the .NET SDK and we're following their poorly thought out naming convention.
<!-- We'll only reference a subset of publicly released package versions that are enough to link, build, and publish . --> | ||
<PackageReference Include="Microsoft.AspNetCore.Components" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="3.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Blazor.Mono" Version="3.1.0-preview3.19531.1" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely we don't want to hardcode any of these version numbers here, do we?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Blazor.Mono
package can be changed to use the version used by the rest of the repository. I'm not sure about the two Components references. We want to avoid referencing the actual projects both in blazor-wasm and in the 5.0 branch to avoid involving arcade's build requirements in our test projects.
In RazorSDK's tests, we use a mix of referencing shipped packages for ones that are already shipped or referencing a runtime shim.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall awesome! Just added some thoughts about removing some of the testasset duplication.
f8dd670
to
632f8f3
Compare
* Clean up MonoRuntime targets * Convert executables in to tasks * Add tests
ae63f2b
to
517a1cb
Compare
bb9338f
to
c1cc586
Compare
c6a2b0c
to
9fb10c6
Compare
b83bd2d
to
a47d0cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!