user2019295
user2019295

Reputation: 23

MSBuild Issue while deploying files

I am deploying some files on the server. But when I am doing this, build is deleting all the files and folder which are residing at that location. I don't want to delete all the files from the server. I want to exclude one folder (folder name is Temp) from the destination folder. Temp folder should not get deleted while deleting other files. How to do that?

Here is TFS Build Definition

<PropertyGroup Condition=" '$(DeployEnvironment)' == 'Dev' "> 
<DeployPath>\\server1\D$\temp\reports</DeployPath> 
</PropertyGroup> 
<Target Name="CoreCompileSolution" /> 
<Target Name="AfterCompile"> 
   <Message Importance ="high" Text="Solution Root: $(SolutionRoot)" />
   <Message Importance ="high" Text="Out Dir: $(OutDir)" />
   <Copy SourceFiles="@(RPTFiles)" DestinationFolder="$(OutDir)_PublishedWebsites\Reports\" /> 
 </Target>
<Target Name="AfterDropBuild" > 
  <CreateItem Exclude="$(DeployPath)\Temp*.*"> 
      <Output ItemName="PreviousDeployment" TaskParameter="Include" /> 
  </CreateItem>
</Target>

Upvotes: 2

Views: 324

Answers (1)

Isantipov
Isantipov

Reputation: 20929

Why are you using a Copy task? I think it is intended to be used for local manipulations during build, rather than deployment (because it does not give you a chance to easily configure behaviour).

I suggest that instead of copy tsak you use one of the following options

  • Non-web applications - use Robocopy: /XD dirs [dirs]... : eXclude Directories matching given names/paths. XF and XD can be used in combination e.g.

    ROBOCOPY c:\source d:\dest /XF *.doc *.xls /XD c:\unwanted /S 
    

    see this link for usage guide. You either run it from the command line (using <Exec Command="" > task, or employ MBuiild Community Tasksproject which has a nice wrapper.

  • Web applications: you should use Web Deploy for your deployments. You an either use MSBuild integration (VS 2010 and later, see this blog series for guidance on setup and configure on VS2010 NB: it has been much simplified in VS 2012, but I don't have a link to share at the moment) or run it from command line (prior to VS 2010):

    <Exec Command="&quot;$(WebDeployToolPath)&quot; -verb:sync - source:dirPath='$(MSBuildProjectDirectory)\Published\' -dest:dirPath='$(DeployDirectoryLocalPath)',computerName=$(DeployTargetURL),userName='$(DeployUserName)',password='$(Password)',authType='Basic' -skip:skipaction='Delete',objectname='filePath',absolutepath='app_offline.htm' -skip:skipaction='Delete',objectname='filePath',absolutepath='logs\\.*' -skip:skipaction='Delete',objectname='dirPath',absolutepath='logs\\.*' -skip:skipaction='Delete',objectname='filePath',absolutepath='UserFiles\\.*' -skip:skipaction='Delete',objectname='dirPath',absolutepath='UserFiles\\.*' -verbose -allowUntrusted" />

NB using skip:skipaction='Delete.. to skip removing files and folders.

Update It looks like I've undestood this a bit incorrect (I supposed, deployment happenned in AfterCompile target, however, as I see now, TFS uses CoreDropBuild target to do the deployment. So I think, what you need is to override CoreDropBuild target as described: here. (although, I've never tried this).

You can either use Copy task as the author of the thread, or go with Robocopy/webdeploy based on your personal preference.

Upvotes: 1

Related Questions