Reputation: 3343
I just want to know if we can compile a single file/class in Visual Studio. I often change just a single file but end up compiling the entire project. This might be a trivial case but will be very helpful:) I am using visual studio 2005 working on a C# project in .net 2.0.
Upvotes: 47
Views: 76968
Reputation: 2585
When using Visual Studio, it's possible to compile and run individual C# class files without the need for extensive configuration. Here's the process I typically follow:
Open the Desired CS File: Ensure the file is opened in Visual Studio.
Set Up a New Startup Configuration:
On the left side of the interface, near the second green run button, click on Startup Project
(highlighted in the provided image).
Select the Current Selection
Option: Apply this selection.
That's it! You're now ready to run your single C# file.
Upvotes: 0
Reputation: 145
Compile a project — ignoring all irrelevant files. (See also https://stackoverflow.com/a/18940150/2422360 for an answer I wrote that has a fuller look at this.)
Upvotes: 0
Reputation: 49
Okay, I think I know what you are looking for. I think there's a better way to word this, but what you need to do, is to open the Visual Studio Command Prompt Found in the Start Menu. Within it you can use the "cl" command to compile C/C++. Usage: cl [ option... ] filename... [ /link linkoption... ]
As in:
cl /O2 test.c
Upvotes: 4
Reputation: 14589
The granularity of compilation is the DLL, so there is no way to do what you are asking.
Or do you mean that you compile the whole solution for a singe change (or at least VS checks if all projects require building) ? There is an option under 'project and solution' / 'Build and run', 'only build startup projects and dependencies on Run' that helps.
Edited: Ctrl-f7 for 'build file' is for C++ projects.
Upvotes: 4
Reputation: 3986
Ctrl+F7 will compile only the active source file.
Look for the Compile item at the bottom of the Build menu.
Of course, you'll still have to do a build before you can test, but if you just want a quick sanity check after modifying a source file, this can be handy.
Upvotes: 57