Filehelpers Publish Release file without need for DLL - c#

this might be a bit of a noob question..
I've coded a simple file conversion app in C Sharp (.net 4, VS2010) that uses the Filehelpers library. I've got a reference to the library in my project references. When I publish the project in Release mode, it outputs the Filehelpers.dll file with the executable together, and the executable won't work unless it's in the same folder as the DLL.
I tried setting Copy Local to False, but it still doesn't work. Is there any way to package the library as part of the exe file?? This is a very simple app which is meant to be distributed easily and having this required Dll floating around is a huge downside.
thanks
T
Got it working after some fiddling with ILmerge not running on .net v4. Here is my command for future thread visitors:
ILMerge /targetplatform:v4,C:\windows\microsoft.net\framework\v4.0.30319 /out:merged.exe /log Original.exe FileHelepers.dll

You may want to look in to your project property settings where you can custom copy files where ever you want post build if you are looking to move files around after the build. If you are looking to include a .dll in your .exe look here

Related

C# .NET 6.0 - exe only?

Hey I switched from NET Framework 4.8 to .NET 6.0
When I build my file it outputs the build.exe (130kb) and an build.dll (2.3mb).
So it looks like the exe is using the dll to run as the dll has the source code inside and the .exe doesn't.
Is it possible to build an .exe only without the dll?
I tried to use a Costura Fody an resource embedder but that didn't work.
Edit:
I was able to use the "publish" feature to create a self contained exe but the file size increased from 3mb to an 180mb exe... Is there any other method?
You probably want a single file framework dependent deployment and not "self contained". This way you would not have to include all the framework file in your deployment package, instead the computer would have to have the framework already installed. To do this, change deployment mode in the deployment settings from self contained to framework dependent. See Single file deployment
You might also check out "trimming" to remove unneeded dependencies, since this should significantly reduce the size of a self contained application.
Your observation is right.
The .exe file of a .NET core app is only a stub loader. The actual code is in the .dll file. For the application project, you now have both an application.dll and an application.exe.
Unless you use any of the options you mentioned (deploy as single file), I don't think there's a way around this.

dlls disappear when performing an incremental build

I am compiling a solution using Visual Studio 2019. This solution has two projects, we can call them Common and Program. Program depends on Common and Common depends on the NuGet packages LibVLCSharp, LibVLCSharp.WPF and VideoLAN.LibVLC.Windows.
If I clean and then build Program, everything is fine: the dlls are correctly copied in bin/Debug or bin/Release. But if I make any change to Program and compile it without cleaning it, the dlls relative to VLC disappear.
What can be the reason for the dlls to disappear?
In the visual studio UI I do not see the commands it is running when I compile the project. How can I debug it?
It seems that you are referencing VideoLAN.LibVLC.Windows on your Common project rather than in your Program project. This is not a scenario that we support.
I wrote this explanation about which project you should install LibVLC in.
In short, you should install the LibVLC package only into your application project, because we insert a build step that copies the files to the Output Folder of your project.
If you reference the LibVLC project in the Common project, there is no way we can copy the files to the Program project, because it is not known by MSBuild. You would then have to tell MSBuild to copy those files from Common/bin/... to Project/bin/..., but trust me, you don't want to mess with MSBuild.
EDIT: That doesn't mean that you can't use LibVLCSharp in your Common project. You can reference the LibVLCSharp packages in your Common project, because it only depends on VideoLAN.LibVLC.Windows at runtime.

How create a .net standard and .net framework self-contained build?

