为什么CW codesnippet生成global :: system.console.writeline();
考虑到我的代码的此简短版本,按照以下:
using Microsoft.EntityFrameworkCore;
var opt = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite("ConnectionString...").Options;
using var dbCon = new MyDbContext(opt);
dbCon.Authors.Include(a => a.Books.Where(b => b.PublicationYear > 2021)).ToList().ForEach(author =>
{
// cw generates following model
global::System.Console.WriteLine();
});
// cw acting normal
Console.WriteLine();
new List<object>().ForEach(a =>
{
// cw acting normal
Console.WriteLine();
});
当使用cw
codesnippet dbcon.authors.include.include.include ...
block,block,block, Visual Studio生成global :: System.Console.Writeline();
,但是在其他情况下,在上面代码中提到的其他情况下,它的正常情况。
我正在使用:
Visual Studio 2022版本17.1.5
是一个错误,还是我缺少某些东西?
Considering this short version of my code written in Dot Net 6's new-console-template as per below:
using Microsoft.EntityFrameworkCore;
var opt = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite("ConnectionString...").Options;
using var dbCon = new MyDbContext(opt);
dbCon.Authors.Include(a => a.Books.Where(b => b.PublicationYear > 2021)).ToList().ForEach(author =>
{
// cw generates following model
global::System.Console.WriteLine();
});
// cw acting normal
Console.WriteLine();
new List<object>().ForEach(a =>
{
// cw acting normal
Console.WriteLine();
});
When using cw
CodeSnippet inside dbCon.Authors.Include...
block, Visual Studio generates global::System.Console.WriteLine();
but in the other scenario's as I mentioned in the above code, its normal.
I'm using:
Visual Studio 2022 Version 17.1.5
Is it a bug, or am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道为什么它到底是这样做的,但是我也遇到了同样的问题。我注意到的是,当我打开一个旧项目时出现了错误,该项目从另一个项目粘贴在新代码中,然后运行时甚至说“ Hello World”。
这使我相信Visual Studio以某种方式正在阅读最初生成的代码。我创建了一个新项目,粘贴了相同的代码,突然间,CW的工作原理。
我希望这会有所帮助。
I have no idea why exactly it does this, but I had the same problem. What I noticed is the error appeared when I opened an old project, pasted in new code from another project, and then when it's run it even says, "hello world".
This led me to believe that Visual Studio somehow was reading the originally generated code. I created a new project, pasted the same code, and suddenly the cw works as it was intended.
I hope this helps.
tl; wr-关闭并重新打开您的选项卡,然后它将作为新的(如果您的问题与我的问题相同)起作用,
我在怪异的Visual Studio崩溃后遇到了同样的问题,我决定将代码移至新位置。
事实证明,Visual Studio具有打开代码的旧选项卡,在这些旧选项卡中,像CW这样的摘要使我为我提供了全局:: System.Console.Writeline()代码,而正常的颜色编码停止了工作。
如果将鼠标悬停在某些旧选项卡上,它将实际上看到它,它将向您显示文件的路径。因此,当我简单地关闭选项卡/文件并从解决方案资源管理器重新打开相同的文件时,一切都很好:)
希望它可以帮助任何在开始编辑XML和解决方案的路径之前遇到这种愚蠢情况的人。他人。
tl;wr - Close and reopen your tabs, then it'll work as new (if your issue was the same as mine)
I had this same issue after a weird Visual Studio crash and I decided to move my code to a new location.
It turned out that Visual Studio had old tabs with code open, and it was within these old tabs that snippets like cw gave me the global::System.Console.WriteLine() code and the normal color coding stopped working.
You can actually see it if you hover your mouse over some of the old tabs, it'll show you the path of the file. So when I simply closed the tab/file and reopened that same file from the solution explorer, everything worked fine :)
Hope it helps any who runs into this silly situation before you start editing the XML and paths of your solution etc. like a certain someone else.