【发布时间】:2020-10-24 20:23:34
【问题描述】:
今天我正在处理一个 .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;
编辑:
我发现我可以通过重命名页面来解决此问题,但不幸的是,这不是一个可行的解决方案。
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-core razor