2014-01-30 27 views
1

我可以用MSBuild构建我的解决方案。它运行grunt并在解决方案目录中生成一个“dist”文件夹,然后MSBuild将这些文件复制到$(OutDir)如何通过MSBuild在AppHarbor上运行grunt?

假设我的解决方案被称为 MySolution.sln。我旁边叫after.MySolution.sln.targets另一个文件,其中包含

<!--?xml version="1.0" encoding="utf-8"?--> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <Target Name="Grunt" AfterTargets="Build"> 
     <Exec Command="grunt build --no-color" WorkingDirectory="$(MSBuildProjectDirectory)" /> 

     <ItemGroup> 
      <DistFiles Include="$(MSBuildProjectDirectory)\dist\**\*.*" /> 
     </ItemGroup> 
     <Copy SourceFiles="@(DistFiles)" DestinationFolder="$(OutDir)\www\%(RecursiveDir)" /> 
    </Target> 
</Project> 

当AppHarbor构建的解决方案,我收到此错误

Grunt: 
    grunt build --no-color 
    'grunt' is not recognized as an internal or external command, 
    operable program or batch file. 

这是可以理解的,如果咕噜-CLI是不是已经被AppHarbor提供。那么我怎么能在AppHarbor上运行我的咕噜声呢?

注:从技术上讲,成功运行的呼噜声,我需要运行npm installbower install,这样的荣誉,如果答案也包括咕噜包和亭子包!

回答

1

为了运行我的构建,我不得不直接使用节点而不是使用grunt-cli。我的MSBuild现在简单地调用run-grunt.bat,其中包含:

@echo off 
echo Installing npm dependencies 
call npm config set registry http://registry.npmjs.org/ 
call npm install 
echo Running bower.commands.install() 
call node -e "var b = require('bower'); b.commands.install()" 
echo Running grunt.cli() 
call node -e "var g = require('grunt'); g.cli.tasks = ['build']; g.cli.options.color = false; g.cli();" 

它似乎工作;下一个问题是构建服务器上的节点仍然在版本0.6.10,但这是另一个问题:)

请注意,我添加注册表,因为否则它不起作用(我将不得不与AppHarbor ),并且由于我使用了bower,可能其他人也会这样,所以我在我的示例中包含了如何运行bower install

重要提示:您需要在您的packages.json文件中包含grunt(如果使用它,请使用bower)!

+0

对于downvote非常抱歉 - 这是无意的,应该是upvote,但我只是意识到太迟了 – Fatal