使用Visual Studio Ultimate / Online和Git构建自动化Php项目的最佳实践 [英] Best practice for automating Php project builds using Visual Studio Ultimate/Online and Git

查看:199
本文介绍了使用Visual Studio Ultimate / Online和Git构建自动化Php项目的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个现有的Php应用程序,我想将它集成到我的 简单的MS Build过程中。目前,我们正在使用Visual Studio 2013 Ultimate与Visual Studio Online(TFService)和Git来源控制各种C ++,C#和这个PHP Web应用程序(全部在不同的Git仓库中)。



为了在VS2013中开发我们的PHP代码,我们使用了Devsense的Php扩展( http://www.devsense.com/products/php-tools )。这非常棒,但本身不支持自动构建。



有没有人为PHP设置自动构建?第一个目标是让构建过程将一个zip文件传递到云端,然后由网站负责人下载。我希望zip文件不包含解决方案和项目文件,而是仅包含我们需要在Web头上的文件。



目前,如果我使用Devsense模板创建一个简单的hello world项目并将其放入VS Online中的自己的Git存储库,构建将会中断出现以下错误。

1个错误,0个警告
C:\ a\src\PhpTest.sln - 1错误,0警告,查看日志文件
C:\ a\src\MyPhpSite\MyPhpSite.phpproj:目标Build在项目中不存在。
C:\a\src\PhpTest.sln编译
无测试结果
无代码覆盖结果



想法?

解决方案

这需要编辑你的phpproj文件和一些MSBUILD的知识。


$ b 为了编辑您的phpproj文件:


  • 右键单击您的项目(MyPhpSite)并选择Unload Project。


  • $再次右击您的项目并选择编辑MyPhpSite.phpproj b
    $ b

    在文件末尾,输入以下内容以拉入Build目标:

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

    因为我不确定您打算如何使用zip文件,我会假定您只需要从Visual Studio Online下载即可。



    添加一个内联任务来压缩文件。

     < UsingTask TaskName =ZipTaskFactory =CodeTaskFactoryAssemblyFile =$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll> 
    < ParameterGroup>
    < InputFileFolder ParameterType =System.StringRequired =true/>
    < OutputFileName ParameterType =System.String必需=true/>
    < / ParameterGroup>
    <任务>
    < Reference Include =System.IO.Compression/>
    < Using Namespace =System.IO.Compression/>
    < Code Type =FragmentLanguage =cs>
    <![CDATA [
    ZipFile.CreateFromDirectory(InputFolderName,OutputFileName);
    ]]>
    < / Code>
    < /任务>
    < / UsingTask>

    设置以下PropertyGroup和ItemGroup

     <&的PropertyGroup GT; 
    < OutputPath> bin \< / OutputPath>
    < / PropertyGroup>

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

    设置以下目标,最后一个将文件移动到一个位置,然后将它们拉起来。

     < Target Name =CreateManifestResourceNames/> 
    < Target Name =CoreCompile/>
    <目标名称=CopyFilesToOutputDirectory>
    < MakeDir Directories =$(OutputPath)$(Name)/>
    < Copy SourceFiles =@(Compile)DestinationFiles =$(OutputPath)$(Name)\%(Identity)/>
    < Copy SourceFiles =@(Content)DestinationFiles =$(OutputPath)$(Name)\%(Identity)/>
    < Zip InputFolderName =@ PayloadOutputFileName =$(OutputPath)$(Name).zip />
    < / Target>

    空白目标是为了防止MSBuild抛出一个错误。



    这会得到你有一个成功的版本,以一个zip文件结尾下载。


    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?

    解决方案

    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.

    这篇关于使用Visual Studio Ultimate / Online和Git构建自动化Php项目的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