Skip to content
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

Error BLAZOR102 when using CSS preprocessing #39344

Closed
1 task done
JohnKiller opened this issue Jan 6, 2022 · 11 comments
Closed
1 task done

Error BLAZOR102 when using CSS preprocessing #39344

JohnKiller opened this issue Jan 6, 2022 · 11 comments
Labels
area-blazor Includes: Blazor, Razor Components enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-css-isolation This issue is related to CSS Isolation feature ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@JohnKiller
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Follow up of #38374 I've successfully managed to use the documentation to copy compiled files to the wwwroot folder using MSBuild.

Now I would like to do the same with Blazor scoped css, but every tutorial I've found just places the compiled CSS file inside the git repository instead of the recommended obj/ folder.

I've update my repo here https://github.com/JohnKiller/TestCopyFile

Inside RazorClassLibrary1/RazorClassLibrary1.csproj I've placed a fake compilation step that just copies the scss in the obj/ folder and then includes it:

<Target Name="NpmRunBuild" BeforeTargets="AssignTargetPaths" Inputs="Component1.razor.scss" Outputs="$(IntermediateOutputPath)Component1.razor.css">
	<Exec Command="copy Component1.razor.scss $(IntermediateOutputPath)Component1.razor.css" />

	<ItemGroup>
		<Content Include="$(IntermediateOutputPath)Component1.razor.css" Link="Component1.razor.css" />
	</ItemGroup>
</Target>

But this is the error I get:

obj\Debug\net6.0\Component1.razor.css : error BLAZOR102: The scoped css file 'obj\Debug\net6.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

To me it looks like since the path is inside obj\Debug the framework misinterprets the path to be outside the component project location and refuses to bundle it.

Expected Behavior

I would like this solution to work so I can avoid adding the compiled css file to the git repo and keep only the source scss. Using .gitignore is not an option because it causes the problem described in #38374

Steps To Reproduce

Build https://github.com/JohnKiller/TestCopyFile

Exceptions (if any)

obj\Debug\net6.0\Component1.razor.css : error BLAZOR102: The scoped css file 'obj\Debug\net6.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

.NET Version

6.0.101

Anything else?

No response

@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Jan 6, 2022
@TanayParikh TanayParikh added the feature-css-isolation This issue is related to CSS Isolation feature label Jan 6, 2022
@mkArtakMSFT mkArtakMSFT added enhancement This issue represents an ask for new feature or an enhancement to an existing one and removed feature-css-isolation This issue is related to CSS Isolation feature labels Jan 6, 2022
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Jan 6, 2022
@ghost
Copy link

ghost commented Jan 6, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@TanayParikh TanayParikh added the feature-css-isolation This issue is related to CSS Isolation feature label Jan 6, 2022
@althepal78
Copy link

I don't know why I am getting this stupid ass message I am not using blazor at all wtf

@iykeypat
Copy link

error BLAZOR102: The scoped css file 'obj\Debug\net6.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

Solution: I recreated the razor component with a different name, copied my code to it, scoped the css file again and copied the css from the former one to it and voila, the error stopped.

@Albiniivari
Copy link

Also having this issue at my work. The generated Scss files stays after switching branches, and thus creates this error. Is any solution found?

@KurtGarrettALS
Copy link

Same issue as reported above . To test; I created new Blazor Server solution targeting .net 6. Then created Razor component CustomNotFound.razor and then CustomNotFound.razor.css. VS attaches the css file correctly but then throws error:

Severity Code Description Project File Line Suppression State
Error BLAZOR102 The scoped css file 'Pages\CustomNotFound.razor.css' was defined but no associated razor component or view was found for it. CustomerService C:\VSApps\Development\CustomerService\CustomerService\Pages\CustomNotFound.razor.css 1

ScopedCssErrorScreenshot

@rmeise
Copy link

rmeise commented Jun 22, 2023

Same error as @KurtGarrettALS , @Albiniivari and others!

my solution: deleted the component that was giving me the problem and restarted VS, recreate the component with new name!

@manojdcoder
Copy link

I had the same issue, was compiling my Sass files before ResolveScopedCssInputs, then added the output to content.

I think ResolveScopedCssInputs target itself takes care of identifying the CSS files, so when I removed the duplicate inclusion on my end the issue was resolved.

@mkArtakMSFT mkArtakMSFT modified the milestones: Backlog, BlazorPlanning Nov 5, 2023
@mkArtakMSFT mkArtakMSFT modified the milestones: Planning: WebUI, Backlog Nov 19, 2023
@dotnet dotnet deleted a comment Nov 19, 2023
@schwindy
Copy link

schwindy commented Mar 7, 2024

I had a similar error, except it was for a .js file.

In my case, I was running dotnet publish src/example/example.csproj -o path/to/publish. The key was the -o, using a "custom output directory".

Using -o, the error always occurred if I ran dotnet publish twice in a row. The only way to fix it was to manually delete the path/to/publish myself. The next publish would work, and the cycle would repeat.

By removing the -o from my dotnet publish, it caused the output of the build to be published to ./bin/Release/net8.0/publish. And the error does not occur when attempting to re-publish.

Summed up, by leaving -o as default, the error went away. 🐒 I am somewhat new to .net but that does not seem intended. Hope this helps someone else, and that someone can explain why this is the case.

@javiercn
Copy link
Member

javiercn commented Jun 3, 2024

The solution is to use ResolveScopedCssInputs as inidicated #39344 (comment)

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Jun 3, 2024
@JohnKiller
Copy link
Author

I've updated https://github.com/JohnKiller/TestCopyFile to use ResolveScopedCssInputs as suggested. It fails with:

BLAZOR102 The scoped css file 'obj\Debug\net7.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

Copy link
Contributor

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@dotnet-policy-service dotnet-policy-service bot removed this from the Backlog milestone Jun 4, 2024
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 enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-css-isolation This issue is related to CSS Isolation feature ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests