0

I'm trying to create a command line MSBUILD publish on a Jenkins server with a PreBuildEvent to do a bower install. I already tried several options (see below) but the command line output just says build completed without executing the PreBuildSteps and without showing any errors.
Test1

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

The command I'm executing is the following:

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

Any help anyone??

BjoVa
  • 43
  • 1
  • 3

2 Answers2

0

The BeforeBuild target is not something that's included in MSBuild by default. You are missing an <Import> of the Microsoft.Web.Publishing.targets, which you can get to your build server by installing the MSBuild.Microsoft.VisualStudio.Web.targets package.

It defines a similar build process as the common msbuild targets. A snippet from the Microsoft.Web.Publishing.targets file:

<!-- 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>
m0sa
  • 10,712
  • 4
  • 44
  • 91
  • Thanks for the answer. I checked the files and everything is in place. Also the import statement is present in the publishproj file. The BeforeBuild however is still not executed. I tried running the same command on the develop machine and even there it is not working... Do I have to add an option to the MSBUILD command that says it needs to do some prebuild steps? – BjoVa Mar 15 '16 at 08:14
  • @BjoVa did you add `` to Test1 & 2? – m0sa Mar 15 '16 at 08:17
0

I found the solution...

All the files were in the correct place and the import statements were correctly defined, but if you want to execute the MSBUILD from command line, you have to add some extra parameters.

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

Command line

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

The trick was to add the /t:<Target Name>;Build (don't forget to add the build are else it will only execute the specified target).

BjoVa
  • 43
  • 1
  • 3