Help me sort out perhaps badly done folder/solution structure so I can add a shared Class Library
Ok, so I have two solutions which must be separate so I can execute them both at the same time so they will communicate (it includes TCP communication between them). They are both inside their own folder (called "Servidor" and "Cliente1") and both these folders are in turn inside a unifying folder called "TP1Code". Here's the output for the root folder of this project from the command line which may be enlightening (truncated for simplicity):
The important folders here are TP1Code itself, Servidor and Cliente1. What I want to do is add some code (only methods really) which is viewed and usable from within Servidor and Cliente1. Perhaps in the form of a Class Library?? Help?
30 Replies
Any suggestions on how to do the shared code part appreciated, also
Oh, and as you can tell I already created a CommonLibrary folder with a CommonUtils.cs file with a class of the same name for the shared code to go inside of.
For some reason the tree powershell command output I posted above doesn't show that file, which may signal some problem here...
Usually, the structure is more along the lines of
.Shared
being referenced by .Gui
, .Api
, and whatever else
And, yes, .Shared
being a class library
Also, as a side note, to everybody including yourself a solid and use only English in your projectsI'd love to, but I'm working within an environment where some people may not understand english that well or at least find english to be an added dificulty
My condolences
I mean, I understand their position. Most of them haven't had the support and opportunities to learn English that I have had. But it's still frustrating
And how do I do this? I tried the
dotnet add reference
command in the shell and it seemed to work fine, it even added the reference in the .csproj fileThat's how
but when I try to write the using statement up top it dosn't know
wait
yeah, it doesn't know wtf im talking about
Is it a
<ProjectReference>
?no, in fact I said it has it in the .csproj but it seems I was wrong, at least the one I'm looking at
MyProject.Api.csproj
would have
in itThis should workyeah, only the root project containing the others has a project reference
But I did the command inside each directory and it said it was included correctly. Why isnt it there already?
¯\_(ツ)_/¯
What was the exact command you used?
Wait, maybe it said already included because it was included in the containing folder, I don't really read shell output messages unfortunately sometimes :peepoNoted:
And I assumed it said added
dotnet add reference
..\CommonLibrary\CommonLibrary.csproj
taken straight off the MS docuAre all the project under the same solution?
No, it's three separate slns
Oooof
Why? One solution per project?
Yes, it has to be that way because the whole point of the project is to simulate a distributed system, which means you have to have two programs running concurrently and get them to communicate with each other
Doesn't mean they can't be in the same solution
So I can nest two solutions under one unifying solution?
No, why?
One solution, three projects
KISS
But I need to have two concurrently running console apps, so two console windows at the same time. Can I do that with just two projects under the same solution? Won't that just create one shared console app because it's one "executable"?
Of course you can
Each project builds on its own
If you have a WebAPi project, and a WPF project, they don't automagically merge into a WPF-but-also-api chimera
dotnet run -p ./Servidor/Servidor.csproj
will run only the servidor
dotnet run -p ./Cliente/Cliente.csproj
will only run the clienteYeah, I see what you mean. Already did it too with the very convenient "add existing project" button
just need to config three separate startup projs right?
in the GUI
I guess I could just do dotnet run, yeah
Yeah, you can configure three profiles
Ok, now that all the projs are under same sln, how should I access my shared code?
As long as the path is right
This should work
I'm sorry I'm really clueless with this stuff, this is my first time venturing into different file structures and .net functionalities
ok, ill try that
but that goes into each .csproj right?
Now, granted, I usually have a very flat structure to my solutions (no
TP1Code
folder, in your case) and Rider usually just references any projects for me as I type
Each project that references the shared one, yesOk, that was about 17 headaches combined, but I was learning how to use a more complicated file structure and how to add a shared class library at the same time so I guess it figures
Thanks again @ZZZZZZZZZZZZZZZZZZZZZZZZZ sorry for one more ping, but this one is a love ping ❤️
Anytime :Ok: