Run button missing for c# in VSCODE - c#

When I am using python in Visual Studio Code, I have the run button at the top right, however, when I am in a c# file, the run button is not there.
Why is that, and how can I fix it?

Since VS Code is a tool built with C# in mind, having the Run hidden is not a disadvantage but rather to dedicate a complete UI for Running and Debugging your C# code. The Run and Debug UI which you can access from the left menu gives your this capability with comprehensive tools to help you debug.
Activating this tool to run correctly involves two setups, one-time setup and a per-project setup (Don't let this intimidate you, it is just a click of a button)
First Time Setup
1. Install .NET command line tools
Install the .NET Core command line tools (CLI) by following the installation part of the instructions here: https://dotnet.microsoft.com/download
2. Install C# Extension for VS Code
In the extensions tab, enter C# in the search box and press Enter. Select the extension from Microsoft and click on Install. If you have previously installed the C# extension, make sure that you have a recent version.
3. Wait for download of platform-specific files
The first time that C# code is opened in VS Code, the extension will download the platform-specific files needed for debugging and editing. Debugging and editor features will not work until these steps finish.
Once Per Project
1. Get a project
You can start from scratch by creating an empty console project with dotnet new. Begin by opening the terminal in Visual Studio Code (View->Integrated Terminal) or CTRL+` and type these commands:
cd ~
mkdir MyApplication
cd MyApplication
dotnet new console
2. Open the directory in VS Code
Go to File->Open Folder (File->Open on macOS) and open the directory in Visual Studio Code. If this is the first time that the C# extension has been activated, it will now download additional platform-specific dependencies.
3. Add VS Code configuration files to the workspace
VS Code needs to be configured so it understands how to build your project and debug it. For this there are two files which need to be added -- .vscode/tasks.json and .vscode/launch.json.
Tasks.json is used to configure what command line command is executed to build your project, and launch.json configures the type of debugger you want to use, and what program should be run under that debugger.
Launch.json configures VS Code to run the build task from tasks.json so that your program is automatically up-to-date each time you go to debug it.
If you open the folder containing your project, the C# extension can automatically generate these files for you if you have a basic project. When you open a project and the C# extension is installed, you should see the following prompt in VS Code:
Clicking Yes when you see this prompt is all that you really have to do when you open a new dotnet project. If the files are there already you won't be prompted.
Clicking Yes on this prompt should add these resources. Should you need to add those resources manually please check the reference link below.
4. Start debugging
Your project is now all set. Set a breakpoint or two where you want to stop, click the debugger play button (or press F5) and you are off.
Reference Link: https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md

try pressing f5, should do the same thing as the run button

Related

Avoid getting "File Modification Detected" message Programmatically

Hi I am developing an visual studio extension where once the solution is open and I try to add a new project using a command after creating that project this msg pops up saying modified outside the environment. Does anyone have solution for disabling it.
I know what you are talking about, I can reproduce.
Based on the default settings of VS Tool, if you use such commands in root directory of the solution file outside VS:
dotnet new console -n ProjectName -f net7.0
dotnet sln SolutionFileName.sln add ProjectName/ProjectName.csproj
And then, if you click in the entire window of Visual Studio, this windows will pop out:
For your situation, currently doesn't have such feature to control 'File Modification Detected' Window when projects be linked to solution file outside.
Your requirement make sense, I suggest you to rise a feature request ticket in Microsoft Official feedback place:
Request a feature
you can share your ideas and your requirements there.
By the way, there is a public extension project in GitHub, which can kill the 'File Modification Detected' window and auto load the solution:
FDMKiller
This extension is based on VS2017, it may not be suitable for your VS version and may not be able to use directly in your VS version, but you can get some inspiration from the source code if you are interest in this.

How to embed the version information in the executable file name when building C# application in Visual Studio?

This question is a complement for the post How to change the output name of an executable built by Visual Studio.
After reading this post I did the following:
Firstly, I followed the answer for this post and I could define the executable file name successfully.
Now, I would like to know if instead of only define the name as "Demo.exe" as mentioned in the example post above, it would be possible to embed the version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute in the built file, resulting in something like "Demo_v1.0.0.0.exe"?
I'm developing my application in C# WinForms, using Visual Studio Express 2017.
Why would you want to change the name of the executable? Whenever you try building a Setup for your application, you need to change the Setup to include the new file. And when you install an update, your Setup needs to know all versions of your executable in order to delete the old version. That's just not what you want to do.
If you want to keep all versions of the software for yourself, come up with a different solution, e.g. moving the executable into a folder which has the version number.
That said, I have done this for Setups, so customers can download different versions of the Setup. I did that using a commercial tool called Visual Build, but there are other build automation tools available. So, my answer is: set up a continuous integration / continuous delivery pipeline (CI/CD) and automate the step there, not in Visual Studio.
From the project properties, you can add Post build event command line to rename your exe
pseudo
Maybe you can create another console renamer.exe which reads version defined in AssemblyInformationalVersionAttribute or in AssemblyVersionAttribute of your app and renames it and then call that renamer.exe from Post build event command line
write a powershell script to rename the newly built exe and call that script from Post build event command line

How to debug run a project as a different user in Visual Studio?

I need to debug run a C# project using a different user. I found this link, However, it's old.
How do you debug a project as a different user in Visual Studio 2022?
The Launch Profiles doesn't have the executable field.
If you mean how to using the approach for a .net core project, here is the steps:
Click the downward arrow in the picture and choose "<project> Debug Properties".
In the dialog click the first button and choose "Executable".
Input the executable and arguments.
Select the new profile (in the first picture) and start debugging.
Note that with this approach you still need attach to the process, see the comments in this answer: https://stackoverflow.com/a/1287221/6196568

c# script compilation vscode

I tried running simple code in my vscode. initially got of "scripts not found internally or externally" after installing the scripts from "choclately" and installing "sriptcsRunner" extension.
I'm again facing a problem running my code.
For VisualStudio Code all you really need to run is the C# extension.
To create a new project you open the integrated terminal in VS Code inside your workspace and run
dotnet new console
That will create everything you need.
You might need to run .NET Generate Assets for Build and Debug, you can do so by pressing ctrl + shift + P and enter the above command there, it should pretty much autocomplete.
to debug your program you can run by pressing F5
To execute normally use this:
dotnet run

How to debug .NET console application from Visual Studio 2013

I've created a .NET 4.5 console application (an .exe file) with c# that processes some data in various files. The whole thing runs in less than one second. I have a problem with a testing version of the .exe that I'd like to step through in the Visual Studio 2013 debugger using particular input files (the filenames are passed as command line arguments). I can't do an "Attach to process..." since the process has completed too quickly to attach to it. How do I debug in this case.
Note that I'm from the python world, and the python equivalent of what I'm trying to do is python -m pdb pdb_script.py.
Thanks for any advice!
Right click on your project and go to "properties".
Then select the "debugging" tab on the left-hand side.
There's a box where you can input the desired command line arguments for use when running in debug mode.
EDIT: If you're asking how to start the debugger, then add some breakpoints to your code, then right click on the project in your solution and pick Debug > Start New Instance.
Alternatively you can right click and choose "Set as Startup Project", after which you can start debugging with F5 or the "Start" button at the top of the UI.
Add the following line in your code:
System.Diagnostics.Debugger.Break();
This will allow you to debug your application before it ends.
In Visual Studio, you can add commandline arguments before starting a debugging session by right-clicking your project, selecting properties and then going down to the debug tab.
Then you can start it in Visual Studio with f5
If that's too much trouble (because you are going to change the arguments a lot), you could do something like adding a Console.ReadLine to your program at the beginning that will give you a change to attach a debugger. You could even have an extra command line argument for debugging that will only pause for you to attach the debugger if you pass that argument.

Categories