How to go to implementation of C# code in VSCode? [duplicate] - c#

This question already has an answer here:
Is there a way to see decompiled C# code in VS Code?
(1 answer)
Closed 5 months ago.
Prerequisites:
I use Visual Studio Code Version: 1.63.2 (Universal)
MacOS Monterey 12.03 with M1
.NET version 6.0.302
Originally I am coming from Python, but lately, I interact with C#(in particular ASP.NET Core 6) a lot.
I have been trying to find an answer to a question:
How can I go to the implementation of the method/class in a dependency package installed in my .NET project? Is it possible to do it in VSCode?
Probably, I am just struggling with how should I formulate this question, so let me provide some examples below.
If I am using PyCharm and, let's say, have an installed package flask-login. I can import the function login_user as on the screenshot below.
Then just go to its implementation and see the whole code as on the screenshot below.
This happens because both in PyCharm and in VSCode it redirects me to the files stored in the bin directory of my interpreter path. As a result, I can always go locally and check the source code of all installed dependencies.
Now coming back to C#: I want to have the same thing in my .NET project with VSCode (I don't use Visual Studio and use MacOS). As for now in VSCode, I can only go to the interface code of a dependency and when I press go to implementation it says Implementation not found.
I am not sure whether this is possible or not, since C# is a compiled language, so probably it would require a decompiler for this to work. The only thing I managed to make work was the possibility to jump into implementation during debugging session https://github.com/OmniSharp/omnisharp-vscode/wiki/Debugging-into-the-.NET-Framework-itself. At the same time, this is slightly different from what I want -> I just want a convenient way to go into the implementation source code to understand what is happening in the code LOCALLY and probably set breakpoints in this code if I think it makes sense.
Therefore, my main question stays the same: Can I do it on MacOS in VSCode?
UPD: I tried Rider from JetBrains(https://www.jetbrains.com/rider) and it works there. Still interested in making this work in VSCode.

An answer is basically here -> Is there a way to see decompiled C# code in VS Code?
There is a feature to enable decompilation in omnisharp extension for C# in VSCode.
Thanks to #UnholySheep!

Related

Setting up a mixed C# and C++ project in Visual Studio

I want to create a Windows application using a C# GUI that calls some C++ code but I have troubles setting up the project in Visual Studio.
I understood that I have to do it the following way : 3 projects (the C++ project, the C# project and a wrapper CLR project) that are linked to each others in some way. I just can't figure out how the link works.
If anyone can explain me in details what I have to do, I'd be really happy :3
Otherwise, I can use a Github link of a project already set up that I could copy.
Thanks in advance to anyone who will take some time to answer.

Importing winform solution to mono (linux) from VS Code (windows)

I tried to import a winform solution file from VS code (windows) to monodevelop (Linux) but it failed. The error is as follows:
Error while trying to load the project '/home/virtuall_kingg/Camera_GUI/Camera_GUI/Camera_GUI.csproj':
File not found: /home/virtuall_kingg/Camera_GUI/Camera_GUI/Camera_GUI.csproj
I added Camera_GUI.csprojfile also but still the error is same.
Can anybody guide me on how to import solution to mono?
This winform project has become pain in my neck.
Is building the GUI using gtk# in Ubuntu from scratch is the only way?
EDIT: Now you can substitute mono with .NET 5, the common .net framework for all platforms.
You are asking multiple questions here. In Linux you have (limited) support for WinForms through Mono. Depending on how complex is your project, you could port it without modification. If there are p/Invokes, then you won't for sure be able to port it.
Yep, in Linux the "other" big option is Gtk#, which has a long history. If you would want to port the project starting from scratch, it'd be a good option, but it'd involve porting your classes from working with WinForms to Gtk#, which is not impossible, but not trivial either. The feasibility of this would mainly depend on how good that project is architected. Do you have bussiness logic and views separated? If the answer is no, then the process will be tedious, and as hard as lengthy.
MonoDevelop is an IDE for C#, and Visual Studio for Mac is roughly MonoDevelop. It certainly works in Linux... as well as Visual Studio Code. So, there is no need to change anything in that front if you just need to port your code to Linux.
Okay, now, what's the road to follow? I think the best one is to try Mono with WinForms. It'd maybe involve simplify some code in the user interface part, but is certainly feasible. Just remember that you need to install Mono, and if your project is set to target .NET Core, then you need to create another project from scratch and set it to target .NET Framework.
Now, the specific question is that MonoDevelop complains about a missing Camera_GUI.csproj. This means that you've only picked a few files, but not the whole solution. Any IDE (Visual Studio, Visual Studio Code, Rider...), would complain about the same thing. Either remove the project from the solution, or add the project with all its files to the directory in which the solution sits.
So, the answer is: don't change anything if you don't need to retarget your project. Just move to a Linux box or virtual machine, with the whole project and open it in Visual Studio Code Rider, Rider, or MonoDevelop it does not matter. From within the IDE, remove those projects that make no sense in Linux (i.e., windows installer), and then recompile and start the program. Polish those parts of the user interface that need tweaking and that's it.
Should you need more help, please be more specific and provide more info.

How to extend functionality of .Net wrapper for scrcpy written in C?

Started looking at scrcpy (original in C), an Android screen mirroring utility through ADB - works fine on my system.
I have found a Visual Studio extension which I have successfully installed, appearing in the VS installed extensions list.
I have also downloaded and ran the source code in VS.
The issue is that when I run the solution, it opens up a new instance of VS and I'm not quite sure how to make use of this extension.
It's supposed to be a wrapper around scrcpy and I see the C# code that does the work. Ultimately I would like to begin extending its current features/functionalities with C# which is what I require assistance with please.
In terms of debugging a .vsix extension, I have ensured the following measures have been taken, i.e. the Debug configuration starts "devenv.exe /rootsuffix Exp".
If you're going to down-vote, please at least comment as to why. I have a valid issue here in trying to get this working.

How can I make an exe that can run on windows with no other installations [duplicate]

This question already has answers here:
Can c# compiled app run on machine where .net is not installed?
(5 answers)
Closed 6 years ago.
I have been looking into c# and c++ compilers and I read that they can be compiled into exe files, however the computer has to have the .NET framework installed for them to work. This is fine for me, the developer, because I have Visual Studio installed, but how can I get it to run on other computers without them having to install the .NET framework manually, the same way games and other programs that I download from the internet work for me? Sorry if this is a noobish type of question, but I'm just getting my feet wet with compiled languages and I don't have a lot of experience yet. Thanks.
EDIT: Hi sorry about any confusion. I'm looking for a way to make my application able to be downloaded or received from wherever I put it, and for the users to be able to use it without having to mess around with installing frameworks and such, especially since they may not be computer savvy users.
You have to link your code statically to the msvc runtime library. If you're writing the compile command yourself, you have to add /MT flag when you compile.
Every compiler is different with this. So depending on what compiler you use, you'll have a different answer.
You could download an installer creating program, such as Advanced Installer, Nullsoft Installer, InstallShield etc. and use those and include your prerequisites that way.
However Visual Studio does provide you with ClickOnce applications and it allows you to create an installer as an EXE. You can find more information on the MSDN site using these links:
How to: Include Prerequisites with a ClickOnce Application and
.NET Framework Deployment Guide for Developers
EDIT: Looking at the answers have I misinterpreted what you mean?
EDT: .NET Native with Windows 10
Of course you could actually achieve this in a standalone executable if it's running on Windows 10 using .NET Native (MSDN Article here).

Debugging C# application that is already built

I have an application I made that I lost the source code for, but the application has worked on my Win 2K computer. Now when moving to a Windows 7 computer it won't start. Probably some dependencies that needs to be solved, but I don't know which. The only error I got is a System.InvalidOperation without further description
Is there any tools(free) that I can use to get more specific information on what goes on
I am not sure how/if you can debug the application, but here is another idea.
There are tool out there called "reflectors", which allow you to look inside the .NET dll or executable.
They basically do the reverse of the compiler convert the dll/exe to source code (Now it won't be exactly the code you wrote, for example some local variables might have changed their names and some things might have been optimized, but the end result is the same, since this reflected code came from the same dll/exe.)
Now you can take the output of this and use it to rebuild and then debug your application.
Here are some ofthese tool:
dotPeek - free
.NET Reflector - not free
I know dotPeek doesn't allow you to debug inside of it, so you have to rebuild your application. The other one seems to be able to do that with its most expensive licence. Good luck!
You can also use Microsoft Debugging Tools for Windows (WinDbg). Here is an article that can help you.
http://www.dependencywalker.com/ will tell you dependencies and missing ones.
Also, you can attach visual studio, or get visual studio to launch a exe in debug mode without the source code.
my first try would be dependency walker just to make sure your not
missing some piece of native code
then I would look to just attempting to attach the program to visual
studio.
My next step would be to use something like reflector to get some
version of source code.
The pro version of regate's reflector let's you debug an existing dll without the sourcecode, costs $ 138 tho.
Ilspy will let you see the source for free, maybe you can figure it out from that.
Rgds Gert-JAn

Categories

Resources