C
C#15mo ago
Developful

❔ How does C#'s inclusion system work?

probably terrible title (again). basically what i'm asking is how does C# know which files to take and compile? in C++ this is done by the whole #include system, but C# has .csproj and that kinda stuff so does C# just take all the .cs files in the current directory? or does it expand its search until it finds a .csproj
3 Replies
Thinker
Thinker15mo ago
C# fundamentally works on .csproj files, they're the root of all C# projects. .cs files are located recursively from the root of the project, eg. all files located in the same folder as or a subfolder of the root will be included in the project As for how references work, when you add a Nuget package or project reference to a project, that is represented as a <ProjectReference> or <PackageReference> tag respectively in the csproj. When building a project (or more specifically restoring one), packages are pulled from available Nuget streams, most commonly from nuget.org, and the DLLs included into the binary output of the project (located in the bin folder). Project references work similarly, but they're just built in dependency order and the DLLs are again included into the binary output.
JakenVeina
JakenVeina15mo ago
the REAL magic, these days, is the "Sdk" setting on the root <Project> tag. That triggers a wole bunch of defaults to be included, depending on which SDK you picked, and buried in there is at least one .Build.props file that has the explicit includes for everything if you wanna look for yourself, you can find the core of this in "C:\Program Files\dotnet\sdk\7.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.props"
Accord
Accord15mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server