There solyushen (Solution). It 4 project. One major, three minor. Main project uses a type of secondary and vice versa. In short they are all intertwined. How to compile all this into a single .EXE file for distribution?
UPD
Because it seems that not everyone understood what it was about, then try to supplement your question.
Here’s an example:
In Solution Explorer shows that in the Solution adds two project. App2 App1 project depends on the project. App1 added in the References.
It is also prescribed appropriate dependency.
If you simply compile the Solution, then the output will get two files – App2.exe and App1.dll. So that the application is working, for instance on another computer, you need to rewrite the two versions. Otherwise, a runtime error occurs. Something like Could not load file or assembly. The system can not find the file specified . So I would like to compile the application in such a way that in the end turned out, only one file – App2.exe. And in order to distribute this application it can be a single file. A file App1.dll was as if built into it.
Answer 1, Authority 100%
Possible solutions:
Merge assemblies one after compiling
Several assemblies can be glued to one after the compilation, using a tool ILMerge .
It has to NuGet.org :
Install-Package ilmerge
The format of the call:
ilmerge
/lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319 "
/ Lib: "C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ PublicAssemblies"
/ Targetplatform: v4
/out:out.dll mydll1.dll mydll2.dll
before using the path cost to fix expired.
The same tools – il-repack , Mono.Merge
Enable DLL to EXE as Embedded Resource to replace the standard loading mechanism:
- Add
bin \ someassembly.dll
in exe project through the Add Existing Item / arrow on the Add / Add as Link, set the Build Type = Embedded Resource - Add the project
someassembly
in the References. Align’s reference in the Copy Local = false – to avoid copying bin -
Edit
CurrentDomain_AssemblyResolve
:using system; using System.Reflection; using System.Windows.Forms; namespace WindowsFormsApplication7 { Static Class Program { [Stathed] Static Void Main () { AppDomain.CurrentDomain.AssemblyResolve + = CurrentDomain_AssemblyResolve; Application.enablevisualstyles (); Application.SetCompatibleTextRenderingDefault (False); Application.Run (New Form1 ()); } private static Assembly CurrentDomain_AssemblyResolve (object sender, ResolveEventArgs args) { var assemblyName = new AssemblyName (args.Name) .Name; if (assemblyName == "someassembly") { using (var stream = typeof (Program) .Assembly.GetManifestResourceStream ( "WindowsFormsApplication7." + AssemblyName + ".dll")) { byte [] assemblyData = new byte [stream.Length]; stream.Read (assemblyData, 0, assemblyData.Length); return Assembly.Load (assemblyData); } } ELSE. { RETURN NULL; } } } }
.
This is the minimum working example. If it does not work – run under the debugger. Most likely you did not guess with the resource name, and getmanifestresourcestream
returns NULL
. Make sure the type of Atem is set to Embedded Resource (and not just in Resource). You can view the names of all available resources right in debugger, call
typeof (Program) .Assembly.getmanifestresourcenems ()
The project entirely on Hithabe, on the example of SevenzipSharp: https://github.com/paShapash/sevenzipSharp-Embedded
Enabling assemblies in the form of resources, automatic option
Install the costura.fody via Nuget and get one EXE at the output.
& gt; PM & GT; Install-Package Costura.fody
Alternatives:
- Solution from VLAD – Compilation in NetModule with a subsequent merger
- Assembly through the addition of all sources in another big project – from @qwertiy
Answer 2, Authority 9%
for .NET 5.0 * There is a simpler, supported Microsoft solution: Single File Deployment .
You need to configure Publication . Go to Build → Publish, create a publication profile. Be sure to select a specific target runTime (for example, Windows 64 Bit), do not leave Portable.
You can also select Deployment Mode = Self-Contained, and all the .NET used to be added to the file, install the .NET Runtime on the user’s user computer (but the file size will grow significantly). You can also request a ReadyTorun compilation (that is, AOT).
everything!
* In fact, it should work with .NET Core 3.0, but I have not checked.
Answer 3, Authority 5%
I will correct myself, the small utility from Microsoft – Ilmerge will solve the problem. I will add that there is a good article on this topic
Answer 4, Authority 5%
There is also a crutch way: create a new project and add to it as existing all files with the code, then compile.