MVC 5 - Precompiling views only works from the command prompt

Viewed 753

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.

2 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

Related