Are .NET projects in Visual Studio always compiled into a single file?

This is one of those things that is so simple that no one ever goes out and talks about it in any of the textbooks I read.

I have created several standalone .NET applications, as well as several DLL-based plug-ins for other programs. I noticed that a project in Visual Studio, at least with Windows applications and class libraries, is compiled into a single file (EXE or DLL).

It's always like that? As for organizing a larger application, should I always think of projects in Visual Studio as matching a single file in the final program?

+7
visual-studio
source share
5 answers

Each project is compiled into one file. (Excluding website designs)

However, if you set the Action for any file in the project to "Always copy" or "Copy" if "Create", the project will copy this file to the output folder.
In addition, if the EXE project has an App.config file, it will also be copied to the output folder.

If your project refers to a DLL (whether it’s your own or someone else’s), which is not part of the main structure, it will copy this DLL to the project’s output folder, resulting in two files (although only one of them will contain code from the project itself)

In addition to the DLL and EXE, Visual Studio will also create a .pdb file containing debug symbols in the output folder. This file is used by the debugger and should not be distributed to your users. (If you do not want them to debug your code for you)

+3
source share

For your simple projects, yes, you always get one build for each project. However, if you upgrade to more off-the-shelf software, the answer is different. Say you want to deliver a DLL, but it contains text that should be displayed to the user. You will probably want to localize this text (provide the English and German versions, or even the English-English and British English versions [think program vs. program]). You put your text into resources and then compile these resources into so-called satellite assemblies. You will receive one satellite assembly for each region that you decide to support.

Here, quickly start the process of creating and using satellite assemblies: http://sanjaysainitech.blogspot.com/2007/08/satellite-assemblies.html

I see people talking about netmodules and ILMerge. I think that if you are worried about network modules, you are doing something wrong because you are not using the tools provided by Microsoft (or you ended up in the land of Mono, in which case you do not have tools from Microsoft). I did not use ILMerge, but after reading about it, I am not sure that I trust this. This person says it works fine except for WPF / XAML code; this person had problems accessing embedded resources after starting ILMerge; this person saw optimized code that could not be executed using the debugger after starting ILMerge. This is enough information to tell me that ILMerge is not a production-ready tool for all scenarios. A piece of development software figures out how you deploy it. If you want to deploy fewer builds, you should design your software this way, and not cheat on IL after you compile it. As the cartographers said: "Here are the dragons."

+2
source share

An example of how to create several modules and associate a theme with one dll:

csc /t:module RarelyUsedTypes.cs csc /out:AllTypes.dll /t:library /addmodule:RarelyUsedTypes.netmodule AllTypes.cs 

For more information, see Richter's CLR book via C # .

You can automate this process for Visual Studio.

For each of your projects, create a netmodule or assembly and compile / combine them all into one assembly.

The first alternative. This was suggested by Jay R. Wren :

This is a nice hack, but with CSC and VBC that support the /target:module and /addmodule , you could do this without ILMerge using a shell script or make a file.

Visual Studio does not support the "netmodule" type, but MSBuild does.

Add the VB project to your solution. Unload the project and edit the project file.

Change OutputType to module:

 <OutputType>module</OutputType> 

Instead of adding a link to the desired project, add a module. Unfortunately, again VStudio does not work here, but MSBUILD works fine. Unload the project and edit the project file. Add a group of elements with AddModules include directives.

 <ItemGroup><AddModules Include="..\VbXml\bin\Debug\VbXml.netmodule" /></ItemGroup> 

This will tell msbuild to tell CSC to use the /addmodule directives, as well as the reference group that Studio controls.

The main disadvantage: there is no Visual Studio Intellisense for the added module. We already have links, it’s too bad that we don’t have modules. [UPDATE: As Arc-kun noted, Visual Studio can link to .netmodule projects and have Intellisense. Just add a link to the project before changing the type of output.]

SharpDevelop has a first step, but a second step - the Add Module GUI has been opened as a low priority item with SD 2.0.

The second alternative. This great article (written by Scott Hanselman) describes how to automatically build assemblies using Visual Studio. It does , gives you IntelliSense support , unlike the first alternative .

+2
source share

For Visual Studio, yes. Search the netmodule online and you will find the documentation you are looking for. I happened to meet them today, when we were going to collect several projects into one DLL.

MSDN: http://msdn.microsoft.com/en-us/library/226t7yxe(VS.80).aspx

+1
source share

Not necessary. If your project has culture-oriented resources, they are usually assembled in separate assemblies (dlls). In addition, ASP.Net projects are not assembled into a single assembly; you will always have either aspx / ascx files, or their equivalent markers, left separately from the compiled code.

+1
source share

All Articles