ILMerge and Visual Studio and PostEvent build - c#

Met a problem. VS2013 doesnt allow to merge files into same exe which created after build.
"$(SolutionDir)ILMerge\ILMerge.exe" "$(TargetPath)" "$(SolutionDir)..\Lib\Soft.dll" /out:"$(TargetPath)"
My idea was to merge built exe with 1 dll (uses in references) and to have the same exe filename.
I can do this without any problem apart of VisualStudio.
But i prefer to do merge exactly in post-build event, and do not change the exe filename.
Is there some workaround ?
PS. I dont want to have a dll in resources, because its used a lot, and its easy to have as usual in references

Related

Visual Studio, Copy Solution to Folder On Build

I'm looking for a way to add an extra build step which will create a backup copy of my entire solution. I want it to do this only if a file in the solution, or the entire solution itself, is not present in the destination folder or flashdrive directory. What would be the easiest way to achieve this? Preferably I would only want this to happen if a file is deemed "newer", and avoid the copy and replace if the file has not changed since the last backup.
You can do this with a batch file using
xcopy /D
which will copy only those files whose source time is newer than the destination time. Or robocopy.
This could recursively copy the entire directory, particular folders, or particular file types. If you're willing to launch your builds from the batch file itself (rather than within visual studio) the batch file has everything you need. Otherwise you might find Solution-wide pre-build event? useful for setting this up to work through Visual Studio. If you follow that process you should be able to take advantage of the Visual Studio Macros for Build Commands like $(SolutionPath).
If you need only those files actually contained in your projects then parsing the solution and project files may be necessary. The .NET framework provides some libraries to help parse solution or project files (SolutionParser). See
Parsing Visual Studio Solution files
That would be a bit of work, but you build a list of only those files contained in your projects and use with xcopy or robocopy.

How to create an .exe file with external .dll?

I've tried almost everything found on the net to solve this problem, but it just seems to not work!
I created a .exe file from a visual studio 2013 project using wpf. I want this file to create pdfs, so I added as references .dlls concerning itextsharp.
Everything works fine if I keep my .exe file in the same directory as itextsharp's .dlls. But when I try to run the .exe outside, the program crashes.
I've tried to use ILMerge, I read it is pretty good to merge .exe and .dll, but when I double-click one the newly-created .exe file nothing happens.
The command I wrote in my command window, once in the ILMerge folder, was:
ilmerge C:\Users\Utente\Desktop\PDFWriter.exe C:\Users\Utente\Desktop\itextsharp.dll /out:C:\Users\Utente\Desktop\merged.exe /target:winexe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5"
Thanks for your help!
Use Fody.Cosura project for merging. A lot nice to work with than ILMerge.
All you need to do is to install nuget package in your project:
PM> Install-Package Costura.Fody
And you are pretty much done. You can adjust the configuration, but that is not always required as just installing the package does the bulk for you.

Creating a "portable" .exe (without installer)

I've recently coded a little program to determine numbers in a picture and it is reliant on two libraries I've used. (DLLs)
Since my target computer is not allowed to install programs due to security reasons, I need to create a portable .exe.
.NET is installed on the target computer but for some reason VS still does not include the libraries I've used in the exe but instead creates an application folder with a setup.exe, some .DEPLOY files and an application manifest.
I am new to VS and .NET in general so this question could be easy to answer, but I'm asking since I've found nothing useful on StackOverflow neither on google.
You can simply build the application and copy your bin/Debug folder along, but that would still mean you need multiple files.
In order to merge all references into the executable, use ILMerge. Here is some help calling ILMerge.
Basically, after building, you should do something like this:
ilmerge /target:winexe /out:SelfContainedProgram.exe
Program.exe ClassLibrary1.dll ClassLibrary2.dll
There is just one file you need to send along.
One way to do this is to build your application in Release mode (You can pick from Debug or Release in the drop-down). Then go to C:\Projects\[ProjectName]\[ProjectName]\bin\Release (The location of your project folder may vary). You'll see a bunch of files but all you really need are the DLLs, executable, and the config if you used one. You won't have to do any setup if you keep the necessary files in the application's folder, just copy them all to a folder on the target computer, create a shortcut if you want then you're good to go.
You can just copy all your assemblies into any folder you want. Simply chose "Build" from within Visual Studio and copy the files from bin/debug to your destination-folder.
However you have to ensure that all (relative) paths (if existing) still work as you cannot be sure where the user of your program copies the files to.
One simple way could be to use 7zip Packager, it doesn't need any installer. However, VisualStudio method might be more reliable.
I encountered the same issue recently. ILMerge suggestion above is no longer supported. I found Fody.Costura as a modern replacement.

How to create a single executable file in Visual Studio 2008?

I've created a Windows Forms Application in Visual Studio 2008, .NET 3.5.
Now I want to finalize my project, i.e. to create a single .exe file which I can give to someone and he will be able to run it on his computer.
In my project files I found bin/Debug directory where I see a .exe file.
Can I just use this file as is, or I am missing some important finalizing procedure ?
Thanks !
You can just take the EXE as long as it has no dependencies. If there are any dll files in there, you need to include them (or use the ILMerge command line utility to combine them). You can, however, ignore any generated pdb or xml files.
As a side note, you should be compiling in release if you plan on deploying your project (the output will be in bin/Release)
You are not clear in you question. If your solutions output is just a single exe file, then Yes, you can give away the exe file in bin\debug.
But instead of bin\debug\ exe you must distribute the bin\Release\ exe which is meant for release purpose.
To make the ILMerge easier, use the GUI tool from codeplex at http://ilmergegui.codeplex.com/
If this is a commercial application, several commercial obfuscators allow creating a single exe.
In SetiSeeker response the link http://ilmergegui.codeplex.com/ is not reachable

Ways to deploying console applications in C#

I have a relatively complex console application which relies on several dlls. I would like to "ship" this in the best form. My preferred way would be an exe file with all dependencies embedded in it (not that big, about 800K). Another thing would be to just zip the contents of the "Debug" folder and make that available, but I'm not sure if everything will be available like that (will all dependencies be resolved just by zipping the debug folder?)
What reliable practices exist for deploying console apps written in C# using VisualStudio 2008?
If you just copy the Foo.exe, dlls and Foo.exe.config files, it's likely to be okay. Have a look at what else is in the debug folder though - you (probably) don't want to ship the .pdb files, or Foo.vshost.exe. Is there anything else? If you've got any items marked as Content which are copied to the output folder, you'll need those too.
You could use ilmerge to put all the dependencies into one exe file, but I'm somewhat leery of that approach - I'd stick with exe + dependency dlls.
You should look into setup projects in Visual Studio. They let you set up dependencies and include the DLLs you need. The end result is a setup.exe and an MSI installer.
Here's a walkthrough that should help.
OR you could use a self-extracting ZIP file. Package all the normal files up - .exe, .dll, .config, and anything else - into a zip file. Extract into a temp directory and set the run-on-extract program to be the actual console exe.
Create a setup project in VS08 and add the primary output of the console app project to it, this resolves the dependencies and packages them in a .msi
You can use wix installers to bundle it. For console application, exe + dependicies DLLs + nuget DLLs , zipping them is enough.

Categories