none
Error MSB3021: Unable to copy file. Access to the path is denied.

    Question

  • Hi,

    I am getting this below given below during TFS build

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3513,5): error MSB3021: Unable to copy file "C:\xxx\SharedLibraries\Microsoft.Practices.Modeling.Common.dll" to "C:\xxx\Binaries\Microsoft.Practices.Modeling.Common.dll". Access to the path 'C:\xxx\Binaries\Microsoft.Practices.Modeling.Common.dll' is denied.

    It is giving an error while trying to copy dll from shared reference folder to build binaries folder.

    I am getting this issue for only one particular project in the solution and it is giving this error for any random dll for each builds

    Please help and advise

    Thanks,

    Irfan Khan

    Monday, February 18, 2013 10:36 AM

All replies

  • Do you have pre/post build script for that one project? Are you using relative path?

    Ahmed is an independent consultant in Ottawa, Canada specialized in .NET, Biztalk, WCF, WPF, TFS and other Microsoft technologies.

    Blog: http://lajak.wordpress.com

    Twitter: ahmedalasaad

    Monday, February 18, 2013 10:18 PM
  • We too often get this error message, and typically only on binary files (e.g. DLL files).  For us simply relaunching the build usually fixes the problem.

    Do you have your build definition's Process -> Basic -> Clean Workspace property set to All  (so that it deletes all files before trying to copy files to it)?  If the DLL is still in use by some other process you may not be able to overwrite it.


    - Dan - "Can't never could do anything"


    • Edited by deadlydog Tuesday, February 19, 2013 1:10 AM
    Tuesday, February 19, 2013 1:08 AM
  • Hi Ahmed,

    Thanks for your reply.

    No I am not using any pre/post build scripts for the project. But I am passing the reference path as an MSBuild Argument to the build process

    /p:ReferencePath="C:\Builds\XXX\Main_CI\Sources\SharedLibraries"

    Thanks,

    Irfan Khan

    Tuesday, February 19, 2013 5:15 AM
  • Hi,

    Thanks for you reply.

    Yes, I have set build definition's Process -> Basic -> Clean Workspace property set to All.

    Is this causing the problem?

    Please advise.

    Thanks,

    Irfan Khan

    Tuesday, February 19, 2013 5:19 AM
  • Does C:\xxx\SharedLibraries\ = C:\Builds\XXX\Main_CI\Sources\SharedLibraries?

    Are you including the SharedLibraries folder in the workspace screen as Active not Cloaked

    Ideally you want to use relative path instead of absolute path

    http://lajak.wordpress.com/2011/03/13/pass-relative-path-arguments-to-msbuild-in-tfs2010-team-build/


    Ahmed is an independent consultant in Ottawa, Canada specialized in .NET, Biztalk, WCF, WPF, TFS and other Microsoft technologies.

    Blog: http://lajak.wordpress.com

    Twitter: ahmedalasaad

    Tuesday, February 19, 2013 5:33 AM
  • Irfan,

    This problem occurs when the Shared Libraries are checked in to Source Control. You should have a AfterGet target for removing the READ ONLY attribute.

    Regards,
    Rahul


    P.S.: Found this for VS 2008. Should be similar for 2010.
    Tuesday, February 19, 2013 5:43 AM
  • Hi Ahmed,

    I had the made changes as mentioned in your above post. Used relative path instead of absolute path for MSBuild argument.

    But still I am getting the same error.

    Please advise.

    Thanks

    Irfan Khan

    Tuesday, February 19, 2013 11:51 AM
  • Hi Rahul,

    Hope you are doing fine :)

    Can you tell me how to make the AfterGet target change in 2010, as we are not using the .proj file for the build.

    Thanks

    Irfan Khan

    Tuesday, February 19, 2013 11:54 AM
  • Does C:\Builds\XXX\Main_CI\Sources\SharedLibraries exist? I mean is it copied to the from Source Control to teh Sources folder?

    Ahmed is an independent consultant in Ottawa, Canada specialized in .NET, Biztalk, WCF, WPF, TFS and other Microsoft technologies.

    Blog: http://lajak.wordpress.com

    Twitter: ahmedalasaad

    Tuesday, February 19, 2013 2:42 PM
  • Hi Ahmed,

    Yes, the C:\Builds\XXX\Main_CI\Sources\SharedLibraries folder does exists. And it is copied from source control to the source folder.

    Thanks,

    Irfan Khan.

    Wednesday, February 20, 2013 5:47 AM
  • Hi Irfan,

    You can add a Invoke Process activity to remove the read-only attributes after the Get Workspace activity in your build process template. 

    Below should be the property values of Invoke Process activity.

    FileName: "C:\Windows\System32\attrib.exe"

    Arguments: "-r"

    WorkingDirectory: <specify shared library path>


    Jahangeer

    Wednesday, February 20, 2013 12:18 PM
  • All fine here, Irfan.

    I was under the impression that you are using the Upgrade Template for the builds.

    Scroll down to Jehan33's reply and try that.

    Regards,
    Rahul

    Thursday, February 21, 2013 7:44 AM
  • Hi Rahul,

    Thanks for the reply.

    I dont think this issue is due to the readonly file attribute. Because going through the log file, I also found the below warning

    12>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3513,5): warning MSB3026: Could not copy "C:\Builds\Madagascar\Main_CI\Sources\SharedLibraries\Microsoft.Practices.Services.Itinerary.DslPackage.dll" to "C:\Builds\XXX\Main_CI\Binaries\Microsoft.Practices.Services.Itinerary.DslPackage.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Builds\XXX\Main_CI\Binaries\Microsoft.Practices.Services.Itinerary.DslPackage.dll' because it is being used by another process.

    Please advise

    Thanks,

    Irfan Khan

    Thursday, February 21, 2013 9:13 AM
  • Try SysInternals' ProcessExplorer to find which process is locking the file.

    Regards,
    Rahul

    Thursday, February 21, 2013 9:53 AM
  • Hi,

    After making the below changes the frequency of the error is reduced. Yesterday, we got this error once from the 26 CI build done.

    1) Added /p:OverwriteReadOnlyFiles=true in the for the MsBuild Arguments in the process tab of build definition

    2) Added <GenerateResourceNeverLockTypeAssemblies>true</GenerateResourceNeverLockTypeAssemblies> in the project ".proj" file for which i was getting the "Access to the path ... is denied" error.

    Please, can everyone provide me a solution for this issue.

    Thanks,

    Irfan Khan

    Friday, March 01, 2013 7:12 AM