question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

staticwebassets.runtime.json also includes files from referenced RCL NuGet package

See original GitHub issue

Is 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 it Portal
    • 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:closed
  • Created 2 years ago
  • Comments:19 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, May 13, 2022

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.

1reaction
BasBakker91commented, Feb 22, 2022

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 copy file-from-library-1.js from RCL2, but that does not exist.

Reproduce

In RCL1:

  • dotnet restore
  • dotnet build -c release --no-restore
  • dotnet pack --include-symbols --no-restore --no-build -c Release

Upload package to NuGet (or any other package manager)

I did NuGet, see: https://www.nuget.org/packages/LinkedFilesTestRCL1/1.1.0

In RCL2:

  • Add package reference
  • in wwwroot you now have a linked file-from-library-1.js file.
  • dotnet restore
  • dotnet build -c release --no-restore
  • dotnet pack --include-symbols --no-restore --no-build -c Release

Upload package to NuGet (or any other package manager)

I did NuGet, see: https://www.nuget.org/packages/LinkedFilesTestRCL2/1.1.0

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.

Could not copy the file "C:\Users\Bas\.nuget\packages\linkedfilestestrcl2\1.1.0\staticwebassets\file-from-library-1.js" because it was not found

To fix this you just have to remove --no-restore --no-build from the dotnet 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. =)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuget package content files not served when deployed
1 Answer. They work fine when I directly reference RCL project, but when packed with NuGet and installed does not work any more....
Read more >
Reusable Razor UI in class libraries with ASP.NET Core
Explains how to create reusable Razor UI using partial views in a class library in ASP.NET Core.
Read more >
ASP.NET Core Razor SDK
An RCL that's used to build Blazor ( .razor ) files minimally requires a reference to the Microsoft.AspNetCore.Components package.
Read more >
Active questions tagged nuget-package - Stack Overflow ...
When I inspect the nuget packages, I can see that they reference the common package. Is there a way that I can get...
Read more >
Working with Razor Class Libraries in ASP.NET Core
NET Core 2.1 as a way to package and distribute UI components to be referenced ... The Identity UI RCL includes the Razor...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found