Unable to copy file, Access to the path is denied

2019-01-10 05:53发布

问题:

I am using visual studio 2005 after taking code from version control first run c#.net application correctly, but after doing some modification, when I build I am getting an error like this.

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 any body know why this issue is coming?

Edit I can see my complete project source code physical folder is Read-only, I am not able to remove that readonly property

First any body tell me how to remove Read-only property for a folder I have removed but still it showing that one, I tried from version control side also but same effect.

回答1:

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



回答2:

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



回答3:

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.



回答4:

Kill process VBCSCompiler.exe and rebuild.



回答5:

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.



回答6:

Run your Visual Studio as Administrator



回答7:

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



回答8:

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!



回答9:

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


回答10:

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.



回答11:

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



回答12:

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.



回答13:

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.



回答14:

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



回答15:

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.



回答16:

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


回答17:

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.



回答18:

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



回答19:

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.



回答20:

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



回答21:

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.



回答22:

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.



回答23:

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

  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...



回答24:

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)



回答25:

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").



回答26:

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.



回答27:

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.



回答28:

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

And Rebuild!!



回答29:

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!!



回答30:

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