用于凉亭安装的命令行MSBUILD PreBuildEvent

时间:2016-03-14 16:35:01

标签: jenkins command-line msbuild pre-build-event

我尝试使用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>

的Test2

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

任何帮助任何人?

2 个答案:

答案 0 :(得分:0)

默认情况下, public List<String> getSubPathsInS3Prefix(String bucketName, String prefix) { if (!prefix.endsWith(FILE_DELIMITER)) { prefix += FILE_DELIMITER; } List<String> paths = new ArrayList<String>(); ListObjectsRequest listObjectsRequest = new ListObjectsRequest() .withBucketName(bucketName).withPrefix(prefix) .withMaxKeys(1000).withDelimiter(FILE_DELIMITER); ObjectListing currentListing = s3Client.listObjects(listObjectsRequest); paths.addAll(currentListing.getCommonPrefixes()); while (currentListing == null || currentListing.isTruncated()) { currentListing = s3Client.listNextBatchOfObjects(currentListing); paths.addAll(currentListing.getCommonPrefixes()); } return paths; } 目标不是MSBuild中包含的内容。您错过了BeforeBuild的{​​{1}},您可以通过安装MSBuild.Microsoft.VisualStudio.Web.targets package来访问构建服务器。

它定义了与常见的msbuild目标类似的构建过程。来自<Import>文件的摘录:

Microsoft.Web.Publishing.targets

答案 1 :(得分:0)

我找到了解决方案......

所有文件都在正确的位置并且导入语句已正确定义,但如果要从命令行执行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(不要忘记添加构建,否则它只会执行指定的目标)。