267

I am using Visual Studio 2005. After taking code from version control first, the c#.net application runs correctly. But, after doing some modifications, when I build I am getting the following error:

Error 383 Unable to copy file "..\root\leaf\Bin\Debug\test.Resources.xml" to "Bin\Debug\test.Resources.xml". Access to the path 'Bin\Debug\test.Resources.xml' is denied. li.rollmodel

Does anybody know why this issue is occurring?

Edit I can see that my entire project source code folder is Read-only, and I am not able to remove the read-only property.

First, can anybody tell me how to remove the Read-only property for this folder? I have tried removing it but the read-only property persists. I tried from the version-control side also and that did not work, either.

RoastBeast
  • 1,059
  • 2
  • 22
  • 38
ricky
  • 2,771
  • 2
  • 16
  • 15
  • Is this on a network share? Do you have administrative access on your machine? This question might be a better fit on serverfault or superuser. – arunkumar Aug 20 '11 at 06:42
  • no,, i am using my own machine i have administrative access – ricky Aug 20 '11 at 06:46
  • i solved that problem by manually copying the file from one location to required location,porbably the problem is related to MSBUILD with readonly file – ricky Aug 20 '11 at 07:44

47 Answers47

316

I solved this problem by deleting the contentious files from bin folder and rebuilding the project.

DiligentKarma
  • 5,198
  • 1
  • 30
  • 33
  • 54
    old post, I know, but I had the same issue just now. Make sure that VS is also closed as it will deny access to delete the folder in some cases – Eon Jun 21 '13 at 11:24
  • Worked last time when I had this problem, but now NOT anymore. I allowed Everyone all the permissions over the bin folder and no result. – Dalibor Sep 09 '16 at 11:16
  • I had a similar fix. I solved it by deleted the package source (aka packages\ ) – Dan Csharpster Jan 20 '17 at 16:14
  • 2
    Little note: I didn't understand, at first, I have to delete these files in the output folder of the main project and not in the output folder of the dll. So, warning here :) – Piero Alberto Mar 01 '17 at 15:58
  • 6
    In my case, even closing VS was not enough to free the folder and allow me to delete it - ProcessExplorer showed that "VBCSCompiler.exe" was still using it. In this case, signing out of and into Windows (or just killing the process) did the trick, allowing me to rebuild the solution and get everything working again. – S. Jensen Sep 15 '17 at 13:58
  • 2
    in my case the reason that folder and the solution turned into ReadOnly and subsequently VS had trouble building it, was because some file failed to synch to GoogleDrive and got somehow locked by that process. So for me to rebuild properly I had to close GoogleDrive and then it built just fine. – konrad Sep 20 '17 at 21:21
  • Did not work in VS2017, but I don't get these errors when I build in the release mode. – S52 Oct 20 '17 at 17:12
  • 2
    I found Bitdefender Antivirus Free to be the culprit. – Warwick Dec 08 '17 at 09:39
  • 1
    Using Visual Studio 2017 with Dropbox. Had to renaming the bin folder to bin_old in the offending project then allowed me to rebuild. – Brian Dec 17 '17 at 20:25
133

Just make sure that the folder is NOT Read-Only and rebuild the solution

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
  • 14
    I am trying to remove the 'Read-only' checkbox filled with Green color. When I click 'Apply' and then 'Ok', and then check the properties of that folder again, I can again see in the previous state (again having 'Read-only' checkbox filled with Green color). Anyone having solution on this? – Vikram Jul 30 '15 at 15:55
  • Also, make sure the file is not locked. In my case, the file was on a share and someone else had it open. – Dan Bechard Oct 01 '15 at 18:20
  • Close Visual Studio before removing read only attribute. Because the file in question may be in use (locked) – Gautam Jain Nov 07 '16 at 14:55
  • 4
    Created a Visual Studio Extension for clearing ReadOnly and Hidden attribute of dlls which blocking the build. UnBlockDllExtension : https://marketplace.visualstudio.com/items?itemName=NithinVR.UnBlockDllExtension – vrnithinkumar Feb 21 '17 at 18:37
78

I solved this problem: Close Visual Studio, open it again and load the solution, Rebuild your solution. My problem occurred using TFS and VIsual Studio 2010.

jordenysp
  • 2,644
  • 22
  • 17
53

Kill process VBCSCompiler.exe and rebuild.

Hakan Fıstık
  • 16,800
  • 14
  • 110
  • 131
MuriloKunze
  • 15,195
  • 17
  • 54
  • 82
26

Run your Visual Studio as Administrator. Or you can add write permission to "Users" on the output folder

