I am new at C#. I am creating a project that contains two solutions and I cannot reference one from the other. I need to use the classes that are in the AssestManagment to ManejoDeActivos. Is it possible to reference based on the screenshot below?
Reference other Solution
Technically, the project "ManejoDeActivos" is to have only the front end of the applicaction. It has the GUI. The AssestManagment project connects to a database, which will allow to add information to the DB. Inside the "ManejoDeActivos" we have a GUI that allow to add a new asset through a form. I having problems calling the Assest class that will allow to create a new object of an asset. I tried to add AssestManagment to ManejoDeActivos, however when I go to references I do not see the AssestManagment project and if I tried to browse it in my computer the project solution is not showing up
You could take the code needed from one of the solutions/projects, put it into a class library project, and compile it into a DLL. You can then reference that DLL inside of another project and access the code.
I would suggest reading How To Ask to learn how to ask a question properly.
Simplest approach will be to reference all the projects of the old solution on the new solution.
It might be cumbersome as the number of projects increase but would accomplish what I’m thinking you’re trying to accomplish.
Related
So, right now I'm working on a mapping project. All the data I have is static, but will eventually be turned into a service. I don't want all the data to be in my main file because it takes up to much space, and is too time consuming to get to the actual code. I want to put the data into it's own file within the project, but I can't get it to reference back the data in the main project. Any suggestions would be helpful.
I think you're looking for Resources. These allow you to include data in your project that is not source code. You can reference back to those resources via properties of a generated Resources class.
I'm not sure how to properly word the title, but here is the situation:
We have a massive solution with about 130 projects in it. There are some redundancies in code, namely a particular LookupButton control we've created. For some reason, instead of being created in the Infrastructure.CommonControls project that all modular projects reference, this LookupButton was created numerous times in the various modules. Quickly poking around through a few of the projects, I found 5 different versions of this control but the only difference is its namespace. All of the code is 100% the same.
I've been tasked with creating one of these LookupButtons in the aforementioned Infrastructure.CommonControls project, and then removing all duplicates from the Module projects.
How can I do this while causing minimal blowback in all of the Designer.cs files that will be looking for MyModule1.LookupButton, MyModule2.LookupButton etc. ? I know I have a backup with SVN but I'm afraid to even start and get inundated with errors...
Easiest thing is to just remove the redundancies from one project, then fix the compile errors in that project until it compiles again.
Push your new code to the SVN and then move on to the next project. There isn't much else you can do.
The following should work:
Ensure you have the current state in SVN
Add the code to Infrastructure.CommonControls
Remove the code from all projects that it does not belong in
Compile the solution
Go through all of the errors. For each occurrence of LookupButton errors, right-click on LookupButton in source control, pick Resolve, and select the option to add a using statement.
You should only find yourself correcting the 5 projects that had their own internal copy of the control, not all 130.
Maybe this is the wrong question. I don't understand the hierarchy/relationship between solutions and projects, so I'll describe my goal first. I have a forms application which works. I want to copy everything in it to another folder on the same PC with a different name which reflects the purpose of a new forms app I want to build. I want to use the old parent which I copied as a skeleton, a starting point. I've tried copying the whole WindowsFormsApplication1 and renaming it, but when it builds, it refers to stuff in the old parent folder. I want each of these to be totally self contained, not reference something above the new folder I just made with the skeleton.
Can someone describe the relationship between projects, solutions, the folder which gets created called WindowsFormsApplicationx and the .sln file? If this is too general, I'd be happy with just some step-by-steps to accomplish my goal.
Thanks for your patience,
Lamar
Thanks onlinecop, this helps but I’m still not all the way there.
When I created the forms application, it made a set of files and directories in the Studio2010/Projects directory:
WindowsFormsApplication2.sln
WindowsFormsApplication2.suo
WindowsFormsApplication2 (folder)
Bin (folder)
Obj (folder)
Properties (folder)
Form1.cs
Form1.Designer.cs
Form1.resx
Program.cs
WindowsFormsApplication2.csproj
WindowsFormsApplication2.csproj.user
I used Forms Designer to make a presentation layer, which although it doesn’t change much, it does change some.
I want to start with all of these and may or may not make changes to them but I will want to change all of their names.
Besides changing the names, most of my changes are in the Form1.cs and wherever Forms Designer keeps its changes. Since it is a graphical input and not text, I don’t know where it stores its stuff.
I’d like to do this without disturbing anything with the originals.
Almost none are unit tests, and most are new, addressing different applications so I don’t want to depend on a version control tool.
I’d like to not use them by reference, but instead by copy because I want the parents sequestered and unchanged.
So it would seem that I would want these to have completely different solutions, not projects inside of a solution….is this right?
Will the “Add Existing” do this for me, and where should I do it
As I’m reading the tutorials, my impression is that basically a solution is associated with an application and projects are sub-entities which might be incremental changes to host unit tests or debugging.
So since I want to make a completely different application, which I do not want to have confused with the parent, I’m thinking I want a new solution. But I want to use most of what I had in the parent so how can I create a new solution and populate it with the contents of the old source files and rename them? I’d like to not have them called Forms1.cs and WindowsFormsApplication2…..more something descriptive of what they are, like NeutronMigrationAnalysis…
If I’m asking the wrong question, it might become clearer if I understood when I should create a new solution instead of a single one with a gazillion projects in it.
Thanks!
Lamar
A solution contains multiple projects.
Let's say that you create a Unit Test. That test will run methods that you've created in a different project, just to ensure that those methods work correctly. So within this solution, you actually have two projects: one which is your normal forms app, and one that is a Unit Test which you, as a developer, can see but that end users won't.
The folders are merely hierarchal in nature: It helps you keep your projects separate, and files in places easy for you to find.
So take your original forms project, within your master solution. Your solution file (usually a .sln file) defines that you have a single project within it, and the directory where it's stored. It usually keeps track of other general or global information as well.
The forms project contains its own project file (usually a .csproj file), and is usually found within whatever subdirectory it was initially started in. That will define all the files that you want included, all of the special build options, the logical layout of your folders, files, and resources, and so on.
When you want to recreate a skeleton project, you will usually create a new, empty project. Then, copy all of the source files into it from your form project and "Add existing..." the files so they are seen by this project. Doing it this way will prevent the .csproj file from being copied from the original project and keeping all those old parent folder files/references.
I'm using VS2010, and developing a C# WinForms app.
I would like to create a new form, that inherits from a form in a different dll. I right click on my project, hit 'add new item' and then under 'forms' click 'inherited from'.
At this point I get the error: 'Unable to load assembly 'X'. Ensure that the file is a valid .net framewrok assembly'. I hit OK, and then get another error for 'Y' project. They are both C# .net 4.0 winforms projects.
The important note here. I don't care about those two projects. I have 270 projects in my solution, and Neither of them are even control libraries. They are .exes.
So, the question:
Is there someway to mark the entire dll as "Im not going to be using any public types, and i don't want to ever load from the inheritance picker"? If not, is there anything I can look for that would help figure out why these 2 of 270 projects wont load?
I know I can just create a new form and manually type the actual class I want to derive from. I need visual studio to work the intended way, and wanting to avoid shortcuts. Also, i've gone through and marked every single class in both projects as either private or internal.
Thanks!
I have a project, lots of files, lots of work, etc.
It turns out that I can do a few hours of work, and change it into something totally different; but useful for a debug project elsewhere in the shop.
I want to do that, but create a different app; one which uses the same large amount of existing (tested, and working) code, but just changes some buttons and displays and so on.
What's the best way to do this ? Use the OS to just duplicate the entire file structure ? Then hack the thing ?
Should I start a new project and add the same classes until it's duplicated that way ?
Does C# have some sort of an "import and copy" function ?
What OP and I decided on doing in chat:
After a long chat discussion this is what OP and I decided on doing for his code:
Create a new project (in OP's case WinForms) and solution in visual studio by clicking File -> New Project
Import the existing code into the new project by right clicking on the new solution and selecting the option Add -> Existing project and adding the original project OP needed code from
Reference the existing project from the new project by clicking on the references part of the new project in the solution explorer and selecting add reference and then choosing the project OP wanted to get code from
Add using OLD_PROJECT_NAMESPACE; to the top of the code in the new project to have access to methods in the old project namespace.
This provides the following benefits:
Old projects remains unchanged
New projects shares old project's code like OP asked for
A more general answer for code sharing scenarios
You might want to consider making the original program into some sort of more reasonable API. Given that you're using the functionality twice you might do so again. The better thing to do is to extract the classes you'd like to share into a different project and then import it twice, once in the original program and once in the new program.
If you can't do that, here is what I would do:
You're a software shop so I'm assuming you have some form of source control. Most source control programs have some notion of branching your source.
I'd create a new folder, pull the source from the repository and branch it to a different branch.
What you get:
You can easily pull bug fixes from the main branch and thus continue to share code between the projects
You can easily push bug fixes back to the main branch