-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Blazor Server scoped CSS missing after dotnet publish #40873
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
Comments
@dynsim thanks for contacting us.
None of this matters since you are publishing the app. Static web assets only plays a role when you run your app inside VS or with the CLI, there is no runtime component once the app has been published. |
@dynsim what you are describing sounds very strange. Could you capture and share the binlog with us by adding /bl to the publish command? |
Hi @dynsim. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@javiercn: I agree, very strange indeed! Please find attached the build bin log. To add further to the mystery, I just tried to set up a new Azure Pipeline using the sample GitHub project as a base for the pipeline (we use Azure Repos as repository manager in the pipeline that is not working). In that pipeline, it works as expected! They share the exact same pipeline configuration. |
@dynsim something in your config is causing the project content not to be picked up. It's not clear to me what's going on, but there are no css files in the content/none item groups, which is the cause for this. Are the files present on the folder to begin with? (I can't think of anything else other than the commit/checkout not having the files to begin with) |
Hi @dynsim. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@javiercn: Thanks a lot for your quick response and helpful insight. Your guidance pointed us in the right direction, and we have now identified the issue. I will briefly explain our findings below for anyone that may encounter the same in the future. We were so focused on the bundle CSS ( The issue in our production app was a little bit different, however. We recently changed from using regular .CSS files to using Sass files, and for that reason, we removed our .CSS files from source control and added a .gitignore rule for these files, as we essentially saw them as build output files. (We then re-used that .gitignore file for the sample project that we sent the binlog from, which was why the .CSS files were not checked into that repo...) We then added a Sass builder as a NuGet reference (we use LibSassBuilder), that compiles the .CSS files as part of the build process. However, this does not seem to be sufficient for the .CSS files to be included in the published files - they need to be there before the publish command is executed. It's not exactly clear to us if this is the expected behavior, or if there is something we are missing. I don't know if you can see a logical explanation for that? Maybe that package compiles the files too late in the build process? We tried with a couple of other packages (e.g. Delegate.SassBuilder, which is suggested in the docs), but that produced the same result, even though the docs states that As a resolution, we chose to add a step prior to the publish step in our Azure Pipelines, compiling the CSS using the LibSassBuilder-Tool, and now it works as expected, as the .CSS are present when the publish starts. We tried invoking the Sass generator tool as a pre-build event, but this does not seem to be sufficient either. Essentially this also means that the issue is not related to Azure Pipelines, as if we freshly clone the repo and run We have updated the sample project in GitHub to reflect the changes, but what we did exactly was: We added a {
"version": 1,
"isRoot": true,
"tools": {
"libsassbuilder-tool": {
"version": "2.0.0",
"commands": ["lsb"]
}
}
} And then this is a snippet of our Azure Pipelines configuration, where we added the call to ...
- script: dotnet tool restore
displayName: 'Restore .NET Tools'
# The CSS files needs to be compiled before starting publish
# Else they will not be included in published files
- script: 'dotnet lsb'
displayName: 'Compile CSS files'
- task: DotNetCoreCLI@2
displayName: 'Prepare Solution for Publish'
inputs:
command: 'publish'
projects: '$(solutionName)'
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: false
... Thanks again for helping us identify the issue. |
@dynsim thanks for the additional details.
This seems like an issue in how the CSS files are built. It normally means that the files got generated too late. We created a package in November and did a blog post around the time to help make this scenario easier. You can check the details here In general, I would recommend against generating build artifacts in a location that makes them susceptible to be included in source control or as part of the build inputs. This is a bit different in .NET Core vs other build systems because the inputs are in many cases implicitly added (you don't need to list them all and there are "default patterns" that discover them) so whenever possible, it is best to place the outputs in a separate folder, (like the obj folder). In general, if you want your files/assets to be considered, they should be generated before We are also looking to productionize this scenario (that is, making easier to integrate third-party client asset toolchains) in 7.0 and are gathering feedback/interest about it, so please take a moment to upvote this issue if this is something you care about. I think the behavior here is expected and that additional steps are needed to correctly integrate within the build process, if the guidance provided above doesn't help, please update the repro and let us know, and we can take another look to see if there's something amiss. |
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. |
Is there an existing issue for this?
Describe the bug
I'm not sure this is the correct repository to post this issue in, but I have not been able to find any other place that seems more fit.
Our issue is: When we run
dotnet publish
for our Blazor Server App in Azure Pipelines, we are missing some key styles in the outputpublish
folder. If we use just a default Blazor Server project template from .NET 6, the missing files in thepublish\wwwroot
folder include the following:{AssemblyName}.styles.css
css\site.css
css\bootstrap\bootstrap.min.css
css\open-iconic\font\css\open-iconic-bootstrap.min.css
If we run
dotnet publish
with the same parameters on our local machines and in GitHub Actions, it is working as expected and we get the correct stylesheet files in thepublish
folder.It seems that in Azure Pipelines, the
DefineStaticWebAssets
task is skipped:In GitHub, the same task has the following output:
Expected Behavior
I expect to have the following files in the
publish\wwwroot
folder after runningdotnet publish
:{AssemblyName}.styles.css
css\site.css
css\bootstrap\bootstrap.min.css
css\open-iconic\font\css\open-iconic-bootstrap.min.css
Steps To Reproduce
Exceptions (if any)
Publishing locally and in GitHub Actions.
.NET Version
6.0.201
Anything else?
Additional info
A sample repository can be found here: https://github.com/dynsim/BlazorServerScopedCSSIssue
What we have tried:
builder.WebHost.UseStaticWebAssets()
in ourProgram.cs
file, as static web apps only are enabled by default inDevelopment
mode, as pointed out here: Changing Environment in Blazor 5.0 causes CSS not to load? #28174 (comment).ASPNETCORE_ENVIRONMENT
toDevelopment
, as static web apps only are enabled by default inDevelopment
mode, as pointed out here: Changing Environment in Blazor 5.0 causes CSS not to load? #28174 (comment).File outputs
Azure Pipelines
GitHub Actions
.NET info
Azure Pipelines
GitHub Actions
The text was updated successfully, but these errors were encountered: