View Component not rendering when deployed – Works locally

huangapple go评论48阅读模式
英文:

View Component not rendering when deployed - Works locally

问题

我们最近使用GitHub Actions进行部署,我不确定是否与此问题有关。在本地运行时,该组件可以正常工作,从Visual Studio发布也可以,但通过GitHub无法。

我们在_Layout.cshtml页面中有以下内容:
<vc:header is-error-page="false"></vc:header>

而在_ViewImports.cshtml页面中有这些内容:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Project.Common.Web
@addTagHelper *, Project.Admin.Web

还有组件的InvokeAsync部分:

public class HeaderViewComponent : ViewComponent
{
	private readonly IMediator _mediator;

	public HeaderViewComponent(IMediator mediator)
	{
		_mediator = mediator;
	}

	public async Task<IViewComponentResult> InvokeAsync(bool isErrorPage)
	{
		var model = await _mediator.Send(new Header.Query(UserClaimsPrincipal, HttpContext.Session.GetString(SessionKeys.HeaderRole)!, isErrorPage), HttpContext.RequestAborted);

		return View(model);
	}
}

有趣的是,如果在部署后查看页面源代码,它将以正确的方式呈现所有HTML。但在开发工具中,它只显示在代码中的方式:
<vc:header is-error-page="false"></vc:header>

此外,这部分代码或相关依赖项未进行任何更改。JS和CSS似乎也像往常一样包含在内。

任何帮助将不胜感激。

此外:
https://stackoverflow.com/questions/44078195/view-component-as-a-tag-helper-does-not-get-invoked
似乎是相同的问题,但答案并不有帮助。

除了重建和重新部署之外,我们没有想到要做的事情。问题刚开始出现,之前我们已成功通过GitHub Actions进行部署。

英文:

We recently moved to GitHub actions for deployments and I am unsure if this is related to the issue or not. The component works when run locally and when published from Visual Studio but not via GitHub.

We have the following in the _Layout.cshtml page:
<vc:header is-error-page="false"></vc:header>

And this in the _ViewImports.cshtml page:

@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Project.Common.Web
@addTagHelper *, Project.Admin.Web

And the the component InvokeAsync:

public class HeaderViewComponent : ViewComponent
{
	private readonly IMediator _mediator;

	public HeaderViewComponent(IMediator mediator)
	{
		_mediator = mediator;
	}

	public async Task<IViewComponentResult> InvokeAsync(bool isErrorPage)
	{
		var model = await _mediator.Send(new Header.Query(UserClaimsPrincipal, HttpContext.Session.GetString(SessionKeys.HeaderRole)!, isErrorPage), HttpContext.RequestAborted);

		return View(model);
	}
}

One interesting thing is if you view the page source after it is deployed it is rendered correctly with all the html. But in the dev tools it is not it just shows up like it is in the code:
<vc:header is-error-page="false"></vc:header>

Also no changes were made to this portion of the code or associated dependencies. The js and css seem to be included as usual as well.

Any help would be appreciated.

Also:
https://stackoverflow.com/questions/44078195/view-component-as-a-tag-helper-does-not-get-invoked
looks to be an identical issue but the answer isn't helpful.

Outside of just rebuilding and redeploying there hasn't been much we can think of to do. The issue just started happening and we were able to deploy via GitHub actions successfully before.

答案1

得分: 0

这似乎是由最新的 .net SDK 使用预览构建版本引起的。我们通过在项目的根目录添加一个 globals.json 文件并指定一个未出现问题的版本来解决了这个问题。

{
  "sdk": {
    "version": "7.0.102"
  }
}
英文:

This appeared to be caused by the latest .net SDK using a preview build version.
We were able to get around it by adding a globals.json file in the root or our project and specifying a version that wasn't broken.

{
  "sdk": {
    "version": "7.0.102"
  }
}

huangapple
  • 本文由 发表于 2023年2月18日 04:38:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75489061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定