How to keep only source files in project folder in Visual Studio - visual-studio-2010

When I create a new project in Visual Studio, after a session of working, the folder of the project is always filled with "junk" such as the ipch (precompiled header) folder, the debug folders, sql database files that I never made...
In short, is it possible to just keep the source files inside the folder of the project, and either
automatically delete every other junk files after closing VS, or
choose a different temporary folder for those junk to go in?

You can delete ipch, Release, Debug, x64 directories and also *.suo and *.sdf files. That will cause the compiler to re-create those files on the next run and maybe it needs some extra time to do so.
Plus, the *.suo files keep track of your open files, cursor positions in them, etc. You return to a clean slate in VS if you delete them, but you don't loose any source code.

You can use the post-build event and delete the files using standard dos commands, or you can run a powershell script for example in the post build event. As for when you close visual studio, I don't think you can do this, you would need some sort of event and a third party script or application.

Related

Does renaming a project in VS require me to change ALL occurrences of it's old name in the .sln file?

I searched already on stackoverflow and on the internet but I couldn't find a similar specific question.
When i have to rename a already checked-in (tfs) project in my visual studio (2010-2013) solution, I always use a procedure similar to this one here in the accepted question:
stackoverflow.com/questions/2043618/proper-way-to-rename-solution-and-directories-in-visual-studio
Here is the important snippet from there (thanks to author):
Close Visual Studio.
Create a backup of your .sln file (you can always roll back).
Imagine you want to rename directory "Project1" to "Project2".
If not using source control, rename the folder from "Project1" to "Project2" using Windows Explorer.
If using source control, rename the folder from "Project1" to "Project2" using the functions supplied by source control. This
preserves the history of the file. For example, with TortoiseSVN,
right click on the file, select TortoiseSVN .. Rename.
In the .sln file, edit all instances of "Project1" to be "Project2".
Restart Visual Studio, and everything will work as before, but with the project in a different directory.
..and there i always do step 6:
Step 6.: In the .sln file, edit all instances of "Project1" to be "Project2".
By observing the .sln file i could see that until step 6 (so in my case of using the tfs i did steps 1,2,3 and 5) there are still occurrences of the old project name in the .sln file:
Project("{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}") = "Project2",
"Project1\Project2.csproj", "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}"
and:
SccProjectUniqueName92 = Project1\Project2.csproj
SccProjectName92 = Project1
SccLocalPath92 = Project1
Until now i had no problems with that approach. But as i could see a colleague of me is skipping step 6 and there are still occurrences of the old project name in the .sln file.
Now i wonder if step 6 is really needed/required?
I am keeping using step 6 just for more cleanness! But whats your opinion on this?
Could the old project name occurrences in the .sln file (if skipping step 6) even some time lead to functional problems with tfs/vs etc.?
Or is it only for the purpose of a cleaner/clearer code better to do carry out step 6?
If you are renaming a project within a solution, that is under source control, really all you need to do is to rename the project in Visual Studio and then submit the changes to the project file and the solution file, back into source control.
Visual Studio and TFS should handle all of the changes for you, VS will rename the project and update the references in the SLN file.
TFS will handle the rename and will maintain the history line.
The only time it should get complicated is if you are moving projects and solutions within source control, when you are carrying out this sort of task then the list above is a fair description of what needs to be done, but after step 4 i would just open the solution remove the project that can no longer be found and add in the newly renamed project, this would then automatically handle the sln file changes. now obviously this would orphan your history on the project if it was under source control, but you would make the project name change through TFS before reopening the solution.
if you want to manually change the sln file then a find and replace operation is the simplest way to update the file.
Coming Back to your question.
You really should ensure the sln file is correct as this tells VS where to download the files from and what projects actually make up the solution, by not updating the sln file correctly you, or other users of TFS may not get the correct files downloaded and you may have issues opening your solution.
An example of fall out from not having these files in line can be found in this question Why missing <SccProjectName> in project file cause "The project file is not bound to source control"

Excluding files in Visual Studio project

I've search everywhere for this, but have yet to find the answer.
I have a VS2012 project with thousands of files and folders I wish to exclude from the project as I don't need them to build any longer. Clicking on the folder and choosing Exclude From Project works, but takes literally forever - at times it appears Visual Studio has stopped running and I have to kill the process.
Question: What is Visual Studio actually doing to exclude a file from a project? Is there a way to simply go into the project file and exclude the files by folder? My project file does not appear to store this information. Where are excluded files defined for the project?
You can open the project file (in s text editor, i.e. Notepad) and remove the lines with the files that you want to exclude.
You can also do that in visual studio but you first need to unload the project (right-click on the project, unload)
Delete the folder in VS which has project to unload then restore it from recycle bin.
It works for me.

Clearcase does not checkout project files when files are moved by resharper

My current project is under source control by clearcase. I am also using Resharper 8.1 with Visual Studio 2012. I am also using a VS integration for ClearCase.
When adding files manually to a project (by right clicking on the Project -> Add-> Class), ClearCase checks out the project file, so that saving all files works like a charm.
"Unfortunatelly", I tend to use a lot of the ReSharper functionallity. When using ReSharpers Move To command, it seems that ClearCase prevents ReSharper (or Visual Studio) to check out the project files. They are modified, but cannot be saved - I always get that Save As dialogue when saving all documents. To get this working, i need to manually check out the *.proj file and then save the modified files. Is there a way to automatically check out those files?
Another problem is when using ReSharpers Rename: I just tried to use Rename on an interface that is used in approx. 60 other files. Everythink worked, except that the files were not checked out by clearcase! In order to save, I needed to Save all, click cancel for the first file (ClearCase then recognizes that the file has been modified and checks it out) and then save again. This is really annoying and prevents from a produtive workflow..

