C
C#9mo ago
Gipper

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):
C:.
├───.vs
│ └───TP1
├───CommonLibrary
│ ├───bin
│ │ ├───Debug
│ │ │ └───net8.0
│ │ └───Release
│ │ └───net8.0
│ └───obj
│ ├───Debug
│ │ └───net8.0
│ │ ├───ref
│ │ └───refint
│ └───Release
│ └───net8.0
│ ├───ref
│ └───refint
└───TP1Code
├───.github
│ └───workflows
├───bin
│ ├───Debug
│ │ └───net8.0
│ └───Release
│ └───net8.0
├───Cliente1
│ ├───bin
│ │ ├───Debug
│ │ │ └───net8.0
│ │ └───Release
│ │ └───net8.0
│ └───obj
│ ├───Debug
│ │ └───net8.0
│ │ ├───ref
│ │ └───refint
│ └───Release
│ └───net8.0
│ ├───ref
│ └───refint
└───Servidor
├───bin
│ ├───Debug
│ │ └───net8.0
│ └───Release
│ └───net8.0
├───Files
├───obj
│ ├───Debug
│ │ └───net8.0
│ │ ├───ref
│ │ └───refint
│ └───Release
│ └───net8.0
│ ├───ref
│ └───refint
└───Properties
└───PublishProfiles
C:.
├───.vs
│ └───TP1
├───CommonLibrary
│ ├───bin
│ │ ├───Debug
│ │ │ └───net8.0
│ │ └───Release
│ │ └───net8.0
│ └───obj
│ ├───Debug
│ │ └───net8.0
│ │ ├───ref
│ │ └───refint
│ └───Release
│ └───net8.0
│ ├───ref
│ └───refint
└───TP1Code
├───.github
│ └───workflows
├───bin
│ ├───Debug
│ │ └───net8.0
│ └───Release
│ └───net8.0
├───Cliente1
│ ├───bin
│ │ ├───Debug
│ │ │ └───net8.0
│ │ └───Release
│ │ └───net8.0
│ └───obj
│ ├───Debug
│ │ └───net8.0
│ │ ├───ref
│ │ └───refint
│ └───Release
│ └───net8.0
│ ├───ref
│ └───refint
└───Servidor
├───bin
│ ├───Debug
│ │ └───net8.0
│ └───Release
│ └───net8.0
├───Files
├───obj
│ ├───Debug
│ │ └───net8.0
│ │ ├───ref
│ │ └───refint
│ └───Release
│ └───net8.0
│ ├───ref
│ └───refint
└───Properties
└───PublishProfiles
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
Gipper
GipperOP9mo ago
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...
Angius
Angius9mo ago
Usually, the structure is more along the lines of
MyProject
├──.git
│ └──...
├──.github
│ └──...
├──.vs
│ └──...
├──MyProject.sln
├──MyProject.Gui
│ ├──MyProject.Gui.csproj
│ ├──Program.cs
│ └──...
├──MyProject.Api
│ ├──MyProject.Api.csproj
│ ├──Program.cs
│ └──...
├──MyProject.Shared
│ ├──MyProject.Shared.csproj
│ ├──MathHelpers.cs
│ └──...
MyProject
├──.git
│ └──...
├──.github
│ └──...
├──.vs
│ └──...
├──MyProject.sln
├──MyProject.Gui
│ ├──MyProject.Gui.csproj
│ ├──Program.cs
│ └──...
├──MyProject.Api
│ ├──MyProject.Api.csproj
│ ├──Program.cs
│ └──...
├──MyProject.Shared
│ ├──MyProject.Shared.csproj
│ ├──MathHelpers.cs
│ └──...
.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 projects
Gipper
GipperOP9mo ago
I'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
Angius
Angius9mo ago
My condolences
Gipper
GipperOP9mo ago
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 file
Angius
Angius9mo ago
That's how
Gipper
GipperOP9mo ago
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
Angius
Angius9mo ago
Is it a <ProjectReference>?
Gipper
GipperOP9mo ago
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
Angius
Angius9mo ago
MyProject.Api.csproj would have
<ItemGroup>
<ProjectReference Include="..\MyProject.Shared\MyProject.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MyProject.Shared\MyProject.Shared.csproj" />
</ItemGroup>
in itThis should work
Gipper
GipperOP9mo ago
yeah, 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?
Angius
Angius9mo ago
¯\_(ツ)_/¯ What was the exact command you used?
Gipper
GipperOP9mo ago
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 docu
Angius
Angius9mo ago
Are all the project under the same solution?
Gipper
GipperOP9mo ago
No, it's three separate slns
Angius
Angius9mo ago
Oooof Why? One solution per project?
Gipper
GipperOP9mo ago
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
Angius
Angius9mo ago
Doesn't mean they can't be in the same solution
Gipper
GipperOP9mo ago
So I can nest two solutions under one unifying solution?
Angius
Angius9mo ago
No, why? One solution, three projects KISS
MyApp.sln
|— Shared
|— Servidor
|— Cliente1
MyApp.sln
|— Shared
|— Servidor
|— Cliente1
Gipper
GipperOP9mo ago
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"?
Angius
Angius9mo ago
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 cliente
Gipper
GipperOP9mo ago
Yeah, 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
Angius
Angius9mo ago
Yeah, you can configure three profiles
Gipper
GipperOP9mo ago
Ok, now that all the projs are under same sln, how should I access my shared code?
Angius
Angius9mo ago
As long as the path is right This should work
Gipper
GipperOP9mo ago
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?
Angius
Angius9mo ago
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, yes
Gipper
GipperOP9mo ago
Ok, 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 ❤️
Angius
Angius9mo ago
Anytime :Ok:
Want results from more Discord servers?
Add your server