How can I make Visual Studio update namespaces when I move classes? - visual-studio

I remember that when I worked with Java tools, I could easily reorganise classes and packages by dragging and dropping them in the IDE. This would automatically update namespaces to match the new file system structure.
In the .NET world, I believe the .NET languages' specifications don't require namespaces to match folder structure. However, I would still like to be able to move class files, or even namespaces, around, and have Visual Studio automatically update the namespaces correspondingly.
How can I achieve this? I'm more interested in a Visual Studio 2010 solution, but I still consider answers for other versions acceptable.

Related

Convert Visual Studio exe-project in lib-project

I am developing an application (exe) in c++ with visual studio. I am not that experienced. Now, I came to the conclusion that it might be better to compile the general program functionality into an lib or dll file, which I then would use in a different visual studio project, where I basically implement the functions from the lib files for the more specific purpose of my project. With my current setup, I get the impression that I am starting to mix the gerenal functionality with the specific problem statement.
Basically I am asking for a way to convert my current full visual studio project into two separate projects, one for the gerenal lib files representing the classes and program modules, and one for the specific problem implementation. Is it possible to also keep everything in one visual studio project (edit: solution) for convenience?

How can I Enumerate Projects/Files in a Visual Studio Solution Extension?

I would like to obtain a collection of all .cs files in a solution for analysis from a Visual Studio Extension. There are a couple methods of doing this on SO, but these are outdated and clunky. Specifically, they utilize old COM compatibility libraries, and require casting and inspecting GUIDs stored as strings.
How do I list all the projects in the current solution using EnvDTE?
Enumerate all files in current visual studio project
Visual Studio Extension get all classes and interfaces metadata
Any method which also gives access to some parse tree would be especially useful (in my case).

Nesting Projects

I see that MS has documentation on how to implement nesting projects when implementing new project types. While this looks do-able, I'd rather not write and maintain my own VS extension if I can avoid doing so. Is there any "generic" project type already implemented by some extension that will allow project nesting? The idea would be that the parent project does nothing but include its children and allow building, adding references, etc.
Managed Package Framework for Projects is for Visual Studio 2013 and includes "a project system that supports nesting" (see the NestedProject sample). I have not tried it myself, though I did look through it a while back (the VS 2010 version) and it has thorough documentation.
It may or may not be as extensive as what you are looking for. From the overview in the documentation:
Creating a new project type in Visual Studio is complex task. Using MPF_Proj is a good starting point for creating custom project types in Visual Studio written in managed code but there are limitations that would have to be considered before using the framework.
MPF_Proj is not a .NET library. It is rather a framework of source files (classes, utilities etc.) that can be included in a VSPackage project.

visual studio 2010 control library references

I wrote a control library using visual studio 2010, I'll call it MyLibrary. MyLibrary references another control library I have that we'll call AnotherLibrary. I also have a clean virtual machine (CVM) and I've added AnotherLibrary to the GAC on the CVM. Using the CVM, I create a new WinForms project, add MyLibrary.dll to the toolbox, and drop one of the controls onto the form. Visual Studio will add MyLibrary.dll AND AnotherLibrary.dll to the references, even though AnotherLibrary.dll is in the GAC (and isn't needed). I can remove AnotherLibrary.dll from the references and everything is fine.
Is there a way to prevent visual studio from adding AnotherLibrary.dll in this scenario?
Edit: I've given this some thought and I have an example. When you add a TabControl to a parent control in the designer, visual studio won't add System.Design to the references, even though the TabControl depends on it. So, surely there is a way to do this?
You still need the reference. Just like you need the reference to, say, System.dll which is also in the GAC. You just don't need the copy of the assembly in your bin\Debug directory. That you happened to not break the compiler by removing the reference is possible, especially since is this is an indirectly used assembly. But some odds that you'll eventually run out of luck.
In general you really want to avoid using the GAC on your dev machine. Because you care about specific versions of an assembly when you, say, create a bug fix. You get those specific versions from source control, not the GAC.
Doesn't it make sense that it would automatically include all dependencies? It cannot assume that AnotherLibrary is in the GAC on every machine you might want to deploy your code on. Of course as you mentioned you can manually remove it....

automate adding references in large VS solution

I'm working on a VS solution with 100+ projects in C#. I'm currently migrating it from VS 2008 to VS 2010. There is some work to be done because a lot of the projects use Enterprise Library 4 (which has to be upgraded to 5.0) and WCSF 2008 (which has to be upgraded to SCSF 2010). I'm going through the SCSF upgrade instructions, and one involves doing this:
Add a reference to the following
Service Location assembly in each
project that has a reference to an
Enterprise Library assembly.
Microsoft.Practices.ServiceLocation.dll
Is there any way to do this without going through the IDE? I mean, opening up each of 100-odd projects, then checking the references, then adding a reference if necessary, is one way of doing it, but is there a faster way? I was thinking along the lines of doing a search over the project files for a particular reference, then doing an insert if it was found.
If you've done this kind of thing before, suggestions would be very welcome. Thanks.
If you want to do this through the IDE, you can write a macro using VSProject.References to add/remove references as necessary.
However, C# project files (.csproj) are just XML, so you may be able to write a simple utility that can adjust the file as necessary using the standard XML classes.

Resources