简体   繁体   English

如何阻止asp.net阻止访问文件然后在构建时抛出访问被拒绝的错误?

[英]How can I stop asp.net from blocking access to files then throwing access denied errors on build?

I repeatedly get build errors along the lines of the following: 我反复按照以下方式获得构建错误:

Failed to make the following project runnable: < project name >(.NETFramework,Version=v4.6.1) reason: Access to the path 'C:\\< path from root >\\src\\< project name >\\bin\\Debug\\net641\\win7-64x\\< some dll, exe, config, whatever >' is denied. 无法使以下项目可运行:< 项目名称 >(。NETFramework,Version = v4.6.1)原因:访问路径'C:\\ < 从根路径 > \\ src \\ < 项目名称 > \\ bin \\ Debug \\ net641 \\ win7-64x \\ < some dll,exe,config,whatever >'被拒绝。

I was getting similar errors from other folders but taking them out of source control helped (see below) 我从其他文件夹中得到了类似的错误,但是将它们从源代码控制中删除了(见下文)

Sometimes manually going to the folder in Explorer > right click > properties > uncheck "read only" works for a successful build but then either VS or TFS locks the file again and the same build error returns 有时手动转到资源管理器中的文件夹>右键单击>属性>取消选中“只读”适用于成功构建但是VS或TFS再次锁定文件并返回相同的构建错误

In particular at the moment there are two .dll files being added to the bin which are repeatedly set to "read only" and I have to manually fix that in file explorer upon rebuild. 特别是目前有两个.dll文件被添加到bin中,它们被重复设置为“只读”,我必须在重建时手动修复文件浏览器中的文件。 AFAIK these are not in source control, but the files in another project within the solution by the same name are checked in and not changing. AFAIK这些不在源代码管理中,但是同一个名称的解决方案中的另一个项目中的文件会被签入并且不会更改。

It may have something to do with the fact I'm using asp.net Core RC2 which is not official yet, plus I'm pairing it with Angular 2 RC1 but I don't think that's related. 它可能与我正在使用的asp.net Core RC2这个事实有关,而且我正在将它与Angular 2 RC1配对,但我不认为这是相关的。

One theory is that it has something to do with TFS since the errors don't seem to start until I put the project under source control. 一种理论认为它与TFS有关,因为在我将项目置于源代码控制之前,错误似乎没有开始。

I've seen a number of similar questions on Stack Overflow but no answers that even begin to resolve my own repetitive problem. 我在Stack Overflow上看过很多类似的问题但是没有答案甚至开始解决我自己的重复问题。

HINT: I was getting the same with transpiled .ts > .js files and taking them out of source control seems to have helped but I don't see the bin folder in source control at all (of course it's hidden in the solution explorer and I see no option to unhide in source control explorer, so not sure if it's there at all...) 提示:我对转换后的.ts> .js文件进行了同样的操作并将它们从源代码控制中取出似乎有所帮助,但我根本没有看到源代码控制中的bin文件夹(当然它隐藏在解决方案资源管理器中我看不到在源代码管理浏览器中取消隐藏的选项,所以不确定它是否在那里...)

The problem appears to be TFS integration with .net Core, or something with TFS anyway. 问题似乎是TFS与.net Core集成,或者无论如何都与TFS集成。

The solution is generally to subvert TFS, which is unwieldy and should not be necessary. 解决方案通常是颠覆TFS,这是不实用的,不应该是必要的。 Here are a few things I've done... 以下是我做过的一些事情......

  • Using a .tfignore (similar to .gitignore) to prevent certain files (such as transpiled .ts => .js) from being checked in. This does not work without taking weird steps like installing this... 使用.tfignore(类似于.gitignore)来阻止某些文件(例如transiled .ts => .js)被检入。如果不采取像安装这样的奇怪步骤,这是行不通的...
  • Simply checking out and locking up any files still giving me trouble (see my answer to my other question here ) 只需检查并锁定任何仍然给我带来麻烦的文件(请参阅我在这里回答我的其他问题)
  • Just about any other tactic to prevent TFS from checking in files that it shouldn't (sometimes as bad as just leaving them in the "Excluded Changes" list until someone else needs access, at which point I have to delete them all and/or undo all the changes) 几乎任何其他策略都可以阻止TFS检查它不应该检查的文件(有时候只是将它们留在“排除的更改”列表中,直到其他人需要访问权限为止,此时我必须全部删除它们和/或撤消所有更改)

All in all, I really hope Microsoft gets most or all the terrible bugs I've encountered worked out by the time .net Core is released officially. 总而言之,我真的希望微软能够获得我遇到的大部分或者所有可怕的错误.net核心正式发布。 At this point I'm sorely tempted to become a node.js developer. 在这一点上,我非常想成为node.js开发人员。

I found a work-around for this issue when it is file <project name>.exe.config causing the problem. 当文件<project name>.exe.config导致问题时,我找到了解决此问题的方法。 Since that file is basically a copy of app.config I tried checking out app.config and the problem went away. 由于该文件基本上是app.config的副本,我尝试检出app.config ,问题就消失了。

I was dead in the water because I couldn't compile the project. 我死在水里,因为我无法编译项目。 I hope this helps someone that is in the same predicament. 我希望这可以帮助处于同样困境的人。

I've added in the script section a postcompile: 我在脚本部分添加了一个后编译:

"postcompile": [
  "cmd /c echo Removing read-only attributes in %project:Directory%\\bin\\ && cmd /c attrib -r  %project:Directory%\\bin\\* /s",
  "cmd /c echo Removing read-only attributes in %project:Directory%\\..\\packages\\ && cmd /c attrib -r  %project:Directory%\\..\\packages\\* /s"
]

works well for me 适合我

It seems this issue is under tracking, you can monitor it at link: 看来这个问题正在跟踪中,你可以在链接上监控它:

https://github.com/dotnet/cli/issues/3419 https://github.com/dotnet/cli/issues/3419

I ended up removing app.config, and moving it's contents to project.json. 我最终删除了app.config,并将其内容移动到project.json。

App.config contents (one that I removed): App.config内容(我删除了一个):

<configuration>
   <runtime>
      <gcServer enabled="true"/>
   </runtime>
</configuration>

Added this to project.json: 将此添加到project.json:

"runtimeOptions": {
  "configProperties": {
    "System.GC.Server": true
  }
},

I also installed latest dotnet/cli from github which has the fix for package folder DLLs with same issue. 我还从github安装了最新的dotnet / cli ,它修复了包含相同问题的包文件夹DLL。 I used .NET Core SDK Installer and dotnet --version now shows 1.0.0-preview3-003585 . 我使用.NET Core SDK安装程序dotnet --version现在显示1.0.0-preview3-003585

Remember to , remove \\bin folder manually after you make changes and before you run next build. 请记住 ,在进行更改之后以及运行下一次构建之前,请手动删除\\bin文件夹。 Clean task does not remove all the files. 清洁任务不会删除所有文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM