Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 5 - Precompiling views only works from the command prompt

I have a strange issue that hopefully, someone can help me with. I got a new laptop and I'm trying to publish the same ASP.NET MVC 5 project on the new machine with precompiled views. However, when I do a publish with "Precompile during publishing" option checked, it does not create the precompiled views. Now, if I copy the exact command that it ran and run it in the Command Prompt, the precompiled views are created.

Here are the details. Both machines have Windows 10 Anniversary Update (Version 1607) with Visual Studio 2013 Update 5. Publishing the app on the old machine with the same publish profile generates the precompiled views. On the new machine, publishing from the "Publish Web" dialog runs without errors, but no precompiled views are generated. I then copied this exact command to the Command Prompt that VS used to precompile:

C:\windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v / -p C:\MyApp\obj\Release\AspnetCompileMerge\Source -c C:\MyApp\obj\Release\AspnetCompileMerge\TempBuildDir

When I ran it, it created the precompiled views in the TempBuildDir\bin directory!

The only difference I can think of between the machines is the Windows Updates.

Any ideas? Thanks.

like image 651
Ionian316 Avatar asked Jul 14 '17 17:07

Ionian316


People also ask

Are Cshtml files compiled?

cshtml extension are compiled at both build and publish time using the Razor SDK. Runtime compilation may be optionally enabled by configuring your project.

Where is Aspnet_compiler EXE located?

NET Framework ships with an ASP.NET compilation tool ( aspnet_compiler.exe ) that enables you to compile the source code (and even the content) of an ASP.NET application built using the WSP model. This tool was released with the . NET Framework version 2.0 and is located in the %WINDIR%\Microsoft.NET\Framework\v2.


1 Answers

I ran into exactly the same problem.

It could be an issue with compressed folders (the drive is not compressed, but individual folders are). For some reason, the .compiled files are simply not generated.

This still applies to VS2019 and MVC5. (The latest toolchain as of today. Probably a .NET Framework issue, unrelated to VS and MsBuild versions).

This thread helped me find the solution (see the last answer): https://social.msdn.microsoft.com/Forums/vstudio/en-US/cb6a4239-9765-4021-a7ab-e5ad3d8aef06/missing-compiled-files-when-publishing-an-aspnet-mvc-4-project-to-filesystem-on-tfs-build-server?forum=msbuild

like image 193
Biró Krisztián Avatar answered Oct 27 '22 14:10

Biró Krisztián