Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying C# (.NET 2.0) application as a portable application?

Is it possible to deploy a .NET 2.0 application as a portable executable? So that my program can be ran in a Flash Disk without the .NET Framework 2.0 installed in the target machine. Or maybe is it possible to distribute my program with the required .NET DLLs, so that no framework installation is necessary?

I know that there are some alternative tools to turn my .NET exe into a single native executable like RemoteSoft Salamander, Xenocode Postbuild, and Thinstall, but unfortunately I can't afford one.

I also tried to embed the dependencies with Mono's mkbundle, but it messed my program up =\ (no XP visual style, broke some controls and its functionality)

Any kind of help would be appreciated :)

Thanks.

fyi: my IDE is Microsoft Visual C# 2008 Express Edition with .NET Framework 2.0 as the target framework.

like image 707
Yana D. Nugraha Avatar asked Aug 08 '09 07:08

Yana D. Nugraha


People also ask

What is deployment in C#?

Framework-dependent deployment. Deploying a framework-dependent deployment with no third-party dependencies simply involves building, testing, and publishing the app. A simple example written in C# illustrates the process. Create the project. Select File > New > Project.

What is deploy in Visual Studio?

When you deploy a project or solution in Visual Studio, the assemblies are automatically built and deployed into the specified application.

What is the difference between deploying and publishing an application?

Deployment: It is a process of deploying the pre compiled dll's to the IIS server. Publish: It is a process of creating precompiled dll's. Web Hosting: It is similar to the process of deployment of a website. Deployment: It is a process of deploying the pre compiled dll's to the IIS server.


4 Answers

Well, other than things like Salamander and Thinstall (now VMWare ThinApp) you would have to have .NET installed if you really want to run .NET.

It may be possible to run Mono without actually installing it (not statically linking your program, but including Mono on the flash drive). I suspect it would be tricky though, as you'd have to tell the runtime about things like the GAC location.

I can't see anything in the Mono FAQ about this, but you might want to ping a Mono mailing list - it sounds like a potentially interesting and useful thing to be able to do.

like image 187
Jon Skeet Avatar answered Oct 04 '22 19:10

Jon Skeet


No; you need either the framework installed, or the tools like you have mentioned.

You could potentially look at mono's new static linker, but that is about it...

like image 23
Marc Gravell Avatar answered Oct 04 '22 18:10

Marc Gravell


I have not tried this myself but here's the procedure:

  • Make a C# project.
  • In Solution Explorer, inside your project, there is a line "Reference". Click the plus near it. Now you can see all the dependencies of your project. Delete all references that aren't used (delete, and try to run/build. If it is possible to do it, that it is unused. If there is an error, return it by adding it (right mouse click, "Add Reference")).
  • For each reference, go to Properties, and in the property "Copy Local" choose "True". For each Image, Icon... make like to the referenced.
  • Rebuild you project. Now in your Build/Release folder (inside bin) you will see many dll files. Those files have the information of every resource.
  • Copy all the files in the folder (from step number 4) into a new folder.
  • Go to the folder: "\Microsoft.Net\Framework\" and copy the file "mscrolib.dll" to the new folder from step 5. If you don't find this file, you can always make a search in the Hard Drive which contains Windows folder.
  • Now your app is portable (with the whole folder content).

-- Source: http://www.codeproject.com/Tips/392308/Csharp-Portable-Exe-File

like image 38
aschoenebeck Avatar answered Oct 04 '22 17:10

aschoenebeck


Well Thinstall is very expensive and it doesn't work in all situations. If you want to run your app without .Net installed you might run into trouble although there are tools that do that Xenocode has a tool that can do this for you and it's cheaper than thinstall.

But if you ask my opinion it's a bad idea to use them. Better convince your target market to install .Net 2 (Which is pretty much universal these days), and then pack all of your library files into one file using a cheaper Obfuscator like tool (There's a good one from Smartassembly.)

I've used Thinstall for a long time, and I've worked on this technology a lot, so I am not shooting off without experience.

like image 43
Cyril Gupta Avatar answered Oct 04 '22 19:10

Cyril Gupta