Visual Studio Makefile Project makes extraneous 'obj' folder

I'm using a Makefile project in Visual Studio 2012 express just fine. However, regardless of the Build Command specified, Visual Studio always makes an 'obj' folder containing empty subfolders obj\Win32\Debug and obj\Win32\Release.
To reproduce the problem, simply create a "Visual C++ - General - Makefile Project" and use a DOS command like 'dir' in the Build Command Line. As soon as you build, the empty obj\Win32\Debug folder will show up.
I can simply skip these in my Mercurial ignore file but it'd be nice to find a fix. Anyone know how to make Visual Studio not generate these empty folders?
Found a trick: to set the intermediate output directory on an existing directory. I modified the project file by hand and added this:
<IntermediateOutputPath>$(ProjectDir)</IntermediateOutputPath>
inside the configuration PropertyGroup. I used the project directory, which obviously already exists. No more useless obj directory!
The obj folder represents VS' own metadata about your project for intellisense support and designer support (for WF/WPF apps). For the most part you can ignore the folder completely without issue.
On occasion though this data can become corrupt and cause VS to show invalid Intellisense options and the workflow/WPF designer can cause errors. Closing VS and deleting the obj folder will quickly resolve this though.

PDB files in Visual Studio bin\debug folders

I have a Visual Studio (2008) solution consisting of several projects, not all in the same namespace. When I build the solution, all the DLL files used by the top level project, TopProject, are copied into the TopProject\bin\debug folder. However, the corresponding .pdb files are only copied for some of the other projects. This is a pain, for example when using NDepend.
How does Visual Studio decide which .pdb files to copy into higher level bin\debug folders? How can I get Visual Studio to copy the others too?
References are as follows: all the DLL files are copied to a central location, without their PDB files. TopProject only has references to these copied DLL files; the DLL files themselves, however, evidently know where their PDB files are, and (most of them) get copied to the debug folder correctly.
From MSDN:
A program database (PDB) file holds
debugging and project state
information that allows incremental
linking of a Debug configuration of
your program. A PDB file is created
when you compile a C/C++ program with
/ZI or /Zi or a Visual
Basic/C#/JScript .NET program with
/debug.
So it looks like the "issue" here (for lack of a better word) is that some of your DLLs are being built in debug mode (and hence emitting PDB files), and some are being built in release mode (hence not emitting PDB files). If that's the case, it should be easy to fix -- go into each project and update its build settings. This would be the default scenario, if you haven't done any tweaking of command line options.
However, it will get trickier if that isn't the case. Maybe you're all in release or debug mode. Now you need to look at the command line compile options (specified in the project properties) for each project. Update them to /debug accordingly if you want the debugger, or remove it if you don't.
Edit in Response to Edit
Yes, the DLL files "know" that they have PDB files, and have paths to them, but that doesn't mean too much. Copying just DLL files to a given directory, as others have mentioned, won't clear this issue up. You need the PDB files as well.
Copying individual files in Windows, with the exception of certain "bundle"-type files (I don't know Microsoft's term for this, but "complete HTML packages" are the concept) doesn't copy associated files. DLL files aren't assembled in the "bundle" way, so copying them leaves their PDB file behind.
I'd say the only answer you're going to have is to update your process for getting the DLL files to those central locations, and include the PDB files ... I'd love to be proven wrong on that, though!
First off, never assume anything. Clean the solution, rebuild it in debug mode, and check to see if all PDB files are created. If not, that's your problem.
If they are created, and they're not all getting copied, you can get around this by creating a post build event that manually copies the PDB files to the desired locations. This is just a workaround, of course.
The only other thing I can think of is that your solution file has become corrupt. You can open your .sln as an XML file and examine the contents. Check the configuration for the projects that are acting as expected and compare them to those that aren't. If you don't see anything, you have to repeat this at the project level. Compare working .csproj (or whatever) project files and the non-working ones.
Edit in response to edit:
If you're just manually copying stuff around, then manually copy the PDF files as well. DLL files shouldn't "know" anything about PDB files, I believe. Just stick them in the destination directory and go have a cup of coffee. Relax.
Check when you clean the solution, that it is actually cleaned.
I've seen Visual Studio leave files hanging around in bin\debug directories even after cleaning. Delete the bin\debug directory on all of your projects and rebuild.
As other posts have said, you may have a compiler/corruption issue.
But, as Will said, if the PDB files are being created, but not showing up where you want them, create a post-build step. Here is the post-build step I define for every project in my solution. It makes sure all output files are copied into a common directory.
If your project file is in \SolutionDir\ProjDir, then the first line of the post-build step will copy the output files to \Solution\Bin\Release or \Solution\Bin\Debug. The second line copies the PDB file if this is a debug build. I don't copy the PDB file for release builds.
So, \SolutionDir\Bin now contains all your output files in one location.
xcopy /r /y $(TargetPath) $(ProjectDir)..\$(OutDir)
if $(ConfigurationName) == Debug xcopy /r /y $(TargetDir)$(TargetName).pdb $(ProjectDir)..\$(OutDir)

Resources