dougajmcdonald
dougajmcdonald

Reputation: 20057

Create a folder during MSBuild TFS Publish

I'd like to create a folder during my TFS build process, in this case it's a 'TempImages' folder which I don't want as part of the solution, nor source control.

To achieve this locally I set up the following post build action:

IF NOT EXIST "$(ProjectDir)\TempImages\" mkdir "$(ProjectDir)\TempImages\"

This works like a charm, except when using TFS to publish to my test environment the folder is not created. After some googling, I found I may need to perform this action in a slightly different way, so added the following to my .csproj file.

  <Target Name="AfterBuild">
    <Exec Command="IF NOT EXIST &quot;$(ProjectDir)\TempImages\&quot; mkdir &quot;$(ProjectDir)\TempImages\&quot;"></Exec>
  </Target>

Unfortunately, this doesn't seem to have done the trick.

What's the recommended route to create a folder on post build / post deployment through TFS for this purpose?

Upvotes: 0

Views: 1640

Answers (2)

Matt Brooks
Matt Brooks

Reputation: 1604

Both should work. The problem is likely to be that the TempImages folder is getting created in the TFS sources folder instead of the output / drop folder.

You could try changing the $(ProjectDir) property to one of:

$(WebProjectOutputDir)
$(TF_BUILD_BINARIESDIRECTORY)
$(TF_BUILD_DROPLOCATION)

The latter two will only work for TF Build and you will almost certainly need to add a relative path suffix, e.g. $(TF_BUILD_BINARIESDIRECTORY)\MyWebSite\TempImages\.

You can add conditional logic to your post build event or MSBuild target to detect when building from TF Build based on the $(TF_BUILD) property.

http://msdn.microsoft.com/en-us/library/hh850448.aspx

Upvotes: 4

Todd
Todd

Reputation: 309

I would modify the build template and add a custom activity after the build succeeds to create this folder. Here is a link to MSDN on customizing the build template.

Upvotes: 0

Related Questions