Bower 安装的命令行 MSBUILD PreBuildEvent

Command line MSBUILD PreBuildEvent for bower install

我正在尝试使用 PreBuildEvent 在 Jenkins 服务器上创建命令行 MSBUILD 发布以执行 bower 安装。我已经尝试了几个选项(见下文)但命令行输出只是说构建完成而没有执行 PreBuildSteps 并且没有显示任何错误。
测试 1

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>URL</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeFoldersFromDeployment>bower_components</ExcludeFoldersFromDeployment>
    <ExcludeFilesFromDeployment>bower.json</ExcludeFilesFromDeployment>
  </PropertyGroup>
  <Target Name="BeforeBuild">
    <Exec Command="bower-installer -silent" />
  </Target>
</Project>

测试2

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemDefinitionGroup>
      <PreBuildEvent>
        <Command>bower-installer -silent</Command>
      </PreBuildEvent>
  </ItemDefinitionGroup>
  <PropertyGroup>
    <PreBuildEventUseInBuild>true</PreBuildEventUseInBuild>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>URL</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeFoldersFromDeployment>bower_components</ExcludeFoldersFromDeployment>
    <ExcludeFilesFromDeployment>bower.json</ExcludeFilesFromDeployment>
  </PropertyGroup>
</Project>

我正在执行的命令如下:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild "<PATH>\website.publishproj" /p:DeployOnBuild=true /p:PublishProfile="<PROFILE>" /p:VisualStudioVersion=14.0  

有什么帮助吗??

BeforeBuild 目标默认情况下不包含在 MSBuild 中。您缺少 Microsoft.Web.Publishing.targets<Import>,您可以通过安装 MSBuild.Microsoft.VisualStudio.Web.targets package.

来访问构建服务器

它定义了与常见 msbuild 目标类似的构建过程。来自 Microsoft.Web.Publishing.targets 文件的片段:

<!-- Setup the minimum set of targets required -->
<PipelineDependsOn Condition="!$(PipelineDependsOnBuild)">
  $(PipelineDependsOn);
  BeforeBuild;
  BuildOnlySettings;
  ResolveReferences;
  PrepareResourceNames;
  ComputeIntermediateSatelliteAssemblies;
  GetCopyToOutputDirectoryItems;
  _SGenCheckForOutputs;
</PipelineDependsOn>

<PipelineDependsOn Condition="$(PipelineDependsOnBuild) And !$(_DeployOnBuild)">
  $(PipelineDependsOn);
  Build;
</PipelineDependsOn>

<PipelineDependsOn Condition="!$(PipelineDependsOnBuild) And !$(_DeployOnBuild)" >
  $(PipelineDependsOn);
  AfterBuild;
</PipelineDependsOn>

我找到了解决方案...

所有文件都在正确的位置并且正确定义了导入语句,但是如果您想从命令行执行 MSBUILD,则必须添加一些额外的参数。

.pubxml

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>True</ExcludeApp_Data>
    <publishUrl>URL</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeFoldersFromDeployment>bower_components</ExcludeFoldersFromDeployment>
    <ExcludeFilesFromDeployment>bower.json</ExcludeFilesFromDeployment>
  </PropertyGroup>
  <Target Name="BeforeBuild">
    <Exec Command="bower-installer -silent" />
  </Target>
</Project>

命令行

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild "<PATH>\website.publishproj" 
/t:BeforeBuild;Build /p:DeployOnBuild=true /p:PublishProfile="<PROFILE>" 
/p:VisualStudioVersion=14.0

诀窍是添加 /t:<Target Name>;Build(不要忘记添加构建,否则它只会执行指定的目标)。