从 ASP.Net Core 2 API 中删除 PrecompiledViews.dll [英] Deleting PrecompiledViews.dll from ASP.Net Core 2 API

查看:25
本文介绍了从 ASP.Net Core 2 API 中删除 PrecompiledViews.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 .NET Core 2 Web API 应用程序中,发布到 MS VS 2017 中的文件夹功能生成:

.PrecompiledViews.dll<ProjectAssembly>.PrecompiledViews.pdb

所以我删除了 PrecompiledViews.dll 并测试了我的 API,它似乎工作正常,没有任何警告或异常.

如果 API 不使用任何剃刀视图,删除 PrecompiledViews.dll 和 pdp 是否安全?如果是,VS 2017 中是否有停止发布未使用的预编译视图的选项?

解决方案

你说得对,预编译步骤总是发出一个程序集并且不检查是否真的有视图.您可以通过将其放入您的 csproj 文件来禁用预编译步骤:

<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish></PropertyGroup>

这将激活正常的编译上下文保存(refs 子文件夹).要停用此功能,请添加

false</PreserveCompilationContext>

到属性组.

In .NET Core 2 Web API app, Publish to folder feature in MS VS 2017 produce:

<ProjectAssembly>.PrecompiledViews.dll
<ProjectAssembly>.PrecompiledViews.pdb

Offical docs says that PrecompiledViews related to precompiling Razor Views, but my API doesn't contain any views or static files, just REST endpoints that return json.

Using .Net reflector I found the PrecompiledViews.dll empty.

So I deleted PrecompiledViews.dll and tested my API and it seems to work fine without any warnings or exceptions.

Is it safe to delete PrecompiledViews.dll and pdp if the API not using any razor views? If yes, Is there option in VS 2017 to stop publishing unused PrecompiledViews?

解决方案

You are right, the precompile step always emits an assembly and doesn't check if there are actually views. You can disable the precompilation step by putting this into your csproj file:

<PropertyGroup>
  <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
</PropertyGroup>

This will then activate the normal copilation context preservation (refs subfolder). To deactivate this as well, add

<PreserveCompilationContext>false</PreserveCompilationContext>

to the property group.

这篇关于从 ASP.Net Core 2 API 中删除 PrecompiledViews.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