Visual Studio Publish Failed: "Unable to delete file ... Access to the path ... is denied."

36,427

Solution 1

I noticed that my folders were read-only. I changed that.

It worked! Publish succeeded.

Folder Properties Read-only

Solution 2

I believe your issue is related to the default permissions assigned the to C: drive in windows 7 (and Vista).

  1. Open explorer and find the c:\code folder
  2. Right click on the c:\code folder and select properties
  3. select the security tab
  4. select the user ID "Users"
  5. In the permissions box, tick the "modify" allow box
  6. Select OK, OK until permision dialog boxes close

That should resolve the permission issue

Solution 3

The most likely cause is a permissions issue. The path in question may have been created while you were running with elevated permissions and hence requires admin permissions to delete. Try running Visual Studio as an admin and see if the problem goes away.

If so then the best solution is to do the following

  1. Save the changes to that directory (check in if necessary)
  2. Delete the repository
  3. Re-check out the repository and ensure you are not running as an admin when doing so

Solution 4

I had this same problem, and none of the previous solutions worked. What worked for me was to take the bin and obj folders out of repository. After doing that, I was able to publish.

Solution 5

Oddly enough, I tried building an old project with Visual Studio 2010. It gave me the error that it failed due to my access being denied. I tried to remove the read-only off the directory and had no luck.

Although, when I opened it in Visual Studio 2015, it gave me the error that my certificate was expired.

Upon creating a new certificate and rebuilding - everything was fine.

Share:
36,427
Zack Peterson
Author by

Zack Peterson

Specializes in the design and creation of web and desktop applications. Contributes in all aspects of the software development process such as: requirements analysis and product definition; prototyping; choosing architecture and framework; interface design; database design; installation and integration; documentation and training; gathering feedback; and maintenance.

Updated on July 03, 2020

Comments

  • Zack Peterson
    Zack Peterson almost 4 years

    I've recently switched from a Windows XP machine to Windows 7. I use Subversion and TortoiseSVN.

    I cannot publish my .NET application in Visual Studio. I get over a thousand errors like this:

    Unable to delete file "obj\Debug\Package\PackageTmp\Views\ViewName.svn\text-base\ActionName.aspx.svn-base". Access to the path 'C:\Code\SolutionName\ProjectName\obj\Debug\Package\PackageTmp\Views\ViewName.svn\text-base\ActionName.aspx.svn-base' is denied.

    Visual Studio: "Publish failed"

    Why is Subversion giving me trouble? How do I fix it?


    I disabled the file indexing of my bin and obj folders. But, that didn't work.

    Allow files in this folder to have contents indexed in addition to file properties

  • Zack Peterson
    Zack Peterson over 13 years
    Thanks. I changed the folder settings. But, that didn't work.
  • Zack Peterson
    Zack Peterson over 13 years
    Thanks. I tried running Visual Studio as an administrator. But, that didn't work.
  • Zack Peterson
    Zack Peterson over 13 years
    Thanks. I recreaded the folder fresh from the Subversion server. But, that didn't work.
  • JaredPar
    JaredPar over 13 years
    @Zack, then that suggests something has the filed opened with non-sharable permissions. Try using handle.exe to see who's holding it open.
  • Jonathan Escobedo
    Jonathan Escobedo over 13 years
    AFAIK Just was a permission issues, Try to set elevated permissions on shared folders but targeting machines, cause otherwise when you use users it wouldn't work
  • BarrettJ
    BarrettJ over 13 years
    I had this problem and this was the fix for me. It was not on the computer the files originated, but one that had done a full get of the project.
  • MetaGuru
    MetaGuru almost 13 years
    Fixed for me as well, I wonder why these were read only by default.
  • kbonnelly
    kbonnelly almost 6 years
    Saved my day ! Thanks. Still wondering how it became a read-only folder..
  • Richard
    Richard about 4 years
    This is still a situation in 2020, for some reasons the bin\roslyn folder is read only, trying to delete it wouldn't work, couldn't take ownership of the directory either (as SA). I Guess: IIS makes the folder Read Only while the App Pool is running to prevent malicious activity against certain libraries.