Question

We have an existing Php application that I'd like to integrate into my very simple MS Build process. Currently we are using Visual Studio 2013 Ultimate with Visual Studio Online (TFService) and Git to source control various C++, C# and this Php web applications (all in different Git repositories).

To develop our Php code inside of VS2013, we use Devsense's Php Extension (http://www.devsense.com/products/php-tools). This has been great, but doesn't natively support automated builds.

Has anyone setup automated builds for Php? The first goal would be to have the build process deliver a zip file to the cloud that can be downloaded by the web head. I want the zip file to not include the solution and project files, but rather to only include the files that we need on the web head.

Currently, if I create a simple out of the box "hello world" project using the Devsense template and put it in it's own Git repository on VS Online, the build breaks with the following error.

1 error(s), 0 warning(s) C:\a\src\PhpTest.sln - 1 error(s), 0 warning(s), View Log File C:\a\src\MyPhpSite\MyPhpSite.phpproj: The target "Build" does not exist in the project. C:\a\src\PhpTest.sln compiled No Test Results No Code Coverage Results

Thoughts?

Was it helpful?

Solution

This requires editing your phpproj file and some knowledge of MSBUILD.

In order to edit your phpproj file:

  • Right-click your project ("MyPhpSite") and select "Unload Project".
  • Right-click your project again and select "edit MyPhpSite.phpproj"

at the end of the file, enter the following to pull in the "Build" target:

<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />

Since I'm not sure exactly how you plan on using the zip file, I'll assume you just want to have it available for download from Visual Studio Online.

Add an inline task for zipping the file.

<UsingTask TaskName="Zip" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
  <ParameterGroup>
    <InputFileFolder ParameterType="System.String" Required="true" />
    <OutputFileName ParameterType="System.String" Required="true" />
  </ParameterGroup>
  <Task>
    <Reference Include="System.IO.Compression" />
    <Using Namespace="System.IO.Compression" />
    <Code Type="Fragment" Language="cs">
    <![CDATA[        
      ZipFile.CreateFromDirectory(InputFolderName, OutputFileName);     
    ]]>
    </Code>
  </Task>
</UsingTask>

set the following PropertyGroup and ItemGroup

<PropertyGroup>
  <OutputPath>bin\</OutputPath>
</PropertyGroup>

<ItemGroup>
  <Payload Include="$(OutputPath)$(Name)" />
</ItemGroup>

Set the following targets, the last one being the one that moves the files to a single location and then zips them up.

<Target Name="CreateManifestResourceNames" />
<Target Name="CoreCompile" />
<Target Name="CopyFilesToOutputDirectory">
  <MakeDir Directories="$(OutputPath)$(Name)" />
  <Copy SourceFiles="@(Compile)" DestinationFiles="$(OutputPath)$(Name)\%(Identity)" />
  <Copy SourceFiles="@(Content)" DestinationFiles="$(OutputPath)$(Name)\%(Identity)" />
  <Zip InputFolderName="@Payload" OutputFileName="$(OutputPath)$(Name).zip/>
</Target>

The Blank targets are there in order to keep MSBuild from throwing an error.

This will get you to having a successful build that ends in a zip file to download.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top