visual-studio 无法在构建时将文件复制到服务器。访问路径被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1923543/
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
Unable to copy file to server on build. Access to path is denied
提问by Christopher Garcia
I have a solution in Visual Studio that is comprised of 5 projects. The projects build to assemblies (.dll). I have the output path of each project set to \my-web-server\wwwroot\bin, which works fine on one project. In the properties for all of my projects, I have the output path set to the same directory, but when I try building all but one of the projects, I get the error:
我在 Visual Studio 中有一个由 5 个项目组成的解决方案。项目构建为程序集 (.dll)。我将每个项目的输出路径设置为 \my-web-server\wwwroot\bin,这在一个项目上运行良好。在我所有项目的属性中,我将输出路径设置为同一目录,但是当我尝试构建除一个项目之外的所有项目时,出现错误:
Unable to copy file "obj\Release\Index.dll" to "\my-web-server\wwwroot\bin\Index.dll". Access to the path '\my-web-server\wwwroot\bin\Index.dll' is denied.
无法将文件“obj\Release\Index.dll”复制到“\my-web-server\wwwroot\bin\Index.dll”。拒绝访问路径“\my-web-server\wwwroot\bin\Index.dll”。
I assume it could be an issue with permissions, because my organization keeps things locked down, but I have no control over granting permissions. Any help in the right direction is much appreciated.
我认为这可能是权限问题,因为我的组织一直处于锁定状态,但我无法控制授予权限。任何在正确方向上的帮助都非常感谢。
回答by Christopher Garcia
It must've been something silly. I deleted the .dll manually, then rebuilt. Looks like everything's working normally. Thanks.
一定是什么傻事。我手动删除了 .dll,然后重建。看起来一切正常。谢谢。
回答by syclee
回答by Alex Marshall
I had the same issue. A copy of Visual Studio (devenv.exe) was still running invisible in the background keeping the particular dll locked.
我遇到过同样的问题。Visual Studio (devenv.exe) 的副本仍在后台隐身运行,保持特定的 dll 被锁定。
回答by Rupesh Dahibavkar
Delete all DLLs from the bin folder and build the solution.
从 bin 文件夹中删除所有 DLL 并构建解决方案。
回答by rob
just had the same issue, built a new project/solution, got it all working and then added to TFS.
刚刚遇到了同样的问题,构建了一个新项目/解决方案,让它全部工作,然后添加到 TFS。
Unfortunately I did not clean the build before adding and this meant some files that should not have been under source control were and were then read only(not checked out). Manually deleting the files before rebuilding fixed the issue.
不幸的是,我在添加之前没有清理构建,这意味着一些不应受源代码控制的文件是只读的(未签出)。在重建之前手动删除文件解决了这个问题。
回答by Brett Allen
Most likely a program is running using that library.
很可能一个程序正在使用该库运行。
This happens to me when running something to debug, and I forget to close it (not attached to IDE debugger).
我在运行调试程序时会发生这种情况,我忘记关闭它(未连接到 IDE 调试器)。
And since this looks like a website, it is potentially due to the website being hosted from the development build folder, and someone is accessing it.
由于这看起来像一个网站,这可能是因为该网站是从开发构建文件夹托管的,并且有人正在访问它。
回答by Agent_9191
Similar to what Aequitarum said, it's mostly likely a locked file because it's in use. Since you have multiple projects, you mostly likely have references between them. And since you have all the projects outputting to the same folder any of the referenced projects will most likely get copied more than once if you have those files set to be deployed in the child project. (In a C# web application, you can view the properties of the reference and look at the "Copy Local" property.) And if you have the MsBuild project set to use multiple processors for the build, two child projects are both trying to copy the file at approximately the same time and one is erring out.
与Aequitarum 所说的类似,它很可能是一个锁定的文件,因为它正在使用中。由于您有多个项目,因此您很可能在它们之间有引用。并且由于您将所有项目输出到同一个文件夹,如果您将这些文件设置为部署在子项目中,那么任何引用的项目很可能会被复制多次。(在 C# Web 应用程序中,您可以查看引用的属性并查看“Copy Local”属性。)如果您将 MsBuild 项目设置为使用多个处理器进行构建,则两个子项目都在尝试复制文件大约在同一时间,一个出错了。
It's a very unique situation, but it is possible.
这是一个非常独特的情况,但这是可能的。
回答by Padmanaban Arumugam
Working solution
工作解决方案
Just go to Task Manager and search Detail (if its Win10) and search with your application name (for easy search just look at your windows user id wise)
只需转到任务管理器并搜索详细信息(如果是 Win10)并使用您的应用程序名称进行搜索(为了方便搜索,只需查看您的 Windows 用户 ID 即可)
And right click shows properties. just give the permission like Administrator access.
并右键单击显示属性。只需授予管理员访问权限等权限即可。
That's all its working fine for me. ( I was struggling for 1 week and its killed more my time)
这对我来说一切正常。(我挣扎了 1 周,它杀死了我更多的时间)
回答by SVZa
It looks like WSearch Service locks up the files and does not release them. I disabled the service on WINDOWS 10 and was able to rebuild the solution.
看起来 WSearch 服务锁定了文件并且不释放它们。我在 WINDOWS 10 上禁用了该服务,并且能够重建解决方案。

