本文介绍了在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具有预编译功能,可以通过引用Microsoft.AspNetCore.Mvc.Razor.ViewCompilation程序包来添加.通过MvcRazorCompileOnPublish属性配置的功能启用/禁用是.csproj.

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:

启用了预编译:

<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中发布项目时未复制视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:27