Declare a SharedClass in a common namespace instead of two different namespaces. You can associate a file with projects, and not include it physically.
From MSDN :
You are referencing a file from your project in Visual Studio. In Solution Explorer, right-click your project and select Add Existing Item. Or type Shift + Alt + A. In the Add Existing Item dialog box, select the file you want to add, and in the Add drop-down list, click Add As Link.
namespace Khargoosh.MathLib.Common { public class SharedClass { ... } } namespace Khargoosh.MathLib.Library1 { ... } namespace Khargoosh.MathLib.Library2 { ... }
or
namespace Khargoosh.MathLib { public class SharedClass { ... } } namespace Khargoosh.MathLib.Library1 { ... } namespace Khargoosh.MathLib.Library2 { ... }
A completely different way of processing is to use the T4 template with some logic to dynamically create a file. The contents of the * .tt template files (not * .cs files!):
namespace library1 { <#@ include file="MyCommonClass.cs"#> }
And in another library
namespace library2 { <#@ include file="MyCommonClass.cs"#> }
The class file itself will not declare a namespace.
source share