在Netcore 2.0 Visual Studio 2017中发布项目时未复制视图 [英] Views not being copied when publish the project in netcore 2.0 visual studio 2017
问题描述
我在VS 2017中创建了一个ASP.NET Core 2.0项目.发布项目时,没有Views
文件夹,但是有wwwroot
文件夹.
I have createa a ASP.NET Core 2.0 project in VS 2017. When I publish my project the Views
folder are not there but the wwwroot
folder is.
我可以在.csproj文件中设置以下内容:
This I can setup in my .csproj file with the following:
<ItemGroup>
<Content Update="appsettings.json;web.config" CopyToOutputDirectory="PreserveNewest"/>
<Content Update="Views\**\*" CopyToOutputDirectory="PreserveNewest" />
<Content Update="wwwroot\**\*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
但是没有用.
推荐答案
ASP.NET Core MVC has a precompilation feature, that could be added by referencing the Microsoft.AspNetCore.Mvc.Razor.ViewCompilation
package. Feature enabling/disabling configured by MvcRazorCompileOnPublish
property is .csproj.
默认情况下,该程序包被添加到ASP.NET Core 2.0 MVC应用程序中:
And by default, the package is added in ASP.NET Core 2.0 MVC applications:
如果您要在netcoreapp2.0上定位ASP.NET Core 2.0或更高版本,请参考 Microsoft. Microsoft.AspNetCore.All添加了AspNetCore.Mvc.Razor.ViewCompilation 包,您无需显式引用它.
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.
和启用了预编译:
ASP.NET Core 2.x项目模板默认情况下将
MvcRazorCompileOnPublish
隐式设置为true,这意味着可以从.csproj文件中安全删除此节点:
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,其中包含您的视图.
If you go to publish output folder, you will see dll like <project_name>.PrecompiledViews.dll
which contains your views.
这篇关于在Netcore 2.0 Visual Studio 2017中发布项目时未复制视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!