✅ using from another csproj
Currently i have 2 projects, an api app and a worker service app
And both use the same models.
Is there a way to put the models in a libary project and the 2 other projects include them? Without me needing to write the models twice per project?
7 Replies
Yes
And how would i do that, been searching online but cant find anything on that topic (mightve searched for the wrong things)
If you use Visual Studio Community then just right-click the solution and just create a new project. Add all the libraries you need and then start implementing the models, then right-click the projects and press add reference then just add it from shared project reference
and if i dont use vsstudio
1. use source control if you are not already doing so
2. create a C# library project
3. copy your shared code into the library and remove the duplicates currently in each project
4. add a project reference from your current projects to the new library project
if you are not using visual studio, then you can just edit the
.csproj
files to add project references. just add
where ...
is the relative pat to the .csproj
of your library project
you need to put that inside the <Project>
...</Project>
node in the .csproj
k this worked ❤️