【问题标题】:Precompile asp.net views with ms build使用 ms build 预编译 asp.net 视图
【发布时间】:2018-08-08 06:04:49
【问题描述】:

当我通过 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 发布时一样。我错过了什么吗?

【问题讨论】:

    标签: c# asp.net asp.net-mvc visual-studio msbuild


    【解决方案1】:

    使用 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>
    

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

    /p:PrecompileBeforePublish=true;EnableUpdateable=false

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

    msbuild.exe "TestPrecompiled.csproj" /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml
    

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

    msbuild.exe "TestPrecompiled.csproj" /p:DeployOnBuild=true /p:PublishProfile=FolderProfile.pubxml /p:PrecompileBeforePublish=true;EnableUpdateable=false
    

    发布完成后,打开发布文件夹中的.cshtml文件,我们会得到This is a marker file generated by the precompilation tool, and should not be deleted!这一行,就像他们从VS发布时一样:

    有关更多详细信息,请参阅Precompiling ASP.NET WebForms and MVC Views with MSBuild

    【讨论】:

    • 非常感谢,这真的很有帮助:)
    猜你喜欢
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 2012-10-18
    • 1970-01-01
    • 2018-03-13
    相关资源
    最近更新 更多