2012-09-20 9 views
7

Tôi muốn Visual Studio là precompile my ASP.NET application được sử dụng làm trọng tải vai trò web Azure. Vì vậy, tôi đã tìm thấy this post giải thích cách gọi aspnet_compiler để xác thực lượt xem.Làm thế nào để có được aspnet_compiler được gọi từ Visual Studio trong quá trình xây dựng?

Tôi cố gắng thêm những điều sau đây để "sau sự kiện xây dựng" của ứng dụng ASP.NET của tôi:

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

hoặc cách khác này (tên ứng dụng quy định một cách rõ ràng):

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

Trong cả hai các trường hợp khi quá trình tạo chạy diễn ra, tôi thấy những điều sau đây trong kết quả xây dựng:

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

và không rõ trước biên dịch xảy ra bởi vì nếu tôi thay đổi bất kỳ tập tin .aspx hoặc .cshtml "Build Action" thành "None" nó không nhận được gói dịch vụ Azure và khung nhìn không còn mở khi gói được triển khai Azure.

Làm cách nào để thiết lập aspnet_compiler cho biên dịch trước từ trong Visual Studio?

Trả lời

4

Nếu bạn muốn sử dụng Asp.NET Compiler trong Visual Studio của bạn/msbuild sau đó bạn có thể thêm AspNetCompiler Task để tập tin dự án của bạn (csproj/.vbproj) và thiết lập MvcBuildViews để true.

Ví dụ:

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

Bạn cũng có thể đặt TargetPath thuộc tính để chỉ định thư mục đích.

AfterTargets="build" tương tự như "sự kiện sau xây dựng". Xem Target Build Order để biết thêm.

+0

Loại tác phẩm này với 'Force' được đặt thành' false' ngoại trừ gói dịch vụ kết quả không thay đổi. – sharptooth

2

Tích hợp ASPX biên soạn vào Visual Studio

Một trong những nguyên tắc tôi nhấn mạnh vào là phải luôn luôn cố gắng xây dựng của tôi trên một môi trường sạch sẽ và mô phỏng cài đặt như thể nó đã được thực hiện bởi QA. Gần đây tôi đã nhận thấy rằng tôi tiếp tục rơi vào lỗi ẩn sâu trong các tập tin aspx. Vì vậy, tại sao không sử dụng công cụ aspnet_compiler.exe cũ và quen thuộc? Nó nằm ở C: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 và nó khá dễ sử dụng.

Là một trình bổ sung VS freak tôi đã bắt đầu suy nghĩ về một add-in tuyệt vời sẽ tích hợp với VS và sẽ lắng nghe để xây dựng các sự kiện và hiển thị các kết quả tại cửa sổ đầu ra. Heck, tại sao không thêm một số khả năng phục vụ cà phê?

Mất khoảng 10 phút googling để vấp ngã trên blog này. Mike Hadlow đã có một thiên tài trong ý tưởng đơn giản của nó. Sử dụng POST BUILD EVENT! Tất cả những gì tôi cần làm là đặt dòng sau vào sự kiện xây dựng bài đăng: C: \ WINDOWS \ Microsoft.NET \ Framework \ v2.0.50727 \ aspnet_compiler.exe -v/-p "$ (ProjectDir) \"

Bây giờ, Tất cả những gì còn lại là làm cho quá trình thêm dòng này vào mỗi và mọi dự án web trong nhóm của chúng tôi là tự động.

tôi có chỉ là add-in cho rằng :)

enter link description here

0

Câu trả lời từ Matej là hữu ích đối với tôi, nhưng tôi đã không thể sử dụng nó như nó vốn có và vẫn nhận được nó để làm việc cho cả hai bản dựng cục bộ trong Visual Studio và tự động xây dựng thông qua TFS.

Tôi phải thêm một số cài đặt msbuild bổ sung. Trên thực tế, có 2 kịch bản khác nhau mà tôi có. Một dự án là một Ứng dụng web được tích hợp vào thư mục _PublishedWebsites và một là một Ứng dụng web MVC không được xây dựng trong thư mục _PublishedWebsites.

