How to split an assembly file(.dll file) into many assembly files - c#

I am building a projects by C#. It contains many folders, each folder represents for a function. Now I want to make a .dll file for each of them. Is there any tools can help me to do it?
And after that I want to merge them together. Is there any solution for me to do it?
Thank you,

You are searching for modules in .NET. Where module is a file (not a DLL) with self sufficient (from structure perspective) content which can be read and executed by CLR virtual machine into machine code.
Read this for detailed explanation: How to: Build a Multifile Assembly
You will need to do a little command line execution, no direct visual studio support, afaik.

You might want to move from a folder structure to a project structure. Each project will automatically have its own .dll file. Then you can have a central project that has references to each of them.
It would be a good idea to group together certain code files by project for other reasons too. Suppose you have a lot of extension methods that could easily be re-used for other coding projects. You might separate these classes into a Util project / namespace for easy re-use and access across other projects.

Related

How to share cs code among multiple solutions?

I'm using VS 2017 and I have a number of Utility class files (NetworkLib.cs, ImageLib.cs, etc) that I find myself constantly having to duplicate over and over again when creating new solutions.
Normally, I would just end up creating a dedicated separate solution, NetworkLib.csproj, compiling these into DLL files, and then adding a DLL reference whenever I need them in a new solution, but this isn't ideal for me.
I want to be able to use these in a shared library sense across multiple solution files but also when debugging if I step-into some function NetworkLib.Post() the debugger should step into the appropriate CS files. Additionally, if I make some changes to NetworkLib.cs from Solution1, all other solutions should pick it up on rebuilding.
I've given thought to creating a standalone Utility solution with a NetworkLib csproj, and then adding the project csproj as an existing project to each solution, but not sure if that's a good approach.
I also just read about the "Shared Project" but when I created it (in its own standalone solution) I can't seem to import it into other solutions. When I look in "Shared Projects" tab it just states "No Items Found".
Normally, I would just end up creating a dedicated separate solution,
NetworkLib.csproj, compiling these into DLL files, and then adding a
DLL reference whenever I need them in a new solution
That's the solution. You should publish your shared DLLs into a "shared" folder, somewhere on your desktop/server/network/... and reference these DLLs in your solutions. If you rebuild the shared library, every solution referencing it will automatically use the new version.
To debug external libs, you will need the .pdb file generated alongside with the .dll file. Look here for complete answer : How to debug external class library projects in visual studio?
Use "Linked items" - where the .csproj project has a soft reference to a *.cs file (or other file type) located anywhere in the filesystem, including outside of your source-control workspace or even a network share - just so long as the file exists your project will build. Use this technique judiciously because it's easy to break CI/CD systems for obvious reasons.
"How to: Add Existing Items to a Project": https://msdn.microsoft.com/en-us/library/9f4t9t92(v=vs.100).aspx

Why does VS2010 allow for the concept of "include in project"?

I'm still learning the basics of how VS2010 sees the world. Apparently, you can optionally "include" a file in a project. I'm a bit confused by this: If a file is version-controlled, AND the file is within the project directory, shouldn't it implicitly be "included" in the project? If not, what's the use case where a version-controlled file in the project directory should NOT be included in the project?
=== Addition ===
Based on the answers I've gotten so far, maybe I should rephrased my question: What does it mean for a file to be "included" in a project?
A project needs to know about files in order for compilation and distribution to occur. Just because you have a file that's under source-control, doesn't mean that it will be compiled if the project is unaware of it.
Also, you may want to include files as part of a distribution package. We do this quite often for our web projects that we distribute using web app gallery.
Conversely, you could have documentation or sql scripts that you version control, but do not want them to be part of the project.
EDIT: In answer to your update, what it means for a file to be included in a project is that the file is actually added to the .csproj or .vbproj file and will be used during compilation and/or distribution. VS does differentiate if the file is Content or if it needs to Compile it. This can be seen by clicking on the file in Solution Explorer and looking at the Build Action property.
No, you don't want random files that happen to be in the project directory included in source control.
We do sometimes put documentation (pdfs) or drawings/schematics in the project folder and under version control but you don't need them inside the visual studio project (especially when they are not being distributed because they are for internal use only).
Excluding the file from your project can be useful if the file is related to the project but not necessarily needed in the solution.
Example
If I need some test XML for an application that i'm writing; that is designed to normally be pulling this from a WCF service, it can be useful to keep that file in the directory for a development environment where I use IO to get the XML for testing, but I don't necessarily want it in my solution which is source controlled.
When you exclude a file from a project is no longer compiled or embedded, then when you want to include it again you can do so without having lost your settings.
If you e.g. copy a file (containing a helpful class which want to have in your project) into a folder of your project, then you will see ... nothing. You have to check the option "Show all files" of the solution explorer and the copied file can be seen, but it is still "greyed out". No you can choose the menuitem Include in project and that file will be integrated in your project and a pending change (add) for your source control is added too. Visual Studio doesn't include all files it can find in the project folder automatically to the project - and that is a good feature.
One of my colleagues explained to me a scenario in which a version-controlled file should NOT be part of the project. Here's the idea:
A developer writes some new code.
The code is experimental, and not intended to be part of the normal build.
The easiest way to exclude the file from the build is to NOT include it in the project, but still version-control it.
This way, the file can be shared with other developers, but not break the build.

