Closed aaronamm closed 1 week ago
Did you try a "Hot Reload" option from VS?
@hishamco thank you so much for prompt reply. I have updated my development environment. I use VS Code not Visual Studio.
This issue is related to this discussion => #15321.
I have updated my development environment. I use VS Code not Visual Studio.
I know :) what I'm asking is to try, we need to make sure is happen for both options or only related to dotnet watch
command
It has never really worked well with VS Code as far as I remember but the VS Code launcher option should be there. If you need Hot Reload I believe you should use Visual Studio as it is better supported.
Can you checkout this issue and see if it helps
@aaronamm Have you noticed this line?
that option is disabled by default ,Because opening it requires more resources, such as memory and compilation time.
You can add the following configuration lines to your local file OrchardCore.Cms.Web.csproj.user
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" />
</ItemGroup>
@MikeAlhayek ,It works fine on my end with no problems, I think this question should be converted to a discussion
@hyzx86 I think all you need is to add <RazorRuntimeCompilation>true</RazorRuntimeCompilation>
to your web csproj without having the need to add reference to
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" />
I have not had time to test it and see if this is a problem of not.
Yes, it may or may not work, I guess csproj.user is executed after xxx.csproj, so I think the other way is more straightforward
@hyzx86 I think all you need is to add
<RazorRuntimeCompilation>true</RazorRuntimeCompilation>
to your web csproj without having the need to add reference to<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" />
I have not had time to test it and see if this is a problem of not.
I tested it and it does work, no problem
@hyzx86 I just tested it real quick to provide you feedback and I am getting a runtime error
An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.
All of the views seems to have similar error
Invalid expression term '['
Syntax error; value expected
Which branch is this? 1.8.3 ?
Which branch is this? 1.8.3?
main
There should be no problem with the main branch. I was still using it a few days ago.
Which branch is this? 1.8.3?
main
I tried it today, and the main branch code is fine, but Visual Studio may have some caches that need to be cleared when switching branches, or else strange problems may occur. You can do this by right clicking on the solution and batch generate -> select all projects -> then click on clean.
I even found that I was able to hot update the cs file when I tweaked it. But the second time I made the changes Visual Studio hit a fatal error and the debugger crashed 🤣
You can do this by right clicking on the solution and batch generate -> select all projects -> then click on clean.
I did that too but that does not work. Remember that I am doing this is a project that references the OC packages not the OC project itself.
By the way, executing npm run cleanup
is better than clean in VS because it ensures that ALL the bin
and obj
folders are removed from every project.
You can use git clean -xdf
@hishamco the command git clean -xdf
will remove things like App_Data folder which is not good in most cases. The npm run clean
will only remove the bin and obj folder. And if you want to clean all npm_modules folders, rune npm run clean all
this will clean all 3 folders from all projects.
I did that too but that does not work. Remember that I am doing this is a project that references the OC packages not the OC project itself.
@MikeAlhayek , If you need to debug OC source code during development, you can try this module. https://github.com/EasyOC/EasyOC.Modules/tree/main/src/Modules/EasyOC.AssemblyLoader
You can step through code or use a debugger from within VS Code or VS, is there any special about the OC.AssemblyLoader
?
I have a framework based on OC, the business code is in another project, then the framework can be separated from the business, before the module I use the submodule but the submodule needs to be modified sln file
In turn, I can create a local branch of OC and add a reference to this module, and I can debug my other OC modules in OC source code
I have the same issue in VS 2022 + OC 1.8.2 + .NET 8.0
OC 1.7.2 works well.
My project is organized according to OC's dependency package management.
Also several .props
files It's working fine so far!
But just now when I modify the cshtml
file, it pops up a message that hot reloading is not supported,
After ignoring this window, refresh the page and still can apply the changes
More context in this duplicate: https://github.com/OrchardCMS/OrchardCore/issues/16504.
I think I may have located the source of this issue. It was introduced by PR #14348. For performance reasons, the following code registers a static compiler provider, but this may cause hot reload to fail. https://github.com/OrchardCMS/OrchardCore/blob/4395dbb793cc166c3179049fc01d3121c603cf72/src/OrchardCore/OrchardCore.Mvc.Core/Startup.cs#L109 Could we register this provider only in the production environment? Something like this:
// Support razor runtime compilation only if in dev mode and if the 'refs' folder exists.
var refsFolderExists = Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "refs"));
if (_hostingEnvironment.IsDevelopment())
{
if (refsFolderExists)
{
builder.AddRazorRuntimeCompilation();
}
}
else
{
// Share across tenants a static compiler even if there is no runtime compilation
// because the compiler still uses its internal cache to retrieve compiled items.
services.AddSingleton<IViewCompilerProvider, SharedViewCompilerProvider>();
}
I'm not sure if the changes are correct. If they are, would it be possible for me to submit my first pull request?
Hmm, interesting, and if this fixes the issue then certainly, please open a PR. But I'm still wondering why hot reload works for me with the same code. @DavidStania could you please test the above code changes?
// Support razor runtime compilation only if in dev mode and if the 'refs' folder exists. var refsFolderExists = Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "refs")); if (_hostingEnvironment.IsDevelopment()) { if (refsFolderExists) { builder.AddRazorRuntimeCompilation(); } } else { // Share across tenants a static compiler even if there is no runtime compilation // because the compiler still uses its internal cache to retrieve compiled items. services.AddSingleton<IViewCompilerProvider, SharedViewCompilerProvider>(); }
I'm not sure if the changes are correct. If they are, would it be possible for me to submit my first pull request?
I can confirm that this fixes the hot reload issue, which I have as well. We would be happy if you want to submit your first PR.
Not working for me!
In my case, the 'refs' folder does not exists and
builder.AddRazorRuntimeCompilation();
will not be hit.
@DavidStania
It doesn't matter whether builder.AddRazorRuntimeCompilation()
is hit or not; we just need to ensure SharedViewCompilerProvider
is not registered in development mode. Please try again and check if hot reload works properly.
Genius! It works for me! Your next coffee is on me. That was a really big problem for us and made us very inefficient.
Just to note, this issue is about hot reload. Runtime compilation is a different beast 😊
Describe the bug
Hot reload stop working Razor page in OC 1.8.3. It does work perfectly if we rollback to OC 1.7.2.
To Reproduce
Steps to reproduce the behavior:
dotnet watch run
Expected behavior
Development environment