Try to make service worker publishing csproj nicer #19007
Labels
area-blazor
Includes: Blazor, Razor Components
Done
This issue has been fixed
feature-blazor-wasm
This issue is related to and / or impacts Blazor WebAssembly
Milestone
Within the PWA template, we have this:
It's not absolutely outrageous, but it's not as elegant and approachable as we'd prefer things to be in newly-created projects. Are there any MSBuild/SDK experts who can suggest a cleaner way to achieve this? The requirements are:
<Content>
item (for examplewwwroot\service-worker.js
) should not actually get included in the publish output<Content>
item (for example,wwwroot\service-worker.published.js
) should get published, but at the path originally occupied by the first item (e.g.,wwwroot\service-worker.js
)Any suggestions gratefully received! cc @rainersigwald @nguerrera
Appendix: Things I've considered / tried
1. Same mechanism, different phrasing
I know we could "simplify" the above slightly by merging more things onto the same line (e.g., converting
TargetPath
to an attribute) but the I think that obscures things further given how long the lines would end up being.2. Different mechanism with pure msbuild
This looks nice and understandable, but doesn't work because the
AssignTargetPath
task doesn't retain existingTargetPath
metadata. It just overwrites that metadata indiscriminately.However
AssignTargetPath
does respectLink
. We can't set that statically because it would mess up the layout in Solution Explorer, but I did try setting it inside a target like this:However that doesn't work because of this unexpected behavior. It assignes the
Link
to allContent
items ignoring theUpdate
condition.3. Factoring it out into SDK
I'm aware we could define new primitives in the SDK. In the short term, that would mean "in the Blazor build targets" but in 5.0 that becomes part of the web SDK generally.
For example, we could have user syntax like this:
We would then put some logic in Blazor's publish targets to find such items and modify the set of
ContentWithTargetPath
items accordingly. I'm not keen on this because:<ReplaceOnPublish ... />
because something that general has no business being in the Blazor or web SDKs.)PublishContentFrom
notion implies we can find the corresponding<Content>
item and either update it or make it not get double-written. This is a risk because if people phrase the itemspec in a different way from its underlying representation (e.g., using an absolute path), it won't work without more subtle logic.Another possible user syntax is:
Again, this looks quite nice, but defining a new low-level primitive like this in the Blazor/web SDKs is hazardous. People will try to use it for totally different purposes, and be confused why it doesn't work the same in non-Blazor projects.
The text was updated successfully, but these errors were encountered: