Gilles
Gilles

Reputation: 5407

Precompiling a site for deployment using .targets file for MSBuild

I have an ASP.NET web project (.Net 4.5, Visual Studio 2015).

The solution uses the XAML builds, not the newer web builds. Some of the builds deploy the application directly to the IIS server using a file copy.

We do not use the Publish action from Visual Studio to publish the project.

In the .csproj file of the ASP.NET project, the following import statement was added to add an additional .targets file:

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

<?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. I know there is a checkbox in the Publish action to precompile but I can't use that. I must use the existing XAML builds with the targets file and possibly instruction in the .csproj file.

I also know that I can use the Aspnet_compiler.exe tool on the server once the file are deployed. 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?

Upvotes: 0

Views: 926

Answers (1)

Tingting0929
Tingting0929

Reputation: 4202

You could create a .pubxml file for your project then check in to TFS, in the .pubxml file, set precompileBeforePublish to True.

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

In the xaml build definition, add these msbuild arguments:

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

Then in TFS xaml build, it will do precompile before deploy.

Upvotes: 1

Related Questions