0

I have few solutions that using the same .cs file.

I'd like to reference the file(so, the code will only be once) and each time it change,

the solutions that using the file will be updated as well.

For ex:

I have solution A in location C:\a

and solution B in location C:\b

and file common.cs in location C:\common

A and B use common.cs
  • The file uses 3 party using statement, so it cant be added to a project and compiled.

  • I've tried by Add -> Exiting Item but it copies the file, not reference it, so changing the original file, the reference will not be updated.

  • I also try using shared project but it's per solution and I need it to be cross solutions.

Any idea?

EDIT

This question is not familiar to this because I cant create a project and compile it. The files are using external libraries and the class library will not be compiled.

R.P
  • 171
  • 1
  • 11
  • 3
    Solutions are not Projects. Please clarify your terminology. – Dai Jun 06 '23 at 05:57
  • 1
    _"I've tried by Add -> Exiting Item but it copies the file, not reference it, so changing the original file, the reference will not be updated."_ - use the "Add as link" option and it won't copy the file. As for the `using` line, wrap it in an `#if` directive. – Dai Jun 06 '23 at 05:57
  • Look at step by step sample in here https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio?pivots=dotnet-7-0 – Ihdina Jun 06 '23 at 06:01
  • You *can* add project references from/to anywhere you like but it makes it hard for anyone else also trying to open, build and run your solution because they likely do not have the same drives and folder layout. – Filburt Jun 06 '23 at 06:04
  • @Dai - you are right. I'm adding references to projects, not to solution. I used 'solutions' because if it is under the same solution I can add it as a shared project or solution item, what I cant do as Im using it in multiple different solutions. – R.P Jun 06 '23 at 09:37
  • @Dai, I dont have Add as link option.. where can I have it? – R.P Jun 06 '23 at 09:42
  • 1
    @R.P "Add as link" is in the split-button menu in the File Browser dialog. I agree it's not very discoverable. – Dai Jun 06 '23 at 17:26

0 Answers0