aspnetcore: Unable to publish views of a Microsoft.NET.Sdk.Web project
Please let me know the steps I need to follow to publish views (.cshtml files) of a Microsoft.NET.Sdk.Web project instead of publishing a precompiled views.dll I am using asp.net core 5.0, and please note it is not a Microsoft.NET.Sdk.Razor project.
- Tried the following settings but that didn’t help. Do these work only for Microsoft.NET.Sdk.Razor projects? If yes, then what are corresponding settings in a Microsoft.NET.Sdk.Web project for the following:
<RazorCompileOnBuild>false</RazorCompileOnBuild>
<RazorCompileOnPublish>false</RazorCompileOnPublish>
<CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
- Also tried include Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation package and including the AddRazorRuntimeCompilation():
services.AddMvc(options => options.Filters.Add(typeof(CustomExceptionFilter)))
.AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null)
.AddControllersAsServices()
.AddRazorRuntimeCompilation();
These didn’t help. So please let me know what I need to do be able to publish views in a Microsoft.NET.Sdk.Web project .
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (11 by maintainers)
I think putting
<Content Update="*.cshtml" CopyToPublishDirectory="PreserveNewest" />after all your includes might work. That said this is a question specific to MSBuild evaluation, and perhaps folks on https://github.com/dotnet/msbuild or StackOverflow might be better suited to respond.CopyRazorGenerateFilesToPublishDirectoryapplies toRazorGenerateitems which are only calculated whenEnableDefaultItemsis true.This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.
See our Issue Management Policies for more information.
You’ll have to manually include cshtml files as
Contentitems:e.g.
<Content Include="**\*.cshtml" />(this does not include any of the the excludes that the Web.SDK adds by default).@geetmenon thanks for contacting us.
Microsoft.NET.Sdk.Web imports Microsoft.NET.Sdk.Razor, otherwise you wouldn’t even be able to compile builds.
I’m not sure what you are trying to achieve, the best way for you to do this would probably be to set
EnableDefaultRazorGenerateItemsandEnableDefaultRazorComponentItemsAt that point they won’t be considered for razor compilation and won’t be compiled nor included in the dlls and is up to you to get them copied to wherever you want.
/cc: @pranavkm