I want to split the components of my applications like:
Application A -> Component X <- Application B
without compiling Component X to a dll. When I include the .cs, Visual Studio copies it to the application directory. I don't want that. I want to include the file and then use a part of it, like开发者_StackOverflow社区 C's #define. For example if I have a ZIP library, I don't want to include the whole assembly if I need a decompression. What's the C# way to make this? Can I somehow tell VS to not copy the file and use #defines or maybe some method attributes?
An assembly is a single, complete file. If you want multiple assemblies which are only included as needed, you need to build them using multiple projects (one per assembly) and reference only the ones you want in the downstream projects you want.
Bigger question, however, is ... Why?
Don't create a problem where there isn't any.
Create a new dll, and MOVE .cs files that should be shared there. Build it, and have AppA and AppB reference and use that dll.
BTW, you can add reference from AppA to AppB, or from AppB to AppA, but not at the same time because it will create circular reference.
And if you want to stick to your idea, LINK your code files as Chris suggested, and use:
#if APPA
// code for AppA
#endif
To have pieces of code compile just in one application. Use project level #defines (project properties) to define APPA and APPB in their respective projects.
You can link to source files in Visual Studio, rather than copying them into in your project. Right click on the folder where you want to put the file, click "Add Existing Item", find the file that you want to add in the dialog, and before hitting Open, note the little down arrow next to the Open button. Click that, and click add as link.
Documentation here: http://msdn.microsoft.com/en-us/library/9f4t9t92(v=VS.100).aspx
Add Existing Item...
Browse to the file you want to include.
Instead of selecting "add", press the arrow to the right of the "Add" button and select "Link" in the drop down.
/B
May be you need Multifile Assembly?
精彩评论