微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

发布单个Razor页面后出现编译错误在发布整个项目后坚持执行 “编译参考可能会丢失”

如何解决发布单个Razor页面后出现编译错误在发布整个项目后坚持执行 “编译参考可能会丢失”

今天,我正在研究.NET Core 3.0项目(VS 2019)。我在一个页面上的<span>添加了CSS类。而已。没有其他的。考虑到更改很小,我认为只发布该文件是适当的。我右键单击该文件,然后选择“发布”。它一起发布了.cshtml.cshtml.cs页,并在短短几秒钟内完成。

这样做之后,该页面现在将无法在我的生产应用程序中编译。

可能缺少一个或多个编译参考。如果在已发布的应用程序中看到此消息,请在项目文件中将'copyRefAssembliesToPublishDirectory'设置为true,以确保refs目录中的文件已发布。

应用程序中的其他页面均不受影响。就是说,即使发布了整个项目,这一页也不再起作用。

我已进行了建议的更改:

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <copyRefAssembliesToPublishDirectory>true</copyRefAssembliesToPublishDirectory>
  </PropertyGroup>
  • 我清理,重建并完整发布了整个项目,但是错误并没有消失。

  • 在我的项目文件中启用建议的设置后,我尝试仅发布此页面

  • 我已经多次在Azure中重新启动Web服务。

  • 排除文件,然后发布,重新添加文件,然后发布。

  • 更改了页面模型名称

错误仍然存​​在。

我将在下面列出所有错误

One or more compilation references may be missing. If you're seeing this in a published application,set 'copyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published.

The type or namespace name 'IndexModel' Could not be found (are you missing a using directive or an assembly reference?)
+
        public global::Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<IndexModel> Html { get; private set; }
The type or namespace name 'IndexModel' Could not be found (are you missing a using directive or an assembly reference?)
+
        public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<IndexModel> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<IndexModel>)PageContext?.ViewData;
The type or namespace name 'IndexModel' Could not be found (are you missing a using directive or an assembly reference?)
+
        public IndexModel Model => ViewData.Model;
The type or namespace name 'IndexModel' Could not be found (are you missing a using directive or an assembly reference?)
+
        public global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<IndexModel> ViewData => (global::Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary<IndexModel>)PageContext?.ViewData;

编辑:

我发现我可以通过重命名页面解决此问题,但不幸的是,这不是可行的解决方案。

解决方法

到目前为止,我的解决方案是从App Service中删除整个应用程序(使用Azure门户中提供的FTP凭据)并重新发布。

尽管如此,它仍然是一个更好的解决方案。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。