how to use same name class libraries on a solution - c#

Need to add two same name .csproj class libraries in my solution.Have two project but unfortunately those project class libraries names are same,like: Hello.csproj.I try to add existing project on solution then show me error
http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx
from above url I learned how to use same namespace dll on same project ,but I need help how to use same classlibraries on a solution
if have any query please ask,thanks in advanced.
Note:ok people want to know the reason,i have two project on Autocat 2005 and 2010,now want to merge those project on one solution,2010 update base on 2005 so class libraries are same,but i need to use both of them.So problem arise and seeking help.

You can have projects with the same name as long as they are already created in different folders and they are in different solution folders. If the projects are already created, do this to add them to your solution:
Add your first project to the solution.
In Solution Explorer window, right click your solution and select Add->New Solution Folder
Give a name to the newly created folder.
Right click the folder and select Add->Existing Project
Navigate to your second project and double-click the .csproj file.
You're done.

If you really must do this, then ensure the second project has a different name, and then change the namespaces of the classes in the second project (normally the project name comprises the first part of the namespace - just change that part). The classes will still be identical internally, but because they have a different namespace they will be distinct entities. This will lead to very smelly code though when you start mixing them up in the ClientApp - to avoid confusion make sure you always refer to them by their full namespace (i.e. do not have a using xyz.myclassname; statement at the top of the class file that uses them).
Maybe you want to run two (almost identical) instances of the same service or something, but as mentioned it is hard to think of a genuine reason why you would need to do this. If you are looking to have two identical looking instances but different implementation then you will want to use interfaces instead.
Edit: Visual Studio will not allow you to have two identically named projects, and you are playing crazy games if you change a project name but don't change its project GUID (in the .proj file and the .sln file).
The simplest thing for you to do here is to create a new empty project in the solution explorer, right click on it and Open folder in Explorer, then copy the class files from the original project to the new one, then back in the solution explorer choose Show all files (little button at the top of the solution explorer), then select the newly added files under the new project, right click, Add to project. (These menu options are from memory, they should be roughly right).

Related

Where to define files required by many projects in visual studio?

Let's say I have 5 or 6 projects in my solution. There is a file called fileCopyHelper.cs that basically copies files from one folder to another. I need this file for a lot of projects in the solution and I don't want to keep redefining it in every project? How do I do it?
I tried adding a .cs file to the solution and Visual studio grouped it into Solution items folder. However I'm unable to access the classes defined in this file in my projects because Solution items is just a folder, not a project, so I can't add a namespace reference from other projects.
Add a new project to your solution, and select the class library type. This gives you a single place to add code that will be shared.
Reference the new project in whatever other projects in your solution need access to the code.
Your setup might look something like this, where the fileCopyHelper class is party of ClassLibrary1, which is then referenced and used in the main ConsoleApp1 application:

Add referenced projects into solution automatically

My situation:
I have a solution A with hundreds of projects,
Some of projects are class libraries and are referenced from other projects.
Now I want to create a new solution B which will consist of subset of projects of solution A. I start by adding the first pre-existing project into this new solution B. This project is referencing couple of class libraries from solution A. Therefore it is logical that these libraries cannot be found and I cannot build. Of course I could add all the referenced projects manually into the new solution B but that would take quite a long time, considering the total amount of projects that I need to add.
Is there some built in Visual Studio feature that can take care of this on my behalf? I.e. I will be offered an opportunity to import all the referenced projects at once and the B.sln file will be updated automatically.
I also have a ReSharper extension but I couldn't find such feature in there as well.
EDIT:
Some more detail on what I am trying to achieve. A.sln has lots of application projects and literally hundreds of class libraries. I want to create a new B.sln for one particular application project from A.sln and only add the class libraries that it is referencing, directly or indirectly... But the dependencies can go up to 15 levels deep so manually removing projects from original A.sln to create B.sln is really not suitable for me as I would have to carefully consider each one of the projects that I would be manually removing from the original sln file, subsequently reviewing the csproj files to find whether the application I am interested in does not indirectly depends on them via one of its direct references.
Copy paste your current solution file and start with it. Open it in new Visual Studio Instance. Remove your projects one by one. Instead of adding new projects, removing unnecessary ones will be more easy for you. As far as I know there is no such feature in Visual Studio as you want.
Removing will be more easy since projects are already there. Do not use Visual Studio to remove project but open sln file in suitable programmers notepad. Your projects are added to sln file as below lines.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Example.Integration.App1", "..\Example.Integration\Example.Integration.App1\Example.Integration.App1.csproj", "{E3977144-AFBA-451D-894C-1F89AA008041}"
EndProject
Removing such lines will be more easy if your projects has naming convention.
The best way to port references from an existing project that I've found is to generate a template for that project.
On the File menu, click Export Template. The Export Template wizard opens.
Choose project template and move through the wizard
Click Finish. Your project is exported into a .zip file and placed in the specified output location, and, if selected, imported into Visual Studio.
Now, when you setup a new project for solution B. You'll be able to choose the project template from A and all the file structure/references are preserved.
Ref: http://msdn.microsoft.com/en-us/library/vstudio/xkh1wxd8%28v=vs.100%29.aspx

