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

WebRootPath in debug mode #58

Closed
stefanodelpero opened this issue Feb 22, 2023 · 10 comments
Closed

WebRootPath in debug mode #58

stefanodelpero opened this issue Feb 22, 2023 · 10 comments

Comments

@stefanodelpero
Copy link

Hi! Great library!

I've a problem with the WebRootPath in debug in Visual Studio.
WebRootPath point to the bin folder that do not contains wwwroot, instead of the wwwroot inside the source folder (as IWebHostEnvironment.WebRootPath does).

I'm missing something?

Thank you!

@soundaranbu
Copy link
Owner

Hi @stefanodelpero, the library internally computes the path for the internal usage. But that should not interfere with mvc behaviour I believe.
Can you give more details please? Some code snippets will also help.

@stefanodelpero
Copy link
Author

stefanodelpero commented Feb 24, 2023

Hi @soundaranbu,
I use a TagHelper in the cshtml that I use to generate HTML with Razor.Templating.Core.

<img write-content="true" src="~/images/logo-header.png" class="mb-4" />

Normally in the application (when in Debug from Visual Studio) the IWebHostEnvironment.WebRootPath points to the wwwroot in the source folder of Visual Studio.

Instead, in the WriteContentTagHelper, I have an IWebHostEnvironment object (from DI) that is created from Razor.Templating.Core.
Here, the WebRootPath property point to the \bin\Debug\net7.0 folder.

public WriteContentTagHelperBase(IWebHostEnvironment environment)
{
    var path = environment.WebRootPath;
    // Path ends with \bin\Debug\net7.0
}

I think this is because DirectoryHelper.GetWebRootDirectory search for the wwwroot in the assembliesBaseDirectory.
But in Debug mode in Visual Studio the assembliesBaseDirectory do not have the wwwroot folder.

soundaranbu added a commit that referenced this issue Feb 25, 2023
@soundaranbu
Copy link
Owner

Hi @stefanodelpero, thanks for this. I've pushed a fix. I hope this will fix your issue. I'll let you know when a pre-release package is published.

@soundaranbu
Copy link
Owner

@stefanodelpero
Copy link
Author

@soundaranbu It do not works. Because the parameter services of the ServiceCollectionExtensions.AddRazorTemplating is a new object created in RazorTemplateEngine.CreateInstance.

@soundaranbu
Copy link
Owner

Thanks @stefanodelpero.

If i understand the problem correctly, then you should be receiving the default IWebHostEnvironment object provided by ASP.NET Core. The default object should have the correct path set retaining the original behaviour of the framework. This is considering your application is MVC.

Please provide a minimal sample if possible. We can take it forward from there.

Thanks!

@stefanodelpero
Copy link
Author

Hi @soundaranbu, here you can find a sample: https://github.com/stefanodelpero/RazorTemplatingCoreSample
Thanks!

@soundaranbu
Copy link
Owner

soundaranbu commented Feb 26, 2023

I made only two changes to make it work in your sample:

In Program.cs, add to DI

builder.Services.AddRazorTemplating();

In .csproj, use the pre-release version

    <PackageReference Include="Razor.Templating.Core" Version="1.9.0-rc.2" />

Result:

image

@soundaranbu
Copy link
Owner

Actually, the pre-release didn't make any difference. The latest stable v1.8.0 itself is working fine after adding to DI.

@stefanodelpero
Copy link
Author

Oh man. Sorry to waste your time!
I've been using your library for a long time and never needed to add DI. So I didn't think about it.
Thanks a lot!

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

No branches or pull requests

2 participants