使用ms build预编译asp.net视图

Ale*_*ksa 10 c# asp.net msbuild asp.net-mvc visual-studio

当我通过visual studio部署asp.net应用程序时,我知道我可以检查Precompile during publish并取消选中Allow precompiled site to be updateable.

我想用msbuild工具做同样的事情我正在使用/p:MvcBuildViews=true /p:EnableUpdateable=false但是当我去IIS打开视图时他们仍然有他们的内容,这意味着他们没有预编译,对吧?

他们应该This is a marker file generated by the precompilation tool像从VS发布时那样行.我错过了什么吗?

Leo*_*SFT 25

使用ms build预编译asp.net视图

您应该使用参数/p:PrecompileBeforePublish=true而不是/p:MvcBuildViews=true.

MvcBuildViews经常被误认为是激活后导致预编译视图的东西.其实.包含视图以构建进程只是一件事,但它不会将这些视图编译为项目二进制文件夹.

当我们选中复选框Precompile during publish并取消选中Allow precompiled site to be updateable文件发布选项上的复选框 时,我们将在FolderProfile.pubxml文件中获得以下属性设置:

  <PropertyGroup>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>False</EnableUpdateable>
  </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

所以如果你想用msbuild工具做同样的事情,我们应该使用参数:

/p:PrecompileBeforePublish=true;EnableUpdateable=false

此外,由于这些参数存储在.pubxml文件中(在解决方案资源管理器的"属性"节点中的"PublishProfiles"下).它们现在设计为签入并与团队成员共享.这些文件现在是MSBuild文件,您可以根据需要自定义它们.要从命令行发布,只需传递DeployOnBuild=true并将PublishProfile设置为配置文件的名称:

msbuild.exe "TestPrecompiled.csproj" /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml
Run Code Online (Sandbox Code Playgroud)

当然,您可以同时使用参数和.pubxml文件,命令行中的参数将覆盖.pubxml文件中的属性:

msbuild.exe "TestPrecompiled.csproj" /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml /p:PrecompileBeforePublish=true;EnableUpdateable=false
Run Code Online (Sandbox Code Playgroud)

发布完成后,打开发布文件夹中的.cshtml文件,我们This is a marker file generated by the precompilation tool, and should not be deleted!将从VS发布时获取该行:

在此输入图像描述

在此输入图像描述

有关更多详细信息,请参阅使用MSBuild预编译ASP.NET WebForms和MVC视图.

  • 非常感谢,这真的很有帮助:) (3认同)