Adding common files to different projects in C#

I have 2 project in difference paths. I want to use some common files (.cs files) in both of projects.
D:\Tests\WindowsFormsApplication_1\WindowsFormsApplication_1
D:\Tests\WindowsFormsApplication_2\WindowsFormsApplication_2
D:\Tests\Common
How do I add this common files from one path ("Common" folder) for both of the projects?
Yes, You can. Right Click on your project, "Add" -> "Existing Item...", select your *.cs file and click on Down arrow next to the "Add" button and select "Add As Link".
There is no way to use same files in 2 different project without copying them. But you can add the third project in type of class library and put your shared files in it then add references to that project in your previous projects
If you want the common files to be available to edit in your other projects then
follow user4015859's suggestion re setting up a class library project for your common files, but rather than adding a reference to that project in your other solutions, add the actual project to your solution by right clicking on the solution and select Add > Existing Project...
You still need to add a reference but in the reference Manager dialog (right click on references to open it) select Projects on the left hand side and your common project should be listed. Tick it and click OK.
To use the classes etc from the common project just add its namespace in the units where you want to use it.
This way you can edit the common files from either of your other solutions and you don't need to manually build your common solution when any of the files are changed.

How to compile a single project in a solution that has other projects?

I've had the errors shown in the picture and I suspect the first 2 are because it is trying to execute all projects but the last 2 I'm not sure (think it might be just cascade from the other 2)
I have 3 projects in my solution but I just want to compiple ParserTest... is there a way to compile only this project without changing the others to Class Library? (and even to change them to class library, is there an option to change it or do I have to create a new project and copy all files?)
Any hints/suggestions are appreciated, thanks!
You can change the "Output type" of your project.
Right click the project in the Solution Explorer and go to Properties.
Under the "Application" tab, there is an Output type option:

Combining between two csproj files safely

I have two very long and detailed .csproj files.
I want to combine them into one.
I used text comparer but the items are not in the same order
and it's hard to isolate differences.
How would you recommend to combine them?
(they have compile, include, post build and after build events)
edit:
I want to merge 2 unrelated projects with some common dependencies
Copy the files from project 1 into the project 2 folder. Then turn on "Show all files" so you can see the files that aren't in the project. Then right-click each file and choose "Include in project".
I would probably do most of this in Visual Studio. You can either drag the files you need from one project to the other, or you can copy all the files from one project folder to the other in the file system and turn on "show all files" in the solution explorer to show which need to be added. You will then need to align the namespaces. The Class View window can help identify types which do not fall inside the right namespace. A refactoring tool like Resharper can also help fix up the namespaces.
If you have explicit pre or post build events in each project, I would use the VS GUI to show these and manually combine. If you have custom build targets/tasks in the files, I would isolate these in a good text/XML editor and manually union them as required.
The other thing you will have to do is to add references to the final project which it did not originally require but were required by the other project. It should be quite quick to identify which references need to be added, by attempting compilation and inspecting any errors.

Categories

Resources