visual-studio Visual Studio 无法打开文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1317369/
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-10-22 10:53:56  来源:igfitidea点击:

Visual Studio Cannot Open File

visual-studiovisual-studio-2008

提问by thepocketwade

I'm working on my first project in Visual Studio and I haven't used Windows much since '05, so please bear with me.

我正在 Visual Studio 中处理我的第一个项目,并且自 05 年以来我就很少使用 Windows,所以请耐心等待。

I've got my project open in Visual Studio 2008, and I'm trying to open a particular file for editing, but I get an error that says

我在 Visual Studio 2008 中打开了我的项目,我正在尝试打开一个特定的文件进行编辑,但我收到一个错误消息

"c:\path\to\file
Cannot open file.

I've verified that the file exists, and I can open it from Windows Explorer, but nothing from inside Visual Studio, any ideas?

我已经验证该文件存在,我可以从 Windows 资源管理器中打开它,但在 Visual Studio 中没有任何内容,有什么想法吗?



I'm not familiar with Visual Studio, so my terminology might be incorrect.

我不熟悉 Visual Studio,所以我的术语可能不正确。

The file appears in the tree in the Visual Studio Explorer pane, so I double clicked it, and got the error. The error said nothing more than the file path: Cannot open file.

该文件出现在 Visual Studio 资源管理器窗格的树中,因此我双击它,并收到错误消息。该错误仅说明文件路径:无法打开文件。

How can I check permissions/ACLs in Windows? I assumed that since I could open it in Windows Explorer, I would be able to open it in Visual Studio.

如何在 Windows 中检查权限/ACL?我假设因为我可以在 Windows 资源管理器中打开它,所以我也可以在 Visual Studio 中打开它。

And it's a .cpp file.

它是一个 .cpp 文件。

回答by James Black

You may want to right-click on the file in the tree, and delete it from the project.

您可能希望右键单击树中的文件,然后将其从项目中删除。

Then, add back an existing item.

然后,添加回现有项目。

Hopefully that will fix the problem.

希望这能解决问题。

回答by Jeff Wilcox

Though I'm not familiar with this specifically, if you just want to move forward, I'd recommend creating a new project type and just adding all the existing files to it. Should be quicker and easier than diagnosing what could be many issues.

虽然我对此并不特别熟悉,但如果您只是想继续前进,我建议您创建一个新的项目类型并将所有现有文件添加到其中。应该比诊断可能存在的许多问题更快、更容易。

Other things to check: encoding type of the project file, permissions/ACLs (can you open that actual file from an unelevated VS prompt, for instance), etc.

其他需要检查的事项:项目文件的编码类型、权限/ACL(例如,您能否从未提升的 VS 提示中打开该实际文件)等。

回答by ppetrov

Additionnaly to the other answers, I found out that this problem may arrise if the target .Net framework version specified in the project file isn't installed.

除了其他答案之外,我发现如果未安装项目文件中指定的目标 .Net 框架版本,则可能会出现此问题。

This seems to prevent visual studio from opening all the files contained in the project, and showing the "Unable to open file " message.

这似乎阻止了 Visual Studio 打开项目中包含的所有文件,并显示“无法打开文件”消息。

Correcting the version (in the csproj file or in the settings), saving and reloading the project fixes the problem.

更正版本(在 csproj 文件或设置中)、保存并重新加载项目可解决问题。

回答by badradnan98

I had same problem, my project were build on (.Net 4.5), which I uninstalled on my PC and replaced by (.Net 4.8), so just replacing project's target framework to the one which is installed "in my case (.Net 4.8)" should fix it.

我遇到了同样的问题,我的项目是建立在 (.Net 4.5) 上的,我在我的 PC 上卸载了它并替换为 (.Net 4.8),所以只需将项目的目标框架替换为“在我的情况下(.Net 4.8)”应该修复它。