Precompile asp.net views with ms build

前端 未结 1 1477
野趣味
野趣味 2021-01-04 04:28

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 updatea

相关标签:
1条回答
  • 2021-01-04 05:02

    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.

    0 讨论(0)
提交回复
热议问题