Razor icon indicating copy to clipboard operation
Razor copied to clipboard

Automatic view compilation isn't happening in asp.net core 2.1.2

Open jimSampica opened this issue 8 years ago • 9 comments

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.0.4

ViewCompilation 2.1.1

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>

jimSampica avatar Jul 13 '18 20:07 jimSampica

Thanks for contacting us, @shoe788. @pranavkm, can you please look into this? Thanks!

mkArtakMSFT avatar Jul 13 '18 21:07 mkArtakMSFT

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?

image

pranavkm avatar Jul 13 '18 21:07 pranavkm

I am on Visual Studio 15.7.5

jimSampica avatar Jul 13 '18 21:07 jimSampica

Here are the build logs.

vslog_1.txt vslog_2.txt vslog_3.txt vslog_4.txt

jimSampica avatar Jul 13 '18 22:07 jimSampica

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?

pranavkm avatar Jul 13 '18 22:07 pranavkm

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?

jimSampica avatar Jul 13 '18 22:07 jimSampica

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.

pranavkm avatar Jul 13 '18 22:07 pranavkm

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.

netranger avatar Aug 01 '18 14:08 netranger

I had the same problem. Thanks you!

sergei66666 avatar Oct 16 '18 09:10 sergei66666