简体   繁体   English

使用.targets文件为MSBuild预编译要部署的站点

[英]Precompiling a site for deployment using .targets file for MSBuild

I have an ASP.NET web project (.Net 4.5, Visual Studio 2015). 我有一个ASP.NET Web项目(.Net 4.5,Visual Studio 2015)。

The solution uses the XAML builds, not the newer web builds. 该解决方案使用XAML构建,而不是较新的Web构建。 Some of the builds deploy the application directly to the IIS server using a file copy. 一些内部版本使用文件副本将应用程序直接部署到IIS服务器。

We do not use the Publish action from Visual Studio to publish the project. 我们不使用Visual Studio中的“发布”操作来发布项目。

In the .csproj file of the ASP.NET project, the following import statement was added to add an additional .targets file: 在ASP.NET项目的.csproj文件中,添加了以下import语句以添加其他.targets文件:

<Import Project="CSADeploy.targets" Condition="Exists('CSADeploy.targets')" />
<Target Name="AdditionalTargets">
  <!-- ... -->
</Target>

In this target file the files are copied. 在该目标文件中,文件被复制。

Here is a short excerpt from the .targets file: 这是.targets文件的简短摘录:

<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <Target Name="BeforeBuild"> 
  </Target>
  <Target Name="AfterBuild">

I would like the code that is deployed to the server to be precompiled for deployment either Deployment Only or Deployment with updateable UI is fine. 我希望预先编译部署到服务器的代码以进行部署,即“仅部署”或“具有可更新UI的部署”都可以。 I know there is a checkbox in the Publish action to precompile but I can't use that. 我知道Publish操作中有一个复选框可以预编译,但我不能使用它。 I must use the existing XAML builds with the targets file and possibly instruction in the .csproj file. 我必须将现有XAML构建与目标文件以及.csproj文件中的指令一起使用。

I also know that I can use the Aspnet_compiler.exe tool on the server once the file are deployed. 我也知道,一旦文件被部署,我就可以在服务器上使用Aspnet_compiler.exe工具。 But I must do it before the file are copied because I do not have access to this server and I want to prevent adding a manual action to the build process. 但是我必须在复制文件之前执行此操作,因为我无权访问此服务器,并且希望防止在构建过程中添加手动操作。

How can I precompile the ASP.NET pages for deployment so that they are deployed correctly in my scenario? 如何预编译ASP.NET页面以进行部署,以便在我的方案中正确部署它们?

You could create a .pubxml file for your project then check in to TFS, in the .pubxml file, set precompileBeforePublish to True. 您可以为您的项目创建一个.pubxml文件,然后签入TFS,在.pubxml文件中,将precompileBeforePublish设置为True。

  <PropertyGroup>
    ......
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
  </PropertyGroup>

In the xaml build definition, add these msbuild arguments: 在xaml构建定义中,添加以下msbuild参数:

 /p:deployOnBuild=true /p:publishProfile=***.pubxml

Then in TFS xaml build, it will do precompile before deploy. 然后在TFS xaml构建中,它将在部署之前进行预编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM