[.net] C# external file references?

Started by
4 comments, last by benryves 16 years, 6 months ago
Is there a way to reference external files in the same way as "include" in C++ and "uses" in pascal? Where I work, we currently use Delphi (visual pascal), and have Uses for a lot of common units that are used in multiple programs. I know that in C# you can create libraries and reference the DLLs, but is there a way to include them inside the same project without having to make it as its own external thing? I'd need to reference it as either just a file name, or as a relative file (such at "..\..\MyFile.cs"). Thanks!
Advertisement
Just include it in the build. If you are using Visual C#, just add the file to the project. Otherwise just make sure it builds with the source for the project and you can access it. The only other option is to build a DLL and reference that.
Why?

C# doesn't require lexical visibility of symbols the way C++ does. That is, if in file Foo.cs you define type Foo, and in Bar.cs you define type Bar, Foo and Bar can "see" eachother and you can use them freely in either file. So long as both files are part of the same project.
Ok, I understand that much, I've seen it done with the DX managed SDK tutorials. But how exactly do you go about doing it? We are using Visual Studio 2005 (team edition or something like that). I know when i click to add a reference it requires a dll or smiliar (yes, I know now that this isn't what i'm trying to do). How would I add a file to the project, and only specify a relative path? Do I click ...->Add existing item.. and type in the non-literal path and name? And can I simply type in a file name, and have a project-level search path specified?

Thanks for your quick responses!
Do add existing file and then just browse to the file. No need to manually type in anything.
Note that hitting add will copy the existing file into your project.



If you don't want this, click the arrow to the right of the "Add" button and select "Add As Link", which will keep the original file in the same place.

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

This topic is closed to new replies.

Advertisement