我在 VS 2017 中创建了一个 ASP.NET Core 2.0 项目。当我发布我的项目时,Views
文件夹不在那里,而是 wwwroot
文件夹是。
我可以在我的 .csproj 文件中使用以下内容进行设置:
<ItemGroup>
<Content Update="appsettings.json;web.config" CopyToOutputDirectory="PreserveNewest"/>
<Content Update="Views\**\*" CopyToOutputDirectory="PreserveNewest" />
<Content Update="wwwroot\**\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
但没有用。
最佳答案
ASP.NET Core MVC 有一个 precompilation功能,可以通过引用 Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
添加包裹。由 MvcRazorCompileOnPublish
配置的功能启用/禁用属性是 .csproj。
默认情况下,该包被添加到 ASP.NET Core 2.0 MVC 应用程序中:
If you're targeting ASP.NET Core 2.0 or higher on netcoreapp2.0, a reference to the Microsoft.AspNetCore.Mvc.Razor.ViewCompilation package is added by Microsoft.AspNetCore.All and you do not need to explicitly reference it.
和 precompilation is enabled :
The ASP.NET Core 2.x project templates implicitly set
MvcRazorCompileOnPublish
to true by default, which means this node can be safely removed from the .csproj file:<PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish> </PropertyGroup>
如果您转到发布输出文件夹,您将看到类似
<project_name>.PrecompiledViews.dll
的 dll。其中包含您的观点。
关于asp.net-core - 在 netcore 2.0 Visual Studio 2017 中发布项目时不会复制 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46685159/