Alejandro Haro
  • 1,355
  • 17
  • 14
  • 1
    Note: here is a short and simple way to always run as administrator by default https://stackoverflow.com/questions/12257110/can-you-force-visual-studio-to-always-run-as-an-administrator-in-windows-8 – wmebane Nov 06 '17 at 21:07
  • 1
    This answer told me enough that I knew to just add write permission to "Users" on my output folder - and that instantly solved my problem (which was that I couldn't publish even the first time). – X Goodrich Oct 25 '19 at 21:22
  • 2
    What an insanely dangerous suggestion. Not only is it irresponsible to advise anyone uncertain enough about what is going on to bypass security, building as admin will hide any deployment problems your code has. – Paul Childs Feb 16 '21 at 00:16
24

I stepped into this problem too.

First go and check if you have mapped your bin and obj folder to the Source Control program.

This may be turning your files from binaries folders into read only archives, which make impossible to visual studio to overwrite them when it compiles the code.

Go and remove the mapping from these folders, check the changes and try again.

My problem occurred using TFS(Team foundation server) and Visual Studio 2010.

Hope this helps someone.

Heitor Corrêa
  • 371
  • 3
  • 6
18

In my case it was the antivirus which blocked the file.

Claudiu Constantin
  • 2,138
  • 27
  • 38
14

In my case, avast anti-virus quarantined the [app-name].exe file that needs to be copied so from the avast app, I had to go to protection > Quarantine, click the menu button beside the file and click 'restore and add exception' as shown below

enter image description here

Olawale david
  • 1,457
  • 1
  • 9
  • 13
11

I use Visual Studio 2013. I faced this problem 2 times:

  1. On first occasion, I was running Visual Studio without Administrator rights. So, I closed VS and started it using 'Run as administrator' option. This solved my problem.

  2. On second occasion, I restarted VS many times, every time making sure that I am running it as an administrator. Also, I rebuilt solution many times. But, in spite of that I was getting error. After that, I removed the concerned file from the target location (the file was already present may be from the previous build at the location where it tries to copy to) and rebuilt the solution. After that, error went away and everything ran smoothly!

Gueorgui Obregon
  • 5,077
  • 3
  • 33
  • 57
Vikram
  • 3,996
  • 8
  • 37
  • 58
10

First go to location of the file. Then right click on the folder of the file -> Properties -> Unchecked Read Only Option and apply to files and its sub folders. It resolved my issue. Happy Coding!

Vinayak Savale
  • 538
  • 6
  • 7
8

This has reared it's head again in Visual Studio 2017, in this case the cause is the Application Insights process ServiceHub.DataWarehouseHost.exe.

There is a workaround discussed in the thread warning MSB3026: Could not copy "obj\Debug\netcoreapp1.1\src.pdb" to "bin\Debug\netcoreapp1.1\src.pdb", which is to add a pre-build event to the project to kill the process every time the project is built. Quoting from that link:

  • Right click properties on project
  • Choose properties
  • Build Events
  • Pre-build event command line
taskkill /IM ServiceHub.DataWarehouseHost.exe /F 2>nul 1>nul
Exit 0
  • Save and build
tomRedox
  • 28,092
  • 24
  • 117
  • 154
7

Can any body know why this issue is coming?

Looking at your response that you resolved your problem by manual copying, I would say that the code you were working on was made by some other user (with administrator privileges too) so it was locked to you. By performing copy --? paste, you made your OWN copy of the source with all access you required. The only thing to notice is that, in this case if this other developer will need to work on your copy, he/she will jump in pretty same problem you got before.

MuKa
  • 165
  • 2
  • 2
  • 13
Tigran
  • 61,654
  • 8
  • 86
  • 123
5

Old post, but this zombie is hitting VS 2017 (I haven't dug into why it's just "some" projects). In this case, it's not user permissions, rather IIS Express process is still using the files.

You'll see the icon in your task tray IIS Express icon

  1. Right Click
  2. Exit
  3. You should be able to rebuild without this annoying "permission denied" message.

This is also why "restarting Visual Studio" will "fix" the issue. Doing so, stops IIS Express.

Hth...

EdSF
  • 11,753
  • 6
  • 42
  • 83
4

I re-added all of my non-.NET dependencies / references and it did the trick.

shawn
  • 591
  • 4
  • 2
4

I resolved this issue myself. The problem was I had the solution opened in another place. After closing it it works

Henley
  • 21,258
  • 32
  • 119
  • 207
4

Had the same problem, but restarting Visual Studio every time was no option for me, as the issue occurs sometimes very often.

I handled it by installing Unlocker (tries to install any toolbar at installation, so don't forget to uncheck this), this application gives me fast access to rename/delete a locked ".xml"-File. I know that this only a workaround too, but for me it was the fastest solution to solve this problem.

David Leitner
  • 3,312
  • 1
  • 18
  • 27
4

Most of the answers I have seen are objectively exploring possible issues with the environment, which is probably correct for 99% of the people running into this issue (unable to copy file from ... to ... access is denied).

I thought I should share my experience for the 1% who ran into this problem due to misc reasons.

I wrote a batch file renaming program that i use to act on tens of thousands of files, and my AntiVirus interpreted it as trojan and auto quarantined it. Having this path sit in my AntiVirus' blacklist, visual studio can never copy the *.exe into the bin folder, hence resulting unable to copy .exe.

My resolution is to whitelist this path and the issue is resolve.

Cheers.

Ji_in_coding
  • 1,691
  • 1
  • 14
  • 17
3

I created this problem when I added a new setup project to the solution, and then added files directly from the /bin/release folder of the main application project to the application files folder of the setup project. The source control of the setup project was consistently blocking me from completing a build of the main application project.

Solution: create a separate dump folder outside of any of the projects that will contain all the files to be included in the install, and add them from there. It's a pain because now I have to remember to copy all the files for each new install package. I might see if I can do something with post-build actions our an automated build to make the process smoother.

portia
  • 124
  • 5
3

If you copy any files across to a solution, make sure the files are not in Read Only mode. Right click on file and uncheck the attribute option solved my problem.

InitialV
  • 96
  • 1
  • 5
3

I had the same error but I am using Perforce version control. Here's how I fixed it.

  1. Closed Perforce P4V client
  2. Restarted Visual Studio 2010 (might not be necessary)
  3. Rebuilt the project, which succeeded
  4. Felt exceptionally happy and disgusted at the same time
Madmartigan
  • 143
  • 1
  • 7
3

I also had same problem. I got error messages that related to cannot copy since access to path denied. In my case all my dll's and xml files and so on are place at D:\TFS\Example\Bin\Debug folder.

I right clicked on Bin folder and clicked Properties and saw that Read-only check box is checked under Attributes.

I un-checked Read only check box and cliked Apply and clicked OK on the new popup that is shown.

I went back to Visual Studio and build my solution which was giving me error messages.

Voilaa.. This time it build successfully without errors.

I donot know whether this is perfect but I did this to solve my issue.

Ziggler
  • 3,361
  • 3
  • 43
  • 61
3

Check Task Manager and make sure you don't have a devenv.exe process hanging. Kill the runaway process and try again.

3

Go to file's path then un-check read only checkbox of this file.

2

I know its an old thread but for those looking for answers, like me a few minutes ago, I recommend trying to restart your computer first. That alone fixed for me. Before could not even manualy copy to the folder.

Joao Leme
  • 9,598
  • 3
  • 33
  • 47
2

Just right click on your MVC project and click on the clean option. I had a similar problem and cleaning the project before rebuilding resolved it for me.

Ehsan
  • 31,833
  • 6
  • 56
  • 65
2

I had also the same problem. I fixed it by unchecking the Read-only properties of root folder.

2

I also had this issue. Here's how is resolved this

  • Exclude bin folder from project.
  • Close visual studio.
  • Disk cleanup of C drive.
  • Re-open project in visual studio.
  • And then rebuild solution.
  • Run project.

This process is works for me.

Manoj
  • 4,951
  • 2
  • 30
  • 56
2

I was able to resolve the problem by removing the target file which is complaining(in your example "Bin\Debug\test.Resources.xml") from bin folder of target web site and re build it.That fixed it for me.

Rama Krshna Ila
  • 486
  • 3
  • 11
2

I tried everything here, somehow deleting all the bin and obj folders in my project didn't work. Releasing the folders from other processes did nothing. Restarting did nothing. Removing read only from every file by unchecking it on the main folder didn't help.

Every dependency ended up adding themselves to the problem. Building directly in the dependencies' folder worked so I was confused. I was going to duplicate this question but I found something that worked.

You know what worked?

dotnet clean

Dominic Grenier
  • 337
  • 1
  • 4
  • 14
1

Make sure you append the file name after the path name (path\fileName.extension). I spent more than one hour without note this.

Marlon Vidal
  • 669
  • 4
  • 14
1

Changing the output path worked for me in Visual Studio 2015. This should help - Changing the Build Output directory

close2zero
  • 85
  • 8
1

1) close the visual studio solution

2) navigate to command prompt --> run as administrator--> iisreset /stop

