I have a large solution which is built daily in TFS. The solution covers multiple logical sub solutions - e.g ApplicationA which consists of projects A,B,C,D; ApplicationB which consists of projects A,B,E,F, ApplicationC which consists of projects A,C,G,H.
Currently we make a copy of the build solution file locally and unload projects we don't need to build to work on a project - so for ApplicationA we'd unload everything other than A,B,C,D.
Another approach would be to create multiple solution configurations which would only build projects A,B,C,D for ApplicationA - but I fear this would be cumbersome and the .sln file would end up huge.
The issue is that many projects are brought together into one wix package and installed together - so the main .sln file makes sense, especially from a build point of view but also debugging.
Maintaining multiple solution files doesn't seem right as when new projects are added we'd need to add them to multiple solutions. So perhaps the configuration method is the way to go, but it doesn't feel right either.
Does anybody have experience of a similar scenario, and how did you get around it?
It sounds like it would make sense to have five solution files:
Master.sln, contains all projects
ApplicationA.sln, contains projects A, B, C, D
ApplicationB.sln, contains projects A, B, E, F
ApplicaitonC.sln, contains projects A, C, G, H
It's fine to have all of those solution files in the same top-level directory.
But maintaining multiple solution files isn't feasible as when new projects are added we'd need to add them to multiple solutions.
Why is that a problem? You need to work out which applications the project is required by anyway... Create the project in the master solution (which will definitely need it) and then use "Add existing project" for the solutions which need it. It's really not that much work - and I wouldn't expect that new projects are added that often anyway. (If they are, that's an indication of a bigger problem.)
Related
I have multiple web projects in one solution with several requiring others to be running in order to function. For example, project A may require projects E and F to be running and Project B may require Projects F, G, and H to be running.
Is there a way to have visual studio manage these dependencies so that when I go to debug project A, projects E & F also starts automatically? I know I can set multiple startup projects in order to make sure both projects startup when I go to debug, but this means that when I go to run project A, I need to have memorized which other projects also need to be set to startup and the same for all of the rest of the projects, each of which has different requirements for running.
Maybe remove runnable projects to separate solutions, and class libraries to one or more solutions which you will reference when needed...
This way, you will run what you need and when needed only, and reduce number of references you have...
Then, you may run everything manually, or create some automated build system with, for example, dashboard app, which will build and you can chose what to run and what do you need active...
Also, keep project specific code inside a project solution, and move shared class libraries to shared solutions, in order to keep your code clean and not duplicated...
If done well, this could lead to lots of code decoupling and simpler app diagram...
Go to your solution and right click on the main one and select Set Startup projects... then pick Multiple startup projectsand if you want to projectB runs before projectA then just move it using the arrows so projectB is above to project A
If needing more assistance, you can also check this official documentation:
https://learn.microsoft.com/en-us/visualstudio/ide/how-to-set-multiple-startup-projects?view=vs-2019
I'm encountering a weird solution structure in my company—the different layers of the application are organized in folders (instead of in projects).
For instance, there are folders within the solution named "DAL", "BL", "WCFClient," etc. I've never seen that before, but can't quite put my finger on what troubles me about it.
Can anyone tell me if there are any cons (or possibly pros) for this folder-based organizational approach?
Here are few cons and pros for C# (.NET) projects:
Pros:
Multiple projects can cause circular reference problems if classes are not put into correct assemblies. See http://en.wikipedia.org/wiki/Circular_reference and
Why are circular references in Visual Studio a bad practice?
Multiple projects leads to multiple dll files. Handling those MIGHT be tricky if they are piling up a lot. For instance we had ~200 files in our project and TeamCity sometimes lost few files at build process. We got around of it by zipping our files before deploying them.
Cons:
Code is not modular. You cant reuse parts of it in other projects. I think this is one of biggest downsides. For instance if you want to use one class from assembly. You have to add reference to whole project.
One project can grow HUGE and cause multiple problems. Starting from name collisions (In VB.NET there are no namespaces automatically created for folders) into deep folder trees.
Searching from huge project is harder than from small one (depending how accurate the foldering is)
I have a few classes that are abstracted in a way that I can use them in multiple projects. I'm always working on these classes, optimizing, adding, etc. So when I optimize something in one of these classes, I then need to copy that new version into every project I remember using it. This isn't a very good way of doing it, but is there a better way?
Thanks
Put these base classes in a single project and share this project between your different solutions as an referenced class library. This way you will not have to copy / paste anything between projects or solutions and everything should always be up to date.
You could even set-up a local NuGet feed so you can use NuGet to retrieve this shared project as a reference in a well structured and managed way.
Instead of manually copying the updated classes to every project that uses them, create a Class Library project and reference the compiled file in every project that uses the classes. Organizing your classes like that will help you to follow the DRY ("Don't repeat yourself") principle.
If you need to reference files instead of compiled libraries, however, you can reference a file as a link so that multiple projects refer to the same file without copying it to each solution folder. To do that, right-click on your project, choose Add existing item..., browse to the .cs file, and choose Add as Link from the combobox in the right lower corner.
How about if you extract the classes into a separate project, and add a reference to this project in every project you are using?
It is a bad idea to copy paste file throughout the application. To avoid these repetitions you can either:
make a link, if the amount of file is really small . In the Solution browser of Visual Studio, right click, Add Existing file, chose your file and in the split button, choose Add as a link
create a separate project and reference this project wherever is is necessary if the amount of files not tiny.
Create a base-lib and build it to a "shared" location. Add a reference to it in you project. It will keep the other projects smaller and will be faster to build.
I created a brand new blank Visual Studio 2010 solution, and added an existing C# Project to it. I built the solution and it compiled correctly.
But when I go the solution folder, I see that the imported C# project is not physically in that folder. It seems it only references the project to wherever it is.
Is this intended? Should I even worry about this?
How can I create a physical import, meaning the project is copied to the solution folder?
How can I create a physical import, meaning the project is copied to the solution folder?
If you want to do this, copy the project to the solution (outside of VS), then add the local copy directly.
The default behavior allows you to share a project between two solutions. This is occasionally useful (if handled with care).
'How do I create a physical import?'
You don't - you're adding a project to the solution which will always result in referencing it in-place. In order to structure your solution you need to copy or move the existing project to the desired folder, created any desired Solution Folders to match the physical structure and then Add existing project as needs be.
The other alternative is to Add new project and then copy all of your project data over from the existing one but this will be prone to errors at some levels.
Adding an existing project always makes reference to the original. That makes sense in a lot of cases. If you want to use the project in a number of solutions and you want to make sure that they are always using the same version then you have the choice to either just reference the compiled library or have it available in each solution. If you do have it available in each solution then the risk is that you will make some mod of it in one solution that breaks the others. I am pretty good at doing this!
As mentioned already if you want to modify that project and don't mind if it gets out of sync with other versions of it then you need to copy it into your solution folder and then add it from there.
The version control software I use pretty much forces me to do that as it does not like code that is not located inside the solution tree.
It's not code-related but IDE related. I'm working on a .NET solution with about 35 different projects. These projects need to be re-organized into a new folder structure. Why? Because about 10 of those will be removed and the rest will be divided in more logical units.
One way to do this is by creating a new solution, Drag&Drop the projects into a new folder tree within the Windows explorer and then just add them to the new solution.
To be honest, that sounds dumb!
Is there a way to just move projects into different folders from within the IDE? I've tried to "save as" the projects but the IDE won't accept a different folder.
It's irritating but because there have been a few wrong choices in folder names, I'm now stuck with those names.
Example: Right now I have a project main folder which contains child folders named "Client", "Server", "Business", "Database" and whatever more. Within those child folders, there are more child folders, each a three-digit number. Within each numbered folder there's a project which is named in some logical way, like Company.Business.Customers with additional logic within this project.
The problem is that not all projects now follow this naming convention and I consider it obsolete.
A project like Company.Business.Customers should just be in a folder named Company.Business.Customers in the project root so it's easier to recognize. The name already makes it clear that it's a business class for this project. The clear division within client classes, business classes and whatever more just needs to be arranged within the solution, but I want to flatten the file structure. (And remove some obsolete projects.) Basically, I'm not refactoring, I'm just cleaning up.
VS2008 doesn't seem to have such an option, though...
Fire up notepad.exe and open the .sln file. And start Windows Explorer, navigate to the solution directory. Observe how the .sln file content matches the solution structure. Edit the entries, make the corresponding change with Explorer. Backup first.
I don't think there's an easy answer here. Your main problem is going to be that Visual Studio (or .NET) doesn't care if you have classes that belong to a different root namespace sitting in a project.
So if you have a project called Project.BusinessObjects and another project called Project.DataObjects there is nothing stopping you from putting a class called Project.BusinessObjects.User into the Project.DataObjects project.
I don't know of any way of doing all of this without a lot of manual work. Resharper will help quite a bit if you use the 'namespace rename' feature, but you're still gonna end up with a lot of grunt work.
Also, be VERY wary of doing this in conjunction with version control systems. You have to know your version control system really well to know how it's going to react to such major refactoring.
Other than that, what you are describing doing is not all that difficult. You do have to edit the solution files and maybe the project files by hand, and you might need to remove a project from a solution and add it again when it's under the right directory.
I would make a backup, and then refactor away. I think it is a mistake to think that you can do everything you need from the IDE, though. And if you do what you describe from the IDE in a source control system that uses the old Visual SourceSafe API, you will certianly (guaranteed) mess up your bindings, that API is just not made for moving (or renaming, for that matter) files around in the way you describe. The best way to do this under that scenario is to remove all source control bindings and then re-add the reorganized solution back in.
It's not that difficult, you just have to prepare (do a backup) and experiment until you get it right.
I don't think there's any way to do this from within Visual Studio, and as #gmagana points out it's going to be very difficult to do if the files are under version control.
However, it is possible to do it manually.
Start by creating the new, desired folder structure - ignore the .csproj files and solution files for now, and more the .cs files you're interested in into the new structure.
Now, fire up Visual Studio, and create a new, empty project. If you have different types of projects, you might want to create one new, empty project for each type. This will leave you with an empty .csproj file, and a .sln file with just one project.
Copy the empty project file to where they're needed, and rename them as needed. You can edit them and change the Assembly name and default namespace if you want, or wait until you're done and change the settings with Visual Studio.
Finally, edit the .sln file, and remove the Project section. Copy the empty .sln file to where you want it, and open it up in Visual Studio. Now go and add each of your existing projects to the new solution.
Within each project, click the "show all" button, and start including all the files you've copied into the project structure. Resolve missing dependencies, change the namespaces and assembly names for the project, and make sure that the code files don't specify a namespace you don't want. Repeat until done.
Once you get the new solution to build, it will be helpful to open up the DLLs in Reflector in order to ensure that you haven't missed any namespace declarations in the code file - if you're trying to get to a point where there's a 1-1 correspondence between the DLL and the namespace, or even ensuring that no namespaces are split between DLLs, Reflector is your friend.
Good luck.
I've used the following solution to solve my problem:
I started with a new, empty solution in a new folder.
For every project that needed to be moved, I used the Windows explorer to create a child folder in the solution folder, this time with the proper name.
I copied the projects from their original location to their new folders.
I added all the (moved) existing projects from their new locations.
In the Solution Manager, I renamed the projects to a better name.
I fixed the project properties and other settings for all projects.
This did clean up the whole project quite nicely. I then added the whole project to Vault (Version Control System) and once it was in the VSS, I deleted the folder again (actually, just renamed it first) and retrieved it back from the VSS system so any obsolete binaries and other garbage was gone too.
It's a lot of work, but the result turned out exactly what it needed.