Automatic view compilation isn't happening in asp.net core 2.1.2
When I upgraded my project to asp.net core 2.1.2 and the ViewCompilation package to 2.1.1 the automatic view compilation doesn't appear to be working when I publish
To test I created two new projects from the asp.net core templates targeting .net framework 4.6.2. In one of them I upgrade it to asp.net core 2.1.2 and the other is default asp.net core 2.0.4 with ViewCompilation 2.0.4.
The resulting output is below
ViewCompilation 2.0.4

ViewCompilation 2.1.1

csProj for 2.0.4
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.4" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.3" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>
</Project>
csProj for 2.1.2
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.1.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
</ItemGroup>
</Project>
Thanks for contacting us, @shoe788. @pranavkm, can you please look into this? Thanks!
What version of VS are you using? ASPNETCore 2.1 requires VS 15.7 or newer
We've deprecated the ViewCompilation tool in favor of build \ publish time compilation using the Razor Sdk. WIth the project template you pasted, I'm able to verify that it works correctly and compiles a Views dll. If you are using 15.7, could you turn up the VS logging to Diagnostic (see the picture) and share the build log from the build output window?

I am on Visual Studio 15.7.5
It looks like your app's using the 2.0 SDK (the SDK versioned 2.1.2x is for the 2.0 runtime \ release). It's strange that VS did not install the 2.1.3.x SDK that shipped with the 2.1 runtime. You may download the Sdk from here - https://www.microsoft.com/net/download/dotnet-core/2.1 if you don't already have it installed. If you do have it installed, perhaps you have a global.json that's pinning the sdk?
Yep, the VS update didn't install the sdk. Thank you very much!
You said that the ViewCompilation package is deprecated so does it work to uninstall that package and just have Microsoft.AspnetCore.Mvc?
You said that the ViewCompilation package is deprecated so does it work to uninstall that package and just have Microsoft.AspnetCore.Mvc?
Yup. Removing that package reference would be the way to go.
For what it's worth... I had the exact same issue on both my workstation (VS2017 Proff) and on my build server (VS2017 Community).
None of them had the 2.1 SDK installed but was using the 2.0 version despite upgrading to newest version of VS2017 15.7.5 yesterday.
I was comparing vanilla projects and upgrading and downgrading packages until I found that my workaround would be to have the Microsoft.AspNetCore.Mvc.Razor.ViewCompilation set to version 2.0.4, and all the rest running version 2.1.1.
After upgrading the SDK to version 2.1 (both local and on buildserver) I can confirm the precompilation of views are working again. I also removed the reference to Microsoft.AspNetCore.Mvc.Razor.ViewCompilation and it is still precompiling the views.
It was hard to find this issue with the solution, but I'm glad to have found the proper solution instead of my ugly workaround.
I had the same problem. Thanks you!