C# 无法写入输出文件 - 访问被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18277157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 11:47:05  来源:igfitidea点击:

Could not write to output file -- Access is denied

c#visual-studio-2012permissionscompiler-errorswindows-7-x64

提问by Darian Everett

I recently switched computers and copied all my projects over to my new local drive. I reformatted the computer I'm on now so it was pretty much a clean machine. Everything seemed to be working fine, but when I opened one of my projects that I had been running from my old machine, it would no longer compile, and I get the following error message: Could not write to output file 'c:\Users\user\Documents\Projects\RegressionWeb\OnetouchUpload\obj\debug\OneTouchUpload.dll' -- 'Access is denied.'

我最近更换了计算机并将我的所有项目复制到我的新本地驱动器上。我重新格式化了我现在使用的计算机,所以它几乎是一台干净的机器。一切似乎都运行良好,但是当我打开我在旧机器上运行的项目之一时,它不再编译,并且我收到以下错误消息:无法写入输出文件 'c:\Users \user\Documents\Projects\RegressionWeb\OnetouchUpload\obj\debug\OneTouchUpload.dll' -- '拒绝访问。'

I'm getting an error like that for each project I have in my solution. I'm also getting this error: Unexpected error creating debug information file 'c:\Users\user\documents\projects\RegressionWeb\RegressionWeb\obj\Debug\RegressionWeb.PDB' Access is denied

对于我的解决方案中的每个项目,我都会收到类似的错误。我也收到此错误:意外错误创建调试信息文件 'c:\Users\user\documents\projects\RegressionWeb\RegressionWeb\obj\Debug\RegressionWeb.PDB' Access is denied

I've searched high and low, and the only similar issues I could find online related specifically to ASP.NET and IIS, neither of which has anything to do with my project (My projects are class libraries of mostly NUnit tests with some support classes).

我搜索了高低,我可以在网上找到的唯一类似的问题专门与 ASP.NET 和 IIS 相关,这两个问题都与我的项目无关(我的项目主要是 NUnit 测试的类库和一些支持类)。

I am the administrator on my local machine. I have already taken ownership of every file in the project using takeown /f .\RegressionWeb /r /d y and also tried to ensure that nothing had a status of Read-only, but the following file threw an error when I tried changing the read-only property of it's parent folder: An error occurred applying attributes to the file: C:...\Regressionweb.sln.DotSettings.user Access is denied

我是本地机器上的管理员。我已经使用 takeown /f .\RegressionWeb /r /dy 获得了项目中每个文件的所有权,并且还尝试确保没有任何内容处于只读状态,但是当我尝试更改读取时,以下文件引发了错误- 其父文件夹的唯一属性:将属性应用于文件时发生错误:C:...\Regressionweb.sln.DotSettings.user 拒绝访问

Basically this project was working perfectly and had no errors from my old computer. After copying over everything, this DotSettings.user file will not be modified, and Visual Studio can't write to any of the dll files. I'm sure the answer must lie in a Visual Studio setting somewhere. Any and all suggestions would be greatly appreciated.

基本上这个项目运行良好,我的旧电脑没有错误。复制完所有内容后,此 DotSettings.user 文件将不会被修改,并且 Visual Studio 无法写入任何 dll 文件。我确定答案必须在某个地方的 Visual Studio 设置中。任何和所有建议将不胜感激。

采纳答案by Jacob Smart

I think Karl has it right. I had a similar situation once, and what I did was delete the file in question, clean the solution, and then rebuild. If the project needs that file it should recreate it; in my case it didn't need it because it never recreated it, but the project ran just fine.

我认为卡尔说得对。我曾经遇到过类似的情况,我所做的是删除有问题的文件,清理解决方案,然后重建。如果项目需要该文件,则应重新创建它;在我的情况下,它不需要它,因为它从未重新创建它,但该项目运行得很好。

One other thing I would recommend; you may be selecting the read-only attribute of the parent folder off and selecting this setting to recurse through all sub-folders and files, but that doesn't mean that's what's happening. For all your sub-folders and files (especially the ones that are cropping up as errors) inspect each one individually and make sure the read-only attribute is off.

我要推荐的另一件事是;您可能选择关闭父文件夹的只读属性并选择此设置以递归所有子文件夹和文件,但这并不意味着这就是正在发生的事情。对于您的所有子文件夹和文件(尤其是那些作为错误出现的子文件夹和文件),分别检查每一个并确保只读属性关闭。

回答by Karl Anderson

My money is on your files are read-only. Verify they are read-only and change them or add your files to a source control system and let them get handled by that.

我的钱是你的文件是只读的。验证它们是只读的并更改它们或将您的文件添加到源代码控制系统并让它们处理。

回答by Danexxtone

See if it is related to this:Could not write to output file - Access is denied. That would be a bit of a bugger to track down. In this case the project is self-referencing the dll and preventing access to the file.

看看它是否与此有关:Could not write to output file - Access is denied。这将是一个追踪的麻烦。在这种情况下,项目自引用 dll 并阻止访问该文件。

回答by DevonTaig

I was able to get this working by closing Visual Studio and then opening it again, but being careful to run Visual Studio "As Administrator". To do this, from the Start menu, right click on Visual Studio and choose "Run as Administrator".

我能够通过关闭 Visual Studio 然后再次打开它来使其工作,但要小心地以“管理员身份”运行 Visual Studio。为此,从开始菜单中,右键单击 Visual Studio 并选择“以管理员身份运行”。

回答by Arun Sharma

it seems that the same error is sometimes displayed when the app pool user doesn't have access to the %TMP%/%TEMP% folder.

当应用程序池用户无权访问 %TMP%/%TEMP% 文件夹时,似乎有时会显示相同的错误。

You'll need to grant IIS_IUSRS read and modify access over the temp folder of the user the app pool is running as.

您需要授予 IIS_IUSRS 读取和修改对运行应用程序池的用户的临时文件夹的访问权限。

This could either be the temp folder in the app pool user's profile, e.g. c:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp, or the system temp folder at c:\windows\temp.

这可以是应用程序池用户配置文件中的临时文件夹,例如 c:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp,或位于 c:\windows\temp 的系统临时文件夹。