VS 2005 保存时编译 C#
这让我感到困惑,我无法找到这个设置(如果存在)。 我 90% 确定我的代码之前可以在保存时进行编译。 我只是在使用 C# 时才开始遇到这个问题,.net 工作得很好。
但现在,当选择进入调试模式时,我只能摆脱错误行等。 例如,当我有一个方法时
public bool Method1(){
//No code added yet so I get a blue line saying return something
}
,即使我在方法中添加要返回的内容,该行在保存时仍保留在那里。它只会在我构建时消失。
(这只是一个例子,它似乎与许多其他事情一起发生)
编辑 - 关于保存时编译的选项。
构建和运行中的选项设置正确
This is baffling me, I am unable to find this setting if it exists.
I am 90% sure that my code used to compile on save before.
I only started having this issue when using C#, .net worked fine.
But now I am only able to get rid of error lines etc, when choosing to enter debug mode.
For example when I have a method
public bool Method1(){
//No code added yet so I get a blue line saying return something
}
Even when I add what to return inside the method the line remains there on save. It only goes away when I build.
(This is just one example it seems to happen with lots of other things)
EDIT - In regards to options to compile on save.
The options in Build and Run are set Correctly
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该会在错误列表窗口中产生红色下划线和一个条目:“并非所有代码路径都返回值”。它是由 IntelliSense 解析器生成的,而不是编译器生成的。保存文件并不能消除错误提示,只有打开另一个项目才能消除错误提示。当然还要修复代码。
此逻辑中存在某种错误,在某些情况下错误列表不会被清除。我见过的唯一解决方法是重新启动 Visual Studio。我只在某些 IntelliSense 警告中看到过这种情况,并且它只影响错误列表,而不影响编辑器。我不记得触发此问题的确切警告类型,只有在使用我没有编写的代码打开项目时才会发生这种情况。当我编辑代码时,这些消息通常不会持续很长时间。这是迄今为止最好的解决方案。
That should produce a red underline and an entry in the Error List window: "not all code paths return a value". It is produced by the IntelliSense parser, not the compiler. Saving the file does not remove the error hint, only opening another project does. And fixing the code of course.
There is a bug of sorts in this logic, in some cases the Error List doesn't get purged. The only workaround I've seen is to restart Visual Studio. I've only seen this with certain IntelliSense warnings and it only affects the Error List, not the editor. I can't remember the exact type of warning that triggers this, it only ever happened when opening a project with code I didn't write. These messages don't normally last long when I'm editing code. Which is by far the best solution.
难道不应该反过来吗?编译时保存。
无论如何,您可以简单地在设置菜单中更改 ctrl+s 组合键来构建和保存。
Should it not be the other way around? Save on compile.
Anyway, you can simple change the ctrl+s key combination to build and save in the settings menu.