staticwebassets.runtime.json also includes files from referenced RCL NuGet package
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
We have the following structure:
- base RCL with shared components, let’s call it
base
- sub RCL module that referenced the
base
RCL, these contain specific components for that project, let’s call itPortal
- this is a Blazor app for the Portal module (the user Portal)
- a consuming Blazor app that consumes both RCLs
- this is a Blazor app for the Admin module (the admin Portal, that also uses user Portal components)
Since .NET 6.0 we’ve moved to use staticwebassets.runtime.json
instead of the xml predecessor.
Since we’ve updated our Blazor app to .NET 6.0, only our admin project does not want to publish anymore. Building works fine.
It throws the following error (for each static web asset you’ve got in the referenced RCL):
C:\Program Files\dotnet\sdk\6.0.102\Sdks\Microsoft.NET.Sdk.Razor\targets\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets(616,5): Error MSB3030: Could not copy the file "C:\Users\{user}\.nuget\packages\Portal\{version}\staticwebassets\{filename}.{extension}" because it was not found.
Now if we look in the staticwebassets.runtime.json
in Portal, it has the following structure:
{
"ContentRoots": [
"Portal.Components\\wwwroot\\",
"Base.Components\\{version}\\staticwebassets\\",
"Portal.Components\\obj\\Debug\\net6.0\\scopedcss\\bundle\\"
],
"Root": {
"Children": {
"app.css": {
...
},
"_content": {
"Children": {
"Base.Components": {
"Children": {
"app.css": {
...
}
}
}
}
}
}
}
}
I’ve removed bunch of data for brevity
Now, Portal does not have any wwwroot
files of its own, VS2022 does however show the files from Base.Components
, with the “linked” file icon. (If I remove the package, those files also go away).
As you can see the staticwebassets.runtime.json
just assumes that we also have the app.css
file in the portal’s wwwroot
. This is not the case. It looks like the code that generates the staticwebassets.runtime.json
does not filter out the “linked” files?
So when we publish Admin
, who references Portal
, it tries to copy files from the Portal
’s staticwebassets, even though they only live in the Base
nuget package.
The Portal reference is also a nuget package reference btw
Expected Behavior
The expected behavior would be to not have the referenced RCL files in the in the [Root].[Children]
of the referencing project’s staticwebassets.runtime.json
.
They should be in the [Root].[Children].[_content].[rcl_name].[Children]
.
Steps To Reproduce
Not really easy to reproduce. =(
.NET Version
6.0.102
Big note
With the previous XML version of the staticwebassets
it all worked fine.
Issue Analytics
- State:
- Created 2 years ago
- Comments:19 (11 by maintainers)
Top GitHub Comments
We are going to use https://github.com/dotnet/aspnetcore/issues/36880 to track these changes in https://github.com/dotnet/sdk/pull/25011 that will fix this issue.
Took me a while, but I figured it out
I added a zip file that contains all the files you need to reproduce this. As also stated in the readme, I am not sure if this is a bug or a feature.
@javiercn If you need any more information, let me know!
LinkedFilesTest.zip
For people that stumble on this issue in the future, here is a the content of the readme, this might help you:
Issue: https://github.com/dotnet/aspnetcore/issues/40317
The issue is that we have a nuget package with content in it, that is recognized as staticwebassets, but it also added a content to the nuget package.
Since it is content, the consuming projects adds it as linked resources. (see
file-from-library-1.js
in RCL2) This confuses something in the MS builder/publisher/packer (I dunno?) when copying RCL2 content to BlazorApp1, it tries to copyfile-from-library-1.js
from RCL2, but that does not exist.Reproduce
In RCL1:
Upload package to NuGet (or any other package manager)
In RCL2:
file-from-library-1.js
file.Upload package to NuGet (or any other package manager)
Add package RCL2 to the BlazorApp1, try to publish BlazorApp1.
You will now get the error message that it can’t copy
file-from-library-1.js
while building RCL2.To fix this you just have to remove
--no-restore --no-build
from thedotnet pack
command. Of course upload the nupkg again etc etc.Related issue
It looks like this issue: https://github.com/dotnet/aspnetcore/issues/36740#issuecomment-942026683 However, we’re not using
GeneratePackageOnBuild
.I don’t know if this is a feature or a bug. =)