3) navigate to c--> Windows --> Microsoft.Net --> Framework64--> v4.030319--> Temporary Asp.NET Files --> Delete all the files and folders in this path.

4) Navigate back to command prompt --> iisreset /start

5) Now open the visual studio --> run as administrator --> clean the solution and build it(don't rebuild..just build worked for me)

Krishna
  • 7,290
  • 3
  • 25
  • 25
1

I had the same issue, To resolved this i had checked/done several things

What Didn't work

1) Read/write permissions were given to directory 
2) Restarted visual studio
3) Tried deleting visual studio temp files

What worked at last

Just paste the command given by Fred Morrison into the "Package Manager Console":

Get-Process | Where-Object -Property Name -EQ 'VBCSCompiler' | Stop-Process -Force -Verbose

Note: Just an observation Restarting Visual studio might not work in this case but restarting system can because stoppin process "VBCSCompiler" was the solution so we can do it either way.

Chiragkumar Thakar
  • 3,616
  • 5
  • 37
  • 49
1

For those who still face this issue in VS 2019

1- Open terminal

2- write 'dotnet clean '

Fadi
  • 585
  • 4
  • 22
0

So I just ran into the same issue, the cause of mine, I had my development folder shared so I could use a mac as a build host for an IOS application using Xamarin. The project was running on mac which took ownership of the dll therefore I could not make changes to that dll from anywhere else. Simply stopping the application on the mac returned ownership back to me which allowed full access again. I hope this make since.

