Like Html, CSS,JAvaScript or React folder can be open on Visual Studio Code by run command ( code . ).Similarly how can we open our C# program folder in visual studio by cmd command
I'll trying by code . but can't be open Visual studio.
You could use the Windows start command:
start MySolution.sln
This will open the program registered for *.sln files which normally is Visual Studio.
Step 1: Go to Control Panel -> System and Security -> System. Under Advanced System Setting option click on Environment Variables as shown below:
Step 2: Now, we have to alter the “Path” variable under System variables so that it also contains the path to the .NET Framework environment. Select the “Path” variable and click on the Edit button as shown below:
Step 3: We will see a list of different paths, click on the New button and then add the path where .NET Framework is installed.( If not installed, you need to install it yourself)
Step 4: Click on OK, Save the settings and it is done !! Now to check whether the environment setup is done correctly, open command prompt and type csc.
Step 5: Open the text editor like Notepad or Notepad++, and write the code that you want to execute. Now save the file with .cs extension.
Step 6: Compile your C# source code with the use of command:
csc File_name.cs
If your program has no error then it will create a filename.exe file in the same directory where you have saved your program. Suppose you saved the above program as Hello.cs. So you will write csc Hello.cs on cmd. This will create a Hello.exe file.
Step 7: Now there are two ways to execute the Hello.exe. First, you have to simply type the filename i.e Hello on the cmd and it will give the output. Second, you can go to the directory where you saved your program and there you find filename.exe. You have to simply double-click that file and it will give the output.
Using Command:
Using .exe file:
Related
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
I've found that if I open the same C# file in Visual Studio 2019 v16.9.3 in different ways, I can get the red squigglies in the text editor or not.
I am following a tutorial (PluralSight, C# Fundamentals) and I have created a directory that is structured as follows:
gradebook/
src/
GradeBook/
GradeBook.csproj
Program.cs
test/
The tutorial instructs me to open the folder using the "Open a local folder" option at the Visual Studio home screen. However, when I do this, there are no red squigglies for errors in my code. However, if I open the project by Ctrl+Shift+O and selecting the "GradeBook.csproj" file listed above, everything seems right with the world.
To clarify, I have included a few screenshots below:
File opened with: Open a local folder
File opened with: Open a project/solution
In case of image problems, the 2 images show a picture of the same Program.cs file opened via the two methods mentioned above. The code in the file is as follows:
using System;
namespace Gradebook
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
int x = "L";
x.grade();
}
}
}
The first picture (file opened via "Open a local folder") shows no red squigglies under the two syntactically incorrect lines, while the second picture (opened via Ctrl+Shift+O) shows red squigglies.
Does anybody know how I might go about having the entire parent folder opened in the Solution Explorer while also being able to see the red squigglies?
As a final note: I have also noticed that, when the file is opened via the local folder, typing opening/closing braces ("{") doesn't autocomplete as it does when opening the file via the project/solution.
This happens because when you open as a local folder you're only browsing the files, Visual Studio is not actually loading your project. When you open the .csproj file Visual Studio knows you're opening a project and loads everything correctly. It's weird that the tutorial you're following didn't provide a proper solution file with the project and extra files inside.
To open as you want, the parent folder, you need to create an empty solution project somewhere, then paste the files in the folder, on Solution Explorer (inside VS) you click to Show All Files (otherwise your pasted files won't show) then add these files to your solution (ricght click, add). Then add add the csproj as an existing project (right click on solution, add existing project, VS will let you select it once you try to add it).
Or use VSCode as you did, VSCode is different indeed from Visual Studio :)
Is there any way to make a hyperlink from a website which would open visual studio and find a file / find a class in a project or so?
We have some code review protocols where there are names of the classes to review and it would be nice if you could just click on the link and it would lead straight into the visual studio instance.
You have to write a program that installs a URI protocol like vs://C:/Projects/myproject.sln&class=Class%20A that would open the Solution myproject.sln as described in http://msdn.microsoft.com/en-us/library/aa767914(VS.85).aspx!
With this sheme you have to register to open another manual written program (clicked on a vs://-link) to start the devenv process with some parameters. Take a look at this to get some more information about "Opening a file in a project from the CMD".
Conclusion: There is no way to do this without installing a program and a macro in Visual Studio.
You can check devenv.exe start up switches(parameters) here:
http://msdn.microsoft.com/en-us/library/xee0c8y7(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/19sf6kk3(v=vs.90).aspx
Also you can use ActiveX to run CMD commands to invoke the devenv:
How to Run cmd.exe with parameters from javascript
I hope this helps :)
anybody knows how to run unit test dlls built using mstest from the command line, without running VS
considering that on the machine there is .net 4.0 and VS2010 installed
I haven't done it myself, but I'd imagine that using the mstest command line is the way forward... if you've already tried that and had problems, please give more details.
mstest /testcontainer:path\to\tests.dll
EDIT: As noted in comments, you should either do this after putting the right directories on the path, or include the full path to mstest.exe.
Quick Answer :
Examples
You must use the /testcontainer option together with the /category option to select which tests in which categories to run. The following command, for example, is run in the solution folder and runs the tests that are in both the Priority 1 and ShoppingCart categories.:
MSTest /testcontainer: testproject2\bin\debug\testproject2.dll /category:"Priority1&ShoppingCart"
Note
Because the test assembly file resides in a different folder, a relative path is necessary,
If you are using test lists, it is best to use the /testmetadata option together with the /testlist option. The following command, for example, is run in the solution folder. Because the test metadata file also resides in that folder, no path is necessary:
MSTest /testmetadata:Bank.vsmdi /testlist:balancetests
Detailed :
To run tests from the command line
1.
Open a Visual Studio command prompt.
To do this, click Start, point to All Programs, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, and then click Visual Studio Command Prompt (2010).
By default, the Visual Studio command prompt opens to the following folder:
:\Program Files\Microsoft Visual Studio 10.0\VC
Note
To change the folder to which the command prompt window opens by default, click Start, point to Microsoft Visual Studio 2010, point to Visual Studio Tools, right-click Visual Studio Command Prompt (2010), and then click Properties. In the Visual Studio Command Prompt (2010) Properties dialog box, you can change the path to the default folder in the Start in box.
2.
Either change directory to your solution folder or, when you run the MSTest.exe program in step 3, specify a full or relative path to the metadata file or to the test container.
To identify your solution folder, first identify the Visual Studio Projects folder. To do this, click Options on the Tools menu in Visual Studio, and then click Projects and Solutions. Under Visual Studio projects location, you see a path such as the following:
:\Documents and Settings\\My Documents\Visual Studio\Projects
Your solution folder is typically a child of this Projects folder, such as the Bank folder in the following example:
:\Documents and Settings\\My Documents\Visual Studio\Projects\Bank
3.
Run the MSTest.exe program.
When you run MSTest.exe, you must specify either a test metadata file or a test container, using either the /testmetadata option or the /testcontainer option, respectively. You use the /testmetadata option only once, to indicate one test metadata file. You can use the /testcontainer option multiple times, to indicate multiple test containers.
If necessary, include the path to the folder in which the metadata file or test container resides. Test metadata files reside in the solution folder.
Depending on the test type, test containers are XML files, assemblies built from test projects, or other files that reside in the folders of a test project.
Source: http://msdn.microsoft.com/en-us/library/ms182487(v=vs.100).aspx
Try this
mstest.exe /testcontainer:c:\projects\MyTests\Sampe.Tests.dll
I have developed a wpf application and created setup for that. I am using windows installer for creating setup package. Now I want to include uninstall MyProgram.exe in start menu after installing my package.
I am able to add the exe to run my program after installation. I want to include uninstall MyProgram.exe, ReadMe file, Help File in start menu.
Any suggestions plz help me regarding this.
Thanks in advance,
Ibrahim.
did you have a look at this post?
How to add uninstall option in .NET Setup Project?
You can create an uninstall shortcut and then add this shortcut to your start menu. the post below explains how to add a shortcut to user's desktop, you can get the idea and apply the same things for the start menu.
desktop shortcut icon not showing in web setup project
When you create installation package, it is assigned unique id (Product Code, if i'm not forgetting). You can create a batch file with following line:
#echo off
start /b /l msiexec.exe /x {Product Code}
Now right click on file system tree (in files view of project) and include this batch file. Assign it a nice icon and create entry "Uninstall " to start menu folder for your application.
ps:- just type msiexec.exe in run or cmd window to get more options.
pps:- Product Code is available in properties of your setup project. Select Setup Project in solution tree and open properties tab.