From @evil-shrike on October 17, 2017 15:31
As continue of aspnet/MvcPrecompilation#187
The problem: I need a class library with embedded UI.
Currently it's hard implement such setup when a class library in a solution contains pre-compilable razor views. Lloading views from embedded resource is another option and it works fine.
At the end of the mentioned discussion (#187) there was posted a link to blog post about how to implement embedded UI - https://dzone.com/articles/self-contained-ui-running-one-aspnet-core-mvc-site
It seems to work well. But looks hacky, too much cleaver things should be done in csproj. Another problem it's not documented in official docs.
So this issue is an suggestion to have more simplified approach for "embedded UI", i.e. keeping razor views in class libraries and automatically compile and deploy them.
Some nuances which should be elaborated:
- a solution with app and lib both can contain views and identical routes (like "Home/Index")
- solution should start with F5/CtrlF5 in VS (views should be compiled and deploy)
- on deployment assemblies with pre-compiled views should be deployed correctly
- ideally there shouldn't be required to make a library project "runnable" (set
Sdk="Microsoft.NET.Sdk.Web" and declare static Main method) but it's not critical indeed, at least it should be documented
Currently (aspnetcore2.0) we have to do the following (thanks to @dasMulli for describing it in this comment - aspnet/MvcPrecompilation#71 (comment))
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<Target Name="SetMvcRazorOutputPath">
<PropertyGroup>
<MvcRazorOutputPath>$(OutputPath)</MvcRazorOutputPath>
</PropertyGroup>
</Target>
<Target Name="_MvcRazorPrecompileOnBuild" DependsOnTargets="SetMvcRazorOutputPath;MvcRazorPrecompile" AfterTargets="Build" Condition=" '$(IsCrossTargetingBuild)' != 'true' " />
<Target Name="IncludePrecompiledViewsInPublishOutput" DependsOnTargets="_MvcRazorPrecompileOnBuild" BeforeTargets="PrepareForPublish" Condition=" '$(IsCrossTargetingBuild)' != 'true' ">
<ItemGroup>
<_PrecompiledViewsOutput Include="$(MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.dll" />
<_PrecompiledViewsOutput Include="$(MvcRazorOutputPath)$(MSBuildProjectName).PrecompiledViews.pdb" />
<ContentWithTargetPath Include="@(_PrecompiledViewsOutput->'%(FullPath)')" RelativePath="%(_PrecompiledViewsOutput.Identity)" TargetPath="%(_PrecompiledViewsOutput.Filename)%(_PrecompiledViewsOutput.Extension)" CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
</Target>
Off the top of my head I'd suggest to introduce MvcRazorCompile=true.
Copied from original issue: aspnet/MvcPrecompilation#214
From @evil-shrike on October 17, 2017 15:31
As continue of aspnet/MvcPrecompilation#187
The problem: I need a class library with embedded UI.
Currently it's hard implement such setup when a class library in a solution contains pre-compilable razor views. Lloading views from embedded resource is another option and it works fine.
At the end of the mentioned discussion (#187) there was posted a link to blog post about how to implement embedded UI - https://dzone.com/articles/self-contained-ui-running-one-aspnet-core-mvc-site
It seems to work well. But looks hacky, too much cleaver things should be done in csproj. Another problem it's not documented in official docs.
So this issue is an suggestion to have more simplified approach for "embedded UI", i.e. keeping razor views in class libraries and automatically compile and deploy them.
Some nuances which should be elaborated:
Sdk="Microsoft.NET.Sdk.Web"and declarestatic Mainmethod) but it's not critical indeed, at least it should be documentedCurrently (aspnetcore2.0) we have to do the following (thanks to @dasMulli for describing it in this comment - aspnet/MvcPrecompilation#71 (comment))
Off the top of my head I'd suggest to introduce
MvcRazorCompile=true.Copied from original issue: aspnet/MvcPrecompilation#214