Jon Willis
  • 36
  • 1
  • 4
0

Clear all referenced libraries in "bin\debug" and right click to Solution in solution explorer after click to "Clean Solution".

And Rebuild!!

0

I ran into this issue multiple times, and the solution which I found is to delete the debug folder and then rebuild your solution/project. Worked for me!!

patil.rahulk
  • 574
  • 1
  • 3
  • 13
0

This can be a strange by-product of loading source initially from source control (TFS etc.) where all files and folders are write protected. Go to the top level directory and check the properties and you could find the Read-only attribute checked. Uncheck that and the system should ask you if you want all the dirs under the top level to be set the writable. This should fix it.

pat capozzi
  • 1,412
  • 1
  • 20
  • 16
0

I tried to log off and log back in and it worked for me. Hopefully this will help someone else.

desiguy
  • 652
  • 2
  • 9
  • 25
0

In my case, I ported a project from Windows to OSX, using Visual Studio Community 7.1.5 for Mac. What did the trick was disabling the Use MSBuild engine (recommended for this type of project)option on the project preferences:

enter image description here

0

For me the issue was that another project in the solution had the same .dll file which had been checked in more recently.

Manually copying the more recently checked in version of the .dll from the other project bin folder to bin folder in the project that was generating the error fixed the problem.

A longer term fix for our solution would be to use the same exact .dll for all projects in the solution instead of having the same .dll file in multiple projects but I didn't feel like tackling that so the quick-and-dirty solution was to just copy over the newer version.

rsmith
  • 83
  • 6
0

after trying almost everything just copy pasted the project on different location and built the project... and it worked.

Er.Imran Shaikh
  • 309
  • 3
  • 7
0

Mine started happening after installing Windows Update KB5003637. My VS2019 project was running fine beforehand, but got this error after installing the Windows Update. Uninstalled it and project works again.

0

For those using Net.Core:

dotnet clear might solve sometimes, but the surefire way to solve this is to simply kill all and any dotnet running processes:

taskkill /im dotnet /f

Note that if you have other Rider/Visual Studio instances running, they'll drop.

Eric Wu
  • 908
  • 12
  • 35
0

You aren't supposed to change the folder attribute to not-readonly. The reason you are seeing this error message is that source control assumes that you only store your miscellaneous files somewhere other than bin folder, for it it reserved for files that are automatically created by .Net and it doesn't want to add them to source control.

I suggest instead of using Environment.CurrectDirectory (which I assume you are using currently), you create a folder named "MyProjectName" in %appdata% address and then use:

System.IO.Path.Combine(Environment.GetEnvironmentVariable("appdata"),"YourProjectName").

Bizhan
  • 16,157
  • 9
  • 63
  • 101
-1

If someone wants an extra simple solution before trying anything else.

Simply restart your PC. Open Visual Studio, try to build again.

Blake Rivell
  • 13,105
  • 31
  • 115
  • 231
-2

Simple Solution:

Just upgrade the following packages

Microsoft.CodeDom.Providers.DotNetCompilerPlatform v1.0.5 to v1.0.7

It will resolve the issue.

Dotnetpickles
  • 1,016
  • 8
  • 13