VS Code - Error check missing in some projects - visual-studio-code

I made a new solution in .NET with a class library (dotnet new classlib) and an XUnit test project (dotnet new xunit). I then added a reference to the class library, from the test project (dotnet add <test-project> reference <class-library>).
Now I have live error checking (syntax highlighting) in the class library, but no in the test project. You can see an example below, where the class Foo doesn't exist anywhere, but doesn't generate a live warning in the unit test project (it still fails on build).
This is a VS Code issue only. If I open it in Visual Studio 2022, it works just fine.
What's going on here?

Thanks to this answer on Twitter I found a way to fix it...
I had to restart OmniSharp (the C# extension for VS Code). It can be done in the command palette (Ctrl+Shift+P). Search for "OmniSharp" and select "OmniSharp: Restart OmniSharp".

Related

Visual Studio Code does not see changes in F# Solution

Currently I am trying to use Visual Studio Code with Ionide to build a F# Solution. To describe my problem, i first describe what i have done, and what works.
I created a solution with two Projects. One Project is a Queue that contains a F# library. Another project is Queue.Test that is a console application that uses the Queue library, and should contain the Tests for the Queue library.
I'm using .Net6 and created the solution and Project with the dotnet cli tool.
In general, i can build the project with dotnet and i also can use everything in Visual Studio Code. I load the Folder that contains both projects, and Visual Studio Code loads the library.
I am able to edit the Library and my Console application. In my Console application i also can access the Queue and so on. Autocompletion works, and so on.
But, there is one problem. When i add a new function to my library, let's say Queue.help then in my Console application, i cannot see that function. It doesn't show in autocomplete, and when I write code that uses that function i get a compiler error telling me that function doesn't exists.
I can Build/Rebuild from VS Code or from CLI but the problem goes not away.
The only way Ionide starts to see the new function is by building the library AND restarting VS Code. As long i don't restart, it seems to not update the generated dll (i guess).
This is sure annoying, as i don't want to reload/restart VSCode everytime I add a new function to my library.
So my question: How i can I fix this?
What i want is to be able to change my library, and at the same time write tests in the other project and get full Code autocompletion.
Does somebody else have the same problem, or should I change my workflow?
What can i do, to debug this problem on my own?
Some tips?
This issue is fixed by the recent version of Ionide 5.10.1

VS 2019: running an extensibility project (VSX) always compiles an unknown external project

Basically this:
I created a fresh project in Visual Studio 2019 using the VSX c# template.
I moved a bunch of files from an older VSX project (for VS 17).
I compiled and ran the project - errors started emerging.
I addressed one error, ran the project - got another error.
I started addressing the second error and in the process of fixing it I noticed that now VS is for some reason compiling an unknown external project whenever I run my project. I realized it because once the program hit the error and instead of jumping into my code and showing me the line, it showed me this message: "The source file is different from when the module was built. Would you like the debugger to use it anyway?" Also whenever I changed something in my code files now - the changes never apply. Moreover, the first error (which I have already fixed) resurfaced again, and when the debugger tried showing me the place of the error - it clearly used the new file, thinking that it's an old one (even if I change the new file to have empty space in the line where the error was, the debugger will still stand on that empty line, talking about the error).
Now whenever I create a new VSX project, even an empty one, and compile/run it - the studio runs that unidentified external project (I have absolutely no clue where that project is, even the files that the debugger uses have no influence on that project.
UPDATE: I deleted Visual Studio cache folders (C:\Users\xxx\AppData\Local\Microsoft\VisualStudio\16.0_xxxx) as well as reset the experimental Visual studio with the start menu prompt "Reset Visual Studio 2019 Experimental Instance". Now, when I compile my VSX projects, a clean and empty Visual Studio instance is launched - my extension code is ignored.

How to use ITestEventListener in Nunit 3 in Visual Studio 2017

The steps I have taken:
I have created a separate project for the ITestEventListener
Installed Nunit.Engine.Api v3.9.0 for the new project
The class A that implements ITestEventListener has the [ExtensionAttribute]
The project that contains class A at root also has .addins file which contains *dll line (to reference all dlls in its directory)
The test project contains a reference to the project that has class A that implements ITestEventListener.
When I try to run a test, nothing happens. Solution Explorer keeps loading indefinitely.
I have not been able to find any step by step instructions for configuring this.
I had followed the official nunit docs
as well as this question without success.
I am trying to run my tests with Visual Studio 2017 no the console runner
Any suggestions or pointers? What am I missing?
I don't believe the NUnit 3 Adapter currently loads Extensions. They should work with the Console Runner however.
See the open issue here: https://github.com/nunit/nunit3-vs-adapter/issues/222

Existing project full of errors in Visual Studio Code

I've received a simple VS Code console project and I intended to open it in my VS Code.
When I opened the Program.cs file, a notification appeared that I needed to restore the packages.
After it is done, every line is full of errors - yet the project compiles and runs.
Is this a bug?
UPDATE:
As of version 1.31.1, it is still an issue.
The contradiction between all the errors and the successful build…
It still looks like a garage project, even after 1-2 years of development...

Project referencing Portable Class Library gives error in Visual Studio Code

I create a console application in Visual Studio 2015 RC and add Automapper 3.3.1 using nuget to the project.
If I then add the following snippet to my project:
public class Class1
{
public void Test()
{
AutoMapper.Mapper.Map<B>(new A());
}
}
And then open the same project in Visual Studio Code preview on Windows 10 then I get a red squiggly on the Map function.
The error message says:
The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.
My project is configured to use .NET 4.52 and there are absolutely no errors or warnings when building the same project using visual studio 2015 RC or using MSBuild from the command line.
Automapper is portable class library and this is what seems to trigger the problem.
Is this a known issue with Visual Studio Code or Omnisharp?
Are there any way to suppress these error messages?
Update:
I have now tested with VS Code version 0.3 and it is still not fixed.
To make it even simpler to reproduce I have also verified that the problem also exist for a ClassLibrary project containing only the 3 classes: Class1 as shown and class A and class B, which are just two dummy classes used to have something to map.
It does not matter which version of Visual Studio is used to create the project. The same problem exist if I create the class library project using VS 2013.
Maybe you added the reference in both dnx451 and dnxcore50 in project.json file.
I think the problem is Automapper did not support .NET Core 5.0, please refer this article for more detail about .NET core 5.0 and .NET framework 4.6.
http://blogs.msdn.com/b/cesardelatorre/archive/2014/11/18/what-is-net-core-5-and-asp-net-5-within-net-2015-preview.aspx.
This might be the limitation of multi-environment in .NET Core 5.0 when using available libraries. You should write by yourself or waiting for other libraries update if you want to use, otherwise, please remove dnxcore50 in project.json.
Happy coding!
This is actually a known issue with the OmniSharp-roslyn server which powers VS Code, see: https://github.com/OmniSharp/omnisharp-roslyn/issues/265
I suspect you might have better luck using the yeoman ASP.NET 5 generator to generate an ASP.NET 5 Console application.
See: http://docs.asp.net/en/latest/client-side/yeoman.html
And http://docs.asp.net/en/latest/dnx/console.html