When I deploy asp.net application through visual studio I know I can just check Precompile during publish
and uncheck Allow precompiled site to be updateable
.
And I want to do the same with msbuild
tool and I am using /p:MvcBuildViews=true /p:EnableUpdateable=false
but when I go to IIS
and open views they still have their content which means they are not precompiled, right?
They should have line This is a marker file generated by the precompilation tool
as they do when publishing from VS. Am I missing something?
Performing Precompilation You can precompile a Web site using the Aspnet_compiler.exe tool on the command line. For more information, see How to: Precompile ASP.NET Web Sites for Deployment and ASP.NET Compilation Tool (Aspnet_compiler.exe). Visual Studio also includes commands to precompile a Web site from the IDE.
The default (checked) setting of "Allow precompiled site to be updateable" allows you to update your view content without needing to rebuild the entire project.
In order for the ASP.NET engine to service a request for this page, the page's code portion (the WebPage. aspx. cs file) must first be compiled. This compilation can happen explicitly or automatically.
Precompile asp.net views with ms build
You should use the arguments /p:PrecompileBeforePublish=true
instead of /p:MvcBuildViews=true
.
MvcBuildViews
is often mistakenly considered as something that when activated results in precompiled views. Actually. It is just a thing to include views to build process but it doesn’t compile these to project binaries folder.
When we check the checkbox Precompile during publish
and uncheck the checkbox Allow precompiled site to be updateable
on the file publish options, we will get following properties setting in our FolderProfile.pubxml
file:
<PropertyGroup>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>False</EnableUpdateable>
</PropertyGroup>
So if you want to do the same with msbuild tool, we should use the arguments:
/p:PrecompileBeforePublish=true;EnableUpdateable=false
Besides, since those arguments are stored in the .pubxml
file(under the PublishProfiles in the Properties node in Solution Explorer). They are now designed to be checked in and shared with team members. These files are now MSBuild files and you can customize them if you wish. In order to publish from the command line just pass DeployOnBuild=true
and set PublishProfile to the name of the profile:
msbuild.exe "TestPrecompiled.csproj" /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml
Of course, you can use the arguments and the .pubxml
file at the same time, the arguments in the command line will overwrite the property in the .pubxml
file:
msbuild.exe "TestPrecompiled.csproj" /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml /p:PrecompileBeforePublish=true;EnableUpdateable=false
After publish completed, open the .cshtml file in the publish folder, we will get the line This is a marker file generated by the precompilation tool, and should not be deleted!
as they do when publishing from VS:
See Precompiling ASP.NET WebForms and MVC Views with MSBuild for some more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With