Deleting PrecompiledViews.dll from ASP.Net Core 2

2020-04-19 11:35发布

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.

enter image description here

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?

1条回答
别忘想泡老子
2楼-- · 2020-04-19 11:56

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.

查看更多
登录 后发表回答