I'm currently working on a Blazor Server application using the latest stable release of .NET Core (6.0.302). I have Hot Reload enabled, but the application seems to view any and all changes I made as "rude edits", and will always rebuild the application. This rather defeats the point of using hot reload in the first place, and it appears that what I'm doing is supported. When I create a new test project, hot reload appears to work just fine, so it's not a problem with the SDK from what I can tell, just a problem with my project.
I've updated all NuGet packages, removed old SDKs from my system, tried removing the RazorRuntimeCompilation package from the project to see if it was interfering, all to no avail.
Upon closer inspection of the errors thrown in the console, it would appear that one error was being triggered before the others:
File changed: ./Pages/TND/ScheduleIndex.razor.
dotnet watch: Failed to create MSBuildWorkspace: [Failure] Msbuild failed when processing
the file '<path>\<project>.csproj' with message: <path>\<project>.csproj: (0, 0):
Package 'Hangfire.Dashboard.Authorization 3.0.0' was restored using '.NETFramework,Version=v4.6.1,
.NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7,
.NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8'
instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
dotnet watch: Exited
dotnet watch: Building...
After removal of the offending package, hot reload began working perfectly. It appears that if any warning is thrown from your .csproj file, even if the application builds just fine upon launch, any subsequent hot reloads will fail and trigger a rude-edit-style rebuild of the project.
Related
I create a brand new ASP.NET Core MVC project using VS 2022 and .NET Core 6.
VS will generate the base template and when I run it without touching any code, everything is fine.
So far so good.
Now I add the NuGet dependency Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation version 6.0.0.
In Program.cs file, I add a line
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages().AddRazorRuntimeCompilation(); //Add this line of code
var app = builder.Build();
Rebuild the program and run it. Now I see the footer is not at the bottom of the page anymore.
Is it a bug or did I do something wrong here? Thanks.
I was struggling the same problem as well,
while trying the versions of Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation nuget package and found the solution with 5.0.13 version.
If you downgrade the package from 6.0.1 to 5.0.13, the problem goes away and footer will be on bottom again.
In Visual Studio 2022, there's an option for hot reload on file save. this fixed my issue without having the need to install Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
What is happening is that when you enable runtime editing, the .NET Core built in bundle and minification is removed. If you look at shared/_layout.cshtml, there is a _layout.cshtml.css file. This is the runtime bundle/include you are missing. Since this is your core layout, move the contents from this file to your wwwroot/css/site.css file and the footer and other elements will render as before.
Is it your intention to actually use RazorPages? It looks like you just want to add runtime compilation to the standard MVC views.
If you intend to use controllers and views, just add:
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
But, I tried your code as well and in my environment, the footer is present in both cases, even if I downgrade Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation from version 6.0.1 to 6.0.0.
I think there's no need to add the runtime compilation since in the newest update/version hot-reload has been officially released.
PS. I am currently following an asp.net tutorial and I encountered this problem. Here's the link: https://youtu.be/hZ1DASYd9rk
I'm watching same video series as you do and i had the same error. I upgraded Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation to v6.0.11 and I don't get any error anymore I
Installing Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation version 5.0.17 Nugget Package cleared the error for me.
You may try to install any version from 5.0.0 - 5.0.17
Having watched Dan Roth's Blazor demo (15 Jan 2020), code changes to a razor file were refreshed to the browser without the stop|build|run cycle. On my VS2019 (latest) I don't get that hot reload. This is a new Blazor SS project from the standard template. Is there a property required to be set to enable it?
I tried
dotnet run watch
but no difference
Edit: 12-04-2021
Initial .NET Hot Reload support
Early support for .NET Hot Reload is now available for ASP.NET Core & Blazor projects using dotnet watch. .NET Hot Reload applies code changes to your running app without restarting it and without losing app state.
To try out hot reload with an existing ASP.NET Core project based on .NET 6, add the "hotReloadProfile": "aspnetcore" property to your launch profile in launchSettings.json. For Blazor WebAssembly projects, use the "blazorwasm" hot reload profile.
Run the project using dotnet watch. The output should indicate that hot reload is enabled:
watch : Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload. Press "Ctrl + R" to restart.
If at any point you want to force the app to rebuild and restart, you can do so by entering Ctrl+R at the console.
You can now start making edits to your code. As you save code changes, applicable changes are automatically hot reloaded into the running app almost instantaneously. Any app state in the running app is preserved.
OLD ANSWER
This will come in .NET 6 hopefully. But at the time of writing this is still not working yet:
Environment: Ubuntu 16.04, .NET Core 1.10 (1.0.0-preview2-1-003177), Visual Studio Code 1.8.1
I just generated a new ASP.NET Core app. When I run the app from a terminal window, the start up web page gets displayed as expected.
$ cd MyApp
$ dotnet run
However, the web page is slightly different when I load MyApp folder from VSC and press F5 to debug it. Specifically, the default top toolbar is missing. Toolbar items such as Home, About, Contact, etc. line up in a single column.
I have compared the generated html between the two. When run from the command line, the stylesheet links are:
href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css"
href="/css/site.min.css"
When run from VCS, the links are:
href="/lib/bootstrap/dist/css/bootstrap.css"
href="/css/site.css"
On examining local file structure, I see file css/site.css is present under folder wwwroot. However, I don't see any lib folder at all.
More information. Turns out _Layout.cshtml adds links based on environment names. When the names are Staging and Production, the generated bootstrap link is for ajax.aspnetcdn.com. For "Development," the link is "/lib/xxx."
Wondering how I force VCS to automatically populate bootstrap.css into lib directory.
Problem solved. When the website is generated, a file, bower.json, is created. This file has information about the bootstrap package. However, for some reason, this package is not automatically downloaded. You need to do the following:
From VSC, install the bower plugin by running "ext install bower."
Press F1 and type Bower. Next type, "Bower Update."
This is it. The plugin will download the bootstrap package and populate it in wwwroot/lib directory. Now, the website would work as expected from within VSC.
Hope the next version of VSC will have bower integrated.
It seems like when your app runs from VS Code, it is not serving the CSS files.
To troubleshoot further, looking at the launch.json, project.json, and Startup.cs files is necessary. My guess is that your launch.json is setup to run under a slightly different configuration than your dotnet run command is from the terminal. That is resulting in...
not serving static files at all, or
not including CSS files in the app's build output.
From your question update, the problem is that your launch.json is running under in the Development environment and your terminal is running under the Staging or Production environment. The former serves bootstrap locally; the latter serves it from a content delivery network.
When running in the "Development" environment, you need to install bootstrap locally and ensure it's in the /lib directory at runtime. That means installing the client-side packages. How to do that depends on the ASP.NET Core application template your using. For instance, if you generated your app with Yeoman, then you need to restore with Bower. Check for a gulpfile.js, a bower.json file, or a package.json that downloads, installs, and builds client-side dependencies, which likely include bootstrap.
I upgraded my environment to v5.0.6. Problem is that everytime i start Eclipse it does this:
[2013-04-19 18:38:41] FWLST1017I: [AppShell] upgraded to the latest
platform version.
When this upgrade takes place, it reverts my templates and adds class files to the iphone\native folder and removes the plugins I configured in the shell:
Removes all my custom plugins from components/AppShell/iphone/native/Classes
Resets project.pbxproj.wltemplate.wluser to stock removing includes for my classes
Resets config.xml.wluser removing all mappings to my plugins
It also always shows at the end of the upgrade process:
Failed to upgrade Worklight project 'AppMobile' to the latest platform
version. [null]
Is that why it keeps running the upgrade and reverting my changes?
According to your question, you have some .wluser files, which means that something is wrong with your project.
Can you please let me know whether the problem still exists and whether you still have those files in you project?
Finding hard to know why am I unable to get this thing :
... I can run my application from command prompt, But when I do idea and Import the existing project using IntelliJ unable to trace out what Libraries or Jar files I need to get going.
In one Play1.2.3 I used to just Import Play and Play1.2.3 jar files and everything works..
Update
Have tried Creating a new project and Open Project(Instead of Import) from IntelliJ,But no luck.It has attached all the Libraries but still the error doesnt go screenshot attached:
IDE :IntelliJ 11.0.2 &
Play : 2.0.2
Since Play 2.0.2 you don't need to create Idea's project from the scratch and import modules into it.
Just choose Open project from the menu, and find the folder where you performed play idea action, whole project will be ready to use in the IDE without any additional steps.
Edit:
Most important: to reflect changes in managed sources your application need to compile it first, so it needs to work in the background while developing or you need to compile it manually if app is stopped. Otherwise Idea will not be able to compile (and find) managed sources. That's exactly job of the Play's DEV mode which differs from others Java frameworks, which requires to compile app manually and/or configuring your IDE to do that from time to time. Play's dev mode allows to do it in background.
Idea will start recognizing your managed sources after first run the app in the browser (as it will compile it, and idea will catch it just few seconds later). Of course the app must be running in dev mode, to compile views, assets etc.
play run
Of course if you're in production mode, you also need to restart the app.
alternatively after idealizing the project, or if your app is not working you can manually compile managed sources with:
play compile
Also if you'll start in tilde-dev mode, it will be compiling changed resources right after the changes' saving
play ~run