加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 如何在构建期间从Visual Studio调用aspnet_compiler

发布时间:2020-12-16 04:09:09 所属栏目:asp.Net 来源:网络整理
导读:我想要Visual Studio到 precompile my ASP.NET application,它用作Azure Web角色有效负载.所以我发现 this post解释了如何调用aspnet_compiler来验证视图. 我尝试将以下内容添加到我的ASP.NET应用程序的“post-build event”中: call "%VS100COMNTOOLS%vsv
我想要Visual Studio到 precompile my ASP.NET application,它用作Azure Web角色有效负载.所以我发现 this post解释了如何调用aspnet_compiler来验证视图.

我尝试将以下内容添加到我的ASP.NET应用程序的“post-build event”中:

call "%VS100COMNTOOLS%vsvars32.bat"
aspnet_compiler -v / -p $(ProjectDir)

或者这个(显式指定的应用程序名称):

call "%VS100COMNTOOLS%vsvars32.bat"
aspnet_compiler -v /ASP.NET-Application-ProjectNameHere -p $(ProjectDir)

在构建运行的两种情况下,我在构建输出中看到以下内容:

Setting environment for using Microsoft Visual Studio 2010 x86 tools.
Utility to precompile an ASP.NET application
Copyright (C) Microsoft Corporation. All rights reserved.

并且显然没有预编译,因为如果我将任何.aspx或.cshtml文件“Build Action”更改为“None”,它将无法访问Azure服务包,并且一旦将包部署到Azure,视图就不再打开.

如何在Visual Studio中设置aspnet_compiler以进行预编译?

解决方法

如果要在Visual Studio / msbuild中使用Asp.NET编译器,则可以添加
AspNetCompiler任务到项目文件(.csproj / .vbproj)并将MvcBuildViews设置为true.

例:

<Project>
  <PropertyGroup>
    <MvcBuildViews>true</MvcBuildViews>
  </PropertyGroup>
  <!-- ... -->
  <Target Name="PrecompileWeb" AfterTargets="build" Condition="'$(MvcBuildViews)'=='true'">
    <Message Text="Starting AspNetCompiler for $(ProjectDir)" Importance="high" />
    <AspNetCompiler
        VirtualPath="temp"
        PhysicalPath="$(WebProjectOutputDir)"
        Force="true"
    />
  </Target>
  <!-- ... -->
</Project>

您还可以设置TargetPath属性以指定目标目录.

AfterTargets =“build”类似于“post-build event”.详见Target Build Order.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读