Link to a common project in several solution projects

I'm trying to fix a warning

Warning CS0436: Type 'Class1' in '... \ SharedProject1 \ SharedProject1 \ Class1.cs' conflicts with the imported type' Class1 'in' ClassLibrary1, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null ". Using the type, defined in '... \ SharedProject1 \ SharedProject1 \ Class1.cs'. WpfApplication1 ... \ SharedProject1 \ WpfApplication1 \ MainWindow.xaml.cs

Repro:

  • create a solution with three projects:

SharedProject1 (add a new class to it)

namespace SharedProject1
{
    public class Class1() { }
}

ClassLibrary1

namespace ClassLibrary1
{
    public class Class1 { }
}

WpfApplication1 (add this to the constructor MainWindow)

public MainWindow()
{
    InitializeComponent();
    var a = new SharedProject1.Class1();
    var b = new ClassLibrary1.Class1();
}
  • link SharedProject1both in ClassLibrary1and WpfApplication1;

  • You will get a warning.

: ?

+5
3

:

Shared -> Class
Shared -> Application

Shared -> Class -> Application

: Application Shared.

, 2 dll. . Class dll , , Application.

, Class Application .

, . , - . . , .

+2

Jarekczek , , , , .

, ...

"Common", - , . "" .

, :

SharedProject -> Common
Common -> ClassLibrary1
Common -> ClassLibrary2
ClassLibrary1 -> Application
ClassLibrary2 -> Application
Common -> Application
+3

:

       namespace SharedProject1{public class Class1() { }}

In your WpfApplication1 project, you must add references to SharedProject1 and ClassLibrary1, after which:

I created a project for you with your speech:

Project example

0
source

All Articles