'How can build independent dll's that depend on the same source?

I am building a few different C# libraries that both depend on a single C# file we'll call Dep.cs, and these dll's need to be used together in a Unity project. I'd like to set up these projects in the following way:

  1. The C# libraries can be built independently of one another using Visual Studio
  2. C# libraries (i.e. dll's) can be imported into a Unity project without conflicting symbols
  3. The C# library projects (i.e. the source code for each library via git submodule for example) can be imported into a Unity project without conflicting sources.

I've solved (1) by including Dep.cs in each library project that requires it, though this causes issue with (2). And I've solved (3) by putting the dependency in a folder like Dependencies~ so that Unity ignores the file (this way no duplicate classes are found).

I'm having trouble solving (2) however. I thought I'd be able to add Dep.cs as reference in the VS solution but This doesn't seem to work. I've heard of Assembly References but I am not sure if they do what I need.



Solution 1:[1]

You can use "Add File as Link" from Visual Studio "Add Existing File" screen. It also works well with git submodule, just place Dep.cs anywhere in a parent folder or in the solution's root directory.

To get the same result you can also directly edit the .csproj file and add a compile instruction:

<ItemGroup>
  <Compile Include="..\..\Path\To\YourFile.cs" Link="YourFile.cs" />
</ItemGroup>

This method solves all the issues you mentioned.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user1624411