Đầu tiên, thêm những điều sau nếu nó không phải là đã có trong hồ sơ dự án của bạn:

<PropertyGroup> 
    <MvcBuildViews>true</MvcBuildViews> 
    </PropertyGroup> 

Đối với một VỚI _PublishedWebsites:

<Choose> 
    <When Condition="'$(BuildingInsideVisualStudio)' == true"> 
     <PropertyGroup> 
     <AspNetCompilerPhysicalPath>$(ProjectDir)</AspNetCompilerPhysicalPath> 
     </PropertyGroup> 
    </When> 
    <Otherwise> 
     <PropertyGroup> 
     <AspNetCompilerPhysicalPath>$(WebProjectOutputDir)</AspNetCompilerPhysicalPath> 
     </PropertyGroup> 
    </Otherwise> 
    </Choose> 
    <Target Name="PrecompileWeb" AfterTargets="build" Condition="'$(MvcBuildViews)'=='true'"> 
    <!-- aspnet_compiler.exe needs to be run on the folder that has the aspx files and the "bin" subfolder. 
      When running locally, the value needs to be the project directory, which is $(ProjectDir). 
      When running the TFS build, the value needs to be (BuildFolder)\(ProjectName)\_PublishedWebsites\(ProjectName). 
      The $(AspNetCompilerPhysicalPath) will hold the correct value for both types of builds. 
    --> 
    <Message Text="Starting AspNetCompiler for $(ProjectName) at $(AspNetCompilerPhysicalPath)" Importance="high" /> 
    <AspNetCompiler 
     VirtualPath="/" 
     PhysicalPath="$(AspNetCompilerPhysicalPath)" 
     TargetPath="$(AspNetCompilerPhysicalPath)\bin_precompile" 
     Force="true" 
     /> 
    </Target> 

Đối với một trong những KHÔNG _PublishedWebsites:

<Choose> 
    <When Condition="'$(BuildingInsideVisualStudio)' == true"> 
     <PropertyGroup> 
     <AspNetCompiler_CopyFilesFirst>false</AspNetCompiler_CopyFilesFirst> 
     </PropertyGroup> 
    </When> 
    <Otherwise> 
     <PropertyGroup> 
     <AspNetCompiler_CopyFilesFirst>true</AspNetCompiler_CopyFilesFirst> 
     </PropertyGroup> 
     <ItemGroup> 
     <AllOutputFiles Include="$(OutDir)\\**\*.*" /> 
     </ItemGroup> 
    </Otherwise> 
    </Choose> 
    <Target Name="PrecompileWeb" AfterTargets="build" Condition="'$(MvcBuildViews)'=='true'"> 
    <!-- aspnet_compiler.exe needs to be run on the folder that has the cshtml files and the "bin" subfolder. I could not find a setting that was appropriate for both. 
      When running locally, the value needs to be the project directory, which is $(ProjectDir). 
      When running the TFS build, there is no folder that matches both of those criteria. 
      So first we will copy the output into the source code folder's "bin" subfolder, 
      then run it against the source $(ProjectDir), the same as if we were building locally. 
    --> 
    <Message Text="Before running AspNetCompiler, copy files from $(OutDir) to $(ProjectDir)\bin" Importance="high" /> 
    <Exec Command="(robocopy.exe /mir $(OutDir) $(ProjectDir)\bin) ^&amp; IF %25ERRORLEVEL%25 LEQ 1 exit 0" Condition="'$(AspNetCompiler_CopyFilesFirst)'=='true'" /> 

    <Message Text="Starting AspNetCompiler for $(ProjectName) at $(ProjectDir)" Importance="high" /> 
    <AspNetCompiler 
     VirtualPath="/" 
     PhysicalPath="$(ProjectDir)" 
     TargetPath="$(ProjectDir)\bin_precompile" 
     Force="true" 
     /> 
    </Target>