0

I have a Solution which consists of two projects - the Manager and Viewer. Naturally, both use the same classes, e.g. Manager is used to edit data in SomeItem class instances, while Viewer is used to display it's data.

I have all class definitions in the Manager project. To use them in the Viewer project, I created the same directory hierarchy in the Viewer and linked all classes with build action set to "Compile".

But now I'm getting tons of warnings like this:

The type 'SomeItem' in 'Manager\Classes\SomeItem.class.cs' conflicts with the imported type 'SomeItem' in 'Viewer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'Manager\Classes\SomeItem.class.cs'.

What is the best way to use the same class in two projects while having it in a single file?

Technical
  • 145
  • 1
  • 11
  • I don't quite understand what you did. What I would do when I want to use classes from another project is simply to right-click "References" and add a reference to the project. – Sweeper Aug 10 '19 at 04:11
  • I tried to add a reference, but it reported "A reference to Manager could not be added. Adding this project as a reference would cause a circular dependency.". To fix that I tried to remove the dependency, but I keep getting "This dependency was added by the project system and cannot be removed". – Technical Aug 10 '19 at 04:16
  • Do you have a reference to Viewer in the Manager project? If so remove it (and remove the linked classes) – iakobski Aug 10 '19 at 05:56

1 Answers1

2

I would suggest that you create a separate project with the classes you want to have in common, set application type as Class library, after doing this and compiling it you will be able to add it as a reference to both of your other projects by right clicking on references and adding it as a project reference.

Mark Hall
  • 53,938
  • 9
  • 94
  • 111