3

With TFS Build 2010, I have build process running devenv.com for several projects. After that, I want all the binaries to be copied from the output folders with C# Custom Build Activities with "File.Copy". However, it threw me this exception with the first copy of the file:

The process cannot access the file 'C:\Test\BuildServer\Sources\Library\LibraryInstall\LibraryInstall\Release\LibraryInstall.msm' because it is being used by another process.

It seems the file is still been using by the devenv.com. Any idea how? Other than File.Copy, is there any better way to copy it regardless the file status?

======

I found an ugly way:

Process proc = new Process();
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = @"C:\WINDOWS\system32\xcopy.exe";
proc.StartInfo.Arguments = "/Y " + Path.Combine(sourcesDirectory, fileName) + " " + binariesDirectory;
proc.Start();
lannyboy
  • 467
  • 2
  • 8
  • 20
  • 1
    On the buildin Copy Task there is a retries and retrydelay setting. Although it masks the real problem it might be an ugly quick fix. http://msdn.microsoft.com/en-us/library/3e54c37h.aspx – rene Nov 25 '11 at 10:15
  • 1
    IT sounds like you have not setup dependencies correctly and/or running a parallel build. – leppie Nov 25 '11 at 10:17
  • Can't you add a Post Build task to your build process? – Jahan Zinedine Jan 20 '12 at 18:25

2 Answers2

0

Devenv is an agressive file locker. If you can build your projects by creating an MSBuild file and bypassing devenv you'll be better off. Some project types can only be built with devenv though, you've not specified what project types you are using so this may not be an option.

MSBuild has a feature called "node reuse" whereby it creates processes that can hang around for up to 15 minutes as an optimization for subsequent builds. It may be that the node reuse combined with devenv's file locking behavior is giving you trouble.

You've not made it clear just exactly how you are executing your build, but if MSBuild is involved, you could try to specify the /nodereuse:false option to disable this feature.

I've also seen rogue MSBuild and devenv process hang onto files, they can get hung up and stay around forever until you kill them if there are obscure exceptions in your build.

Brian Kretzler
  • 9,748
  • 1
  • 31
  • 28
0

I have few amateur things. Don't put a minus on my answer =)

First, take a look at this answer to change your algorithm little bit

  • You can create batch file which includes same ugly method in it. Then call this batch file from C#
  • Maybe you can use FileStream.. binary read-write
  • Maybe you can import vb referance to your project and use ( non-sense )
  • Or directly kill the process which accourding with this error.

And here is an another search, please take a look this question too.

This is the last and hard-core long shot.

Best Regards...

Community
  • 1
  • 1
Lost_In_Library
  • 3,265
  • 6
  • 38
  • 70