.Net Core 2.2 - After publishing a Webapp, the links were not working and the generated HTML code was the same as Razor

Asked

Viewed 76 times

0

I am publishing a Net Core Webapp (version 2.2.108) on the Smaterasp.net host in "self-contained Deployment mode".

My file . CSPROJ looks like this:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <UserSecretsId>438bea06-a241-4638-a75d-2c9de371a6b3</UserSecretsId>
    <AssemblyName>ProjectName.UI.Web.Admin</AssemblyName>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  </PropertyGroup>

After publishing and running the Webapp I saw that the links were not working and the generated HTML code was the same as Razor, like this:

<a asp-area="" asp-controller="Ticket" asp-action="Index">Tickets</a>

But the right thing should be:

<a href="/Ticket/Index">Tickets</a>

If I publish without the parameters below:

<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

I have the following mistake:

Error - The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=

Can you tell me what I did wrong or how to adjust it?

Thank you for your attention.

  • No endenti... it is returning cshtml as static file? you are accessing by route or typing the file path with the extension?

  • I’m sorry Leandro, I’ll go into it a little more. In addition to the Webapp project, I have another project that is a class library of Viewcomponents identical to this project that I refer to in the Webapp. For applications . Net Core 2.2 run on the host, I need to publish in Deployment self-contained mode. When I run the application on some server links (inspecting Cod. ) are not converted to HREF.

  • but if you want a link, your tag-helper is wrong, it doesn’t have the asp-area="" would just be <a asp-controller="Ticket"&#xA; asp-action="Index">Tickets</a>

1 answer

-1


Take a look if you are properly importing the lib cm the tagHelpers. Take a look at this article: https://www.koskila.net/how-to-fix-microsoft-aspnetcore-mvc-taghelpers-not-being-rendered/. Perhaps it can help to understand the problem. I suspected that perhaps these Imports were missing.

See if you have a _Viewimports.cshtml file in the "Views" folder with the contents:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

To be more specific and help with common errors that may occur, please follow the related documentation link, which deals with the _Viewimports.cshtmlfile. There he explains exactly how it works, the directives for which he supports and also explains the following:

"The _Viewimports.cshtml file for an ASP.NET Core MVC application is usually placed in the Pages (or Views) folder. A file _Viewimports.cshtml can be placed in any folder, in which case it will only be applied to pages or views in that folder and its subfolders. _Viewimports files are processed starting at level root and then for each folder up to the location of the page or the display itself. The _Viewimports settings specified in the level root can be overwritten at folder level."

https://docs.microsoft.com/pt-br/aspnet/core/mvc/views/layout?view=aspnetcore-2.2#importing-Shared-Directives

And, as the article suggests, the lack of this file leads to the error reported in the question: Taghelpers are not compiled.

Now I hope I’ve helped.

  • Now you have improved the answer, but it would be interesting to bring the content of the external link here too, after all your answer will stay here, but that address can be deactivated tomorrow.

  • Hi Leandro, there really is no _Viewimports.cshtml file in the Viewcomponentslibrary project. I will read the article you reported, make the necessary adjustments and perform the tests. The funny thing that running locally the situation does not occur, occurs only in production environment. I will also adjust my question by detailing what I wrote in the comments, I agree with you. Thank you for your attention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.