English 中文(简体)
Creating portable (non-installing) windows applications in C#
原标题:

I have a .net 3.5 application and i d like to make it portable. It s simple and runs perfectly, i ve sent the .EXE + .DLL s to some friends and it works as intended when running the exe with the .DLL s and the .ICO (that i have used in it) along in the same folder.

What i want is simple: creating a single EXE file that cares the dll s, image and whatever-i-want along with it without being a setup, and requiring no installation. (a.k.a portable)

I may consider migrating it to .net 2.0 if needed, i don t use any 3.5-only functionality, in fact, i m not really sure why i m using 3.5 (i m new at programming anyhow)

I d like any tips, links, or an explanation on how to do it, because it s really annoying sending .rar s to my friends and telling them to extract and run the .exe among all "weird files" as they call (besides, not everyone has extension display in folders, so it s a nightmare)

(I have searched in StackOverflow, and haven t found any questions that answer what i m asking, the only one that I found to be like it ended up in a discussion of framework availability in windows machines, language choosing and no good answers.)

最佳回答

You can use ILMerge to merge all the assemblies into your executable. I d expect your icon to already be an embedded resource - or you should at least be able to create it as such.

Targeting .NET 2.0 would make the application more widely portable in that it would just work on machines which only have .NET 2.0 installed - but I don t know what the proportions look like for 2.0 vs 3.5 deployment, and more importantly they may well not be the same as the proportions for deployment out of your target audience.

问题回答

You can add any data (assemblies, icons, etc) required by your application as resources or embedded files.

Either use the resource editor, or if you want to get your hands dirtier, you can add any file by just right clicking on the project in the solution explorer and doing an "add existing item", getting properties on the file and setting Build Aciton to "Embedded Resource".

Resources like Icons can just be used directly - as in DrawIcon(Properties.Resources.MyIcon)

Data files can be loaded using Application.GetManifestResource (and related methods) to get a stream to load from. For example, for an assembly, you can use Assembly.Load() directly from the manifest resource stream for your resource.

You could also use Xenocode to Virtualize Your Applications. Specifically Xenocode Postbuild for .NET.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签