问题描述
今天,我正在研究.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凭据)并重新发布。
尽管如此,它仍然是一个更好的解决方案。