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

OrchardCore.Cms.Web, Mvc.Web and Templates with .NET 6 #10762

Merged
merged 20 commits into from
Sep 20, 2022
Merged

Conversation

agriffard
Copy link
Member

@agriffard agriffard commented Nov 27, 2021

Use only Program.cs

Options in csproj:

    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>

Docs updated.
Templates updated.

Fixes #11932

@agriffard
Copy link
Member Author

agriffard commented Nov 27, 2021

  1. I figured out that it would only work with .NET 6.0 so we could not support .net5.0 and 3.1 as currently, right?

  2. Launching it using this line, with VS and IIS Express:
    builder.WebHost.UseNLogWeb();

seems to cause an error:

NotSupportedException: The web root changed from "D:\Orchard\OrchardCore\src\OrchardCore.Cms.Web\wwwroot" to "D:\Orchard\OrchardCore\src\OrchardCore.Cms.Web\". Changing the host configuration using WebApplicationBuilder.WebHost is not supported. Use WebApplication.CreateBuilder(WebApplicationOptions) instead.

@Skrypt
Copy link
Contributor

Skrypt commented Nov 29, 2021

We can't have this because of multi-targeting. Same issue as on OrchardCore.Commerce recently.

@sebastienros sebastienros modified the milestone: 1.2 Dec 14, 2021
@agriffard
Copy link
Member Author

Example repo to repro the error using builder.WebHost.UseNLogWeb(); : https://github.com/agriffard/Cms.Web

@agriffard
Copy link
Member Author

@deanmarcussen or @Skrypt Can you please have a look to the NLog error?

@snakefoot
Copy link

snakefoot commented Jan 8, 2022

WebHost is legacy and now obsolete with NET6. Instead use Host:

builder.Host.UseNLogWeb();

And change from IWebHostBuilder to IHostBuilder:

    public static class WebHostBuilderExtensions
    {
        public static IHostBuilder UseNLogWeb(this IHostBuilder builder)
        {
            LayoutRenderer.Register<TenantLayoutRenderer>(TenantLayoutRenderer.LayoutRendererName);
            builder.UseNLog();
            builder.ConfigureAppConfiguration((context, configuration) =>
            {
                var environment = context.HostingEnvironment;
                NLog.LogManager.Setup()
                      .LoadConfigurationFromFile(System.IO.Path.Combine(environment.ContentRootPath, "NLog.config"))
                      .LoadConfiguration(builder => builder.Configuration.Variables["configDir"] = environment.ContentRootPath);
            });

            return builder;
        }
    }

Notice NLog.Web.AspNetCore ver. 5.0 will automatically attempt to load NLog.config from ContentRootPath. And one can use ${aspnet-appbasepath} as an alternative to ${var:configDir}

Copy link
Member

@deanmarcussen deanmarcussen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snakefoot thanks for the assist.

@agriffard this needs the same for the Mvc templates / program.cs / startup.cs

You could take this out of draft :)

@agriffard
Copy link
Member Author

Mvc sample and template updated.

@agriffard agriffard marked this pull request as ready for review January 11, 2022 10:20
@agriffard
Copy link
Member Author

Could be merged, now that we use .NET 6.

@Skrypt
Copy link
Contributor

Skrypt commented Mar 12, 2022

I'm ok with it if we merge we will have time to adjust if any breaking change is introduced.

@Skrypt Skrypt added this to the 1.4 milestone May 12, 2022
@sebastienros
Copy link
Member

Needs testing around razor compilation with implicit using. Niraj mentions there is an issue with that.

@ns8482e
Copy link
Contributor

ns8482e commented Aug 23, 2022

@agriffard @Skrypt Updated Program.cs and fix merge conflict

@ns8482e
Copy link
Contributor

ns8482e commented Aug 28, 2022

@agriffard @Skrypt @sebastienros @deanmarcussen @hishamco Can you please review the updates?.

@ns8482e
Copy link
Contributor

ns8482e commented Aug 28, 2022

Needs testing around razor compilation with implicit using. Niraj mentions there is an issue with that.

@sebastienros for OrchardCore.Web conditional enable implicit using based on RazorCompilation value.
For templates removed Razor compilation

@ns8482e ns8482e requested review from hishamco and removed request for MikeAlhayek August 28, 2022 17:57
@ns8482e ns8482e changed the title Orchard.Cms.Web with .NET 6 OrchardCore.Cms.Web, Mvc.Web and Templates with .NET 6 Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update project templates to .NET 6 minimal hosting model
9 participants