VS2010 Building Solution - Add Files to BIN folder

We have a solution comprising of a windows application and various library files. Not all of the library files are referenced by the main windows application however we would like to have all the library files included in the output build folder "bin".
Obviously one solution is to simply reference every single library from the Windows application however we would like to avoid any unnecessary referencing.
How can we include additional files into our build folder?
This is a C# project.
You can always use the pre-build or post-build events in the project settings to copy the additional files.
You can do this simply by doing a bunch of copy source target, or you could even be fancy and write an nmake file. You do have to maintain the list of source files however...
Edit:
One other thought. Your assumption is that this is "unnecessary referencing". However, if your application depends on these assemblies to run, whether or not they are compile time references, then don't these dependencies become "necessary" references? In that case, isn't adding them as references and letting Studio's build system work for you the best (and simplest) approach?
The solution was to change the build location for all "libraries" within the solution to the main output "bin" location. The main Windows application only references the libraries that it depends upon however all the libraries are built to the one "common" location.
Thanks to Nader Shirazie for help with this question.

Adding a dll file to a C# project

It's a beginners question, but...
Image of dll reference and dll included in project file http://a3.vox.com/6a00c2251e5b66549d00e398ca81eb0003-pi
If you look at the image above, there is the "Bass.Net" dll added as reference and also directly as file in the project.
Can someone tell me what's the point of doing that?
No reason, really. It could be that Visual Studio is set to display files not in the project (hard to tell from the picture) and the dll's happen to be in the main directory. The text is pretty clear that the extra files are
bass.dll
bassenc.dll
lame.exe
The .net one happens to be with the others in the same directory and you need to add it as a reference.
Within Windows, a DLL is a dynamic link library, which packages a set of programmatic functionality together. In this example, bass.dll exposes the features and functionality relevant to audio processing through this file (and any files it depends on). In order to use this functionality, you need the reference in the solution, so that Visual Studio can link it at compile time. The DLL will then typically be copied to your output directory when the application is built.
That's all that is necessary to get the code to work properly, the rest is really just preference or convention. Some people prefer to have all the files that exist in the project directory in the solution, so that the Solution Explorer reflects the file system. Typically you will want to have libraries your application depends on somewhere in your solution directory hierarchy so that the entire application is packaged together (making source code control use easier, for instance). You won't want to put this library in the BIN directory or any directory that Visual Studio generates, though, to avoid accidental deletions. In any event, having the reference is the important part, the file being in the project or solution is not necessary.
Typically, you'll want to keep external libraries out of your source directories, though, so I wouldn't actually recommend this structure. I tend to use a structure like this, but, again, this is all preference:
Source: Source code and project files
Libraries: DLLs
Support: Miscellaneous code or projects, but not actually part of the application (perhaps deployment scripts)
Having those in your project and output directory allows the final executing code to reference them without any issues running on different machines.
It sounds as it they put the reference dlls in the project directory, reference them from there, and also include them in the project. That way, when the project directory is copied, the reference dll will be copied with it. Additionally, if the reference dll is missing, the project will complain in Visual Studio.
If an assembly (Bass.Net.dll in your case) contains classes you want to use, you must add a reference to that assembly to your project.
No point the best thing to do is get all your dependenicies and store them in a seperate folder and only reference them do not copy them to your solution ;)
It's really hard to guess why someone else did something, but if I really had to guess, I'ld say that the guy thought to embed the necessary dlls as resources to be sure it was availale to the application. I have seen this technique used to embed fonts or sounds and am not sure if it works at all with dlls; but it's just a guess.
Of course the best way to be sure the files were available would have been to create a deployment project, with Visual Studio or some other installation tool loke Wise or InnoSetup, just to name a few.
This actually might be a good idea in a lot of circumstances. In my opinion their are 3 types of dependencies
Assemblies from the .Net standard library. Never include those locally.
Assemblies that you expect other developers to install as part of an MSI or exe setup package. This usually means their strongly signed and have a copy in the GAC.
Assemblies that you don't expect other developers to install via an MSI or exe installer. Maybe because you have a third party or in house library not in the GAC.
In the third case, the simplest thing to do is store a copy of the DLL in the source repo.

Referencing resource files from multiple projects in a solution

I am working on localization for a asp.net application that consists of several projects.
For this, there are some strings that are used in several of these projects. Naturally, I would prefer to have only one copy of the resource file in each project.
Since the resource files don't have an namespace (at least as far as I can tell), they can't be accessed like regular classes.
Is there any way to reference resx files in another project, within the same solution?
You can just create a class library project, add a resource file there, and then refer to that assembly for common resources.
I have used this solution before to share a assembley info.cs file across all projects in a solution I would presume the same would work fro a resource file.
Create a linked file to each individual project/class library. There will be only one copy and every project will have a reference to the code via a linked file at compile time. Its a very elegant solution to solve shared non public resources without duplicating code.
<Compile Include="path to shared file usually relative">
<Link>filename for Visual Studio To Dispaly.resx</Link>
</Compile>
add that code to the complile item group of a csproj file then replace the paths with your actual paths to the resx files and you sould be able to open them.
Once you have done this for one project file you should be able to employ the copy & paste the linked file to other projects without having to hack the csproj.
Some useful advice on how to manage a situation like this is available here:
http://www.codeproject.com/KB/dotnet/Localization.aspx

Categories

Resources