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.
Related
This is the first time I start with StackOverflow...
I think my question is a silly question!!
I need to call the forms and classes from two C# projects in a third project
I follow these steps:
From Solution Explorer in a third project, I have clicked the Add Reference
I click the Project Tab
I didn't find any add browsing to add these two projects. see the image
Create your multiple project in a single solution. then add project1 and project2 in your project3 reference using >> Add Reference >> Projects >> Solution.
here's how: https://msdn.microsoft.com/en-us/library/f3st0d45.aspx
Your Projects should be under same solution.
If in case you are building two projects differently not under same solution follow these steps
1.Create a winform project let say "Project1" go to project settings change the output type to class library and build it.
2.Create another winform project lets say "Project2" go to project setting change the output type to class library and build it
3.Create third project from where you want to call it. Go to Add reference. Browse for folders as below
debug folder of project1 select project1.dll and add reference.
debug folder of project2 select project2.dll and add reference.
4.Now create objects of Forms and call.
Alright. Visual Studio offers you the ability to add references you just created yourself. Those references could be (dynamic-link-)libraries DLL or executables EXE. So go ahead and create a project and add a new Form. This custom Form needs to be public so the other project is able to extract the code.
Now you are able to add and use a reference. Just be sure to include the namespace, if it doesn't match the one, in which you're going to use it.
The thing is called Project-to-project Reference
I have merged another project in my existing project by right-clicking on the project name and selecting Add->Existing project option. Now i wan't to access the files from my newly added project from the existing one in Visual Studio (Its a C# project) , how can i do this?
If I'm following your question, you had a solution with a project A. You then added an existing project B.
You now want to access a file from A in B. If that's the case, right click on the B -> References and add a reference to project A. Now you can use the files from that project.
Edit: From your comment, I'm not sure if you want to have a separate project / file. If you want them to be only 1, you shouldn't really add a new project, you should add to your project A the files you need from project B. If you want to keep it as a different module that is included, then the above holds, but you need to realize that usually you have one solution, with many projects inside of it.
I struggle with this until I found this the link is below:
If you want all windows application to run as one program rather then calling multiple .exe. Then change 'Out Put Type' of each project to 'Class Library'.
Step 1:
You can do that by right-clicking on each Project in solution -> Go to Properties -> Application -> Out Put Type... set it to Class Library
Once you have done that output of these will be generated as .DLL.
Step2:
Add a new Window Form application project, add reference of exiting projects in it so that they can be executed from here.. you can do that by.. right click on main project-> Add Reference->Projects select all existing projects from here.
Now on the main application, you can create 3 buttons to launch each project...
[Inventory]
[Accounts]
[Payroll]
Now in each button code will be something like that...
Inventory_click()
{
Inventory.MainForm frm=new Inventory.MainForm();
frm.show();
}
Credit goes to forum post
I'm wondering if its possible to set up and share an entire folder of source code between multiple projects in Visual Studio 2012 like how eclipse lets you use multiple source folders. I'm currently developing an entity framework model for a game I'm making with split server and client code, said framework currently sits in a class library referenced by both projects.
The reason I'd like to use a shared code folder instead is to add code to each entity component type by declaring the classes in the shared folder as partial and having another partial class in the client/server projects that adds sided functionality. I thought that achieving this would be more useful than extending each component on both sides, and it would also eliminate the need to have a DLL included with the product.
you can add a project to your solution (right click Solution -> Add -> Existing Project) and reference it (right click on your project -> Add Reference -> Solution -> Projects -> "Project you want to reference")
You can right click on a project and select - Add - Existing item.... Within the open file dialog select the desired file, click on the arrow next to the Add button and afterwards on Add As Link
(source: modbusdriver.com)
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).
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.