My goal is to create a build output that acts as portable version of my application, containing the non-framework dependencies (nuget + projects) directly as dlls.
This demonstrates the solution and the four projects contained:
You can see the libraries are .net standard 2.0 while a console app (to run / debug some code) is using .net framework 4.7.2 (because we have some .net framework apps in use around here). The arrows in the image show the references that have been set.
Parts of the the libraries (not console app) might be imported into MS sql server in the future; these imports usually pick up all dependencies from the same folder if available (which is the reason for a self-contained output).
Problem A: Running the code on linux/mono
Using jetbrains rider to open the solution, build + restore packages will work without problems.
Running the console app will work to some extend (e.g. loading data from SQL) until it fails when calling some code that makes use of BouncyCastle (dll not found exception).
Looking at the build output shows three .dll files of my lib-projects along with the .exe file of the console-app plus all the .pdb files AND additionally the System.Data.SqlClient.dll.
Seems that might be the reason my sql code worked.
Problem B: Running the code on win10, .net framework / core installed
Using VS / rider made no difference here, opened the solution, restored packages + build without problems. Running the console-app fails earlier than before: this time it was unable to find the Syste.Data.SqlClient.dll.
Checking the build folder shows my three lib-dlls and the .exe including the .pdb files, nothing else.
To my understanding, the files have to be either in GAC or inside the same folder for them to be found. It seems when a .net standard library dependency includes nuget-packages, something is having troubling either loading them into GAC or at least copying them to the build directory (which is outdated I guess).
So even if my approach (having a portable-ish / self-contained version of my app) might be uncommon or even stupid, I would have thought that just running this code on the dev-machine should work fine.
Problem C: Including dependencies in the build output
According to information I found here, the <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> property can be used to have dependencies being copied to the build directory.
And while this seems to copy too many files (tried excluding some according to docs) it does indeed copy the .dll files for a complete package when building the ExchangeIntegration project (.net standard 2.0).
Looking into accomplishing the same for .net framework .csproj projects yielded mixed results. I was playing around with the copy-local setting and stumbled across similar problems when creating nuget packages and using .targets files but had no success.
About the specific libraries used
I'm more interested in learning the right concept to handle this, it's not really about whether or not it makes sense to import Newtonsoft.Json into MS sql server.
I feel I'm fundamentally missing something; maybe the output type library is not correct for my goal or maybe I'm mixing problematic .net versions, although I did a quick check and it seems ok.
How can I get a .net framework (console-app) build that contains all non-framework dependencies (e.g. nuget) AND an separate .net standard (library) build, that also contains all non-framework dependencies?
EDIT: Adding all nuget packages to the top tier project (console-app in my example) seems to work around the problem, code executes without problems. I'm still waiting for a proper solution.
EDIT2: Added mono/msbuild version used under arch: 16.4

Open SQLite database in C# WITHOUT installing anything

I am writing a portable C# application designed to be run as a single executable file on a USB. It needs to be able to extract some data from a SQLite database. Because it is portable, installing something locally is not an option. I have seen questions like this and this but they require installing third party software.
How can I get this data without losing the portability?
Edit:
I tried using the System.Data.SQLite NuGet package. It works, but then suddenly I have gone from a single executable file to an executable, a .dll and two additional folders. I can deal (albeit unhappily) with a single dll addition, but that is too much.
You have two options:
Use IlMerge.
Embed an assembly as a resource.
Well I think is about as good as it is going to get: I got it down to a single executable and a single dll file.
To do this I changed the architecture of the executable from Any CPU to x86 only, and then installed the "System.Data.SQLite.x86" NuGet package.
If anyone knows how to keep the capability but in a single executable file, I would be very grateful.
Try Costura.Fody (browse on Nuget Packages), i usually use this one and it packs everything in a single exe, i believe it should work.

How do you create a standalone exe in Visual Studio? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Embedding DLLs in a compiled executable
I want to compile my C# application to a single exe file. The problem is that my project depends on many other projects resulting in many dlls in the Release folder when I compile it. Is there any way to just make an exe with these dlls included?
Note: It does not need to be independent from the .NET framework. I assume that anyone using this exe will have that installed.
.NET ships with a tool called ILMerge where multiple assemblies can be packaged together into a single file. You would use it like:
ilmerge /target:winexe /out:myoneexecutable.exe Foo.exe Bar1.dll Bar2.dll
ILMerge is one option, but it can't merge WPF assemblies. You can embed assemblies as resources and dynamically load them. See this Richter article.
I believe the closest you will get to being able to compile to a single executable is using Visual Studio's Setup Project functionality / Wizards to generate a standard MSI package which you can then use to distribute your application.
There may well be 3rd party tools available that allow you to condense everything down into one file, however. But I don't believe this will gain you anything over the standard MSI approach - indeed, it's just an extra manual step in the build process which you don't strictly need.

Categories