I have a installer app with a embedded .resx file with some information, like server name, port, password etc...
I have to generate this installer (this process is automated, and is done through our website) for each customer. This is working fine
I use ildasm for disassembler and replace the resx file, and then I use ilasm to make .exe again.
But after this process the .exe lost our icon, putting the default one in it's place.
I cannot find a way to change the default icon.
Thanks
You are missing out on a fairly obscure detail in a C# program. The executable the compiler generates also contains unmanaged resources. Required because Windows doesn't know anything about managed resources. This is something you can see with Visual Studio. Use File + Open + File and select a .exe generated by the C# compiler. RTM edition required, it doesn't work for Express.
You'll see at least 3 nodes for your program:
RT_MANIFEST contains the manifest for the executable. Very important on later Windows versions, it declares the program compatible with UAC. It prevents Windows from treating your program like an earlier Windows program that needs to be lied to when it does UAC verboten things like trying to write files to protected directories and trying to create registry keys in HKLM. The content of the manifest is a default one in most programs, you can get a custom one with the "Application Manifest File" project item template.
"Version" contains the version resource for the executable. It contains the info you see when you look at the properties of the executable with Windows Explorer. Its content is auto-generated from the [assembly:] attributes in your AssemblyInfo.cs source code file.
"Icon" contains the icon resource for your program. The one you don't have anymore.
You'll need to use the /resource option for ilasm.exe to embed those unmanaged resources into the patched executable. That requires a .res file, the compiled version of the unmanaged resources, produced by the rc.exe Windows SDK tool. Note how this is also exposed in the Project + Properties, Application tab, Resource file radio button.
You cannot ignore this requirement, you can live without the Icon resource but not the manifest, especially not in an installer program. Getting the .res file out of the original executable is going to be difficult, fairly sure that ildasm.exe doesn't support decompiling it. If a tool like Resource Hacker doesn't do it then you'll need to create a .res file for your program. Or review the wisdom of using ildasm.exe to do what you wanted to do.
Related
I'm trying this again, since yesterday my question drew no attention, and I'm guessing it was due to the lack of a well worded explanation.
When I build my WPF application, with the "Embed manifest with default settings" option checked, my AssemblyInfo.cs version info is embedded inside the output .EXE, and right-clicking the .EXE and checking properties shows that. I'm wondering how and at what point, does the compiler embed that data into my .EXE?
I ask because I recently had to create my own .res file to embed multiple icons into my .EXE with appropriate indexes. The problem with that is you need to select the "Resource File" instead of "Embed manifest with default settings option;" so you lose your AssemblyInfo version information and have to update and rebuild your .res file every time you do a release.
In short, I'm trying to find a way to compile my own .res file that uses my AssemblyInfo.cs version information and is automatically embedded for every build (my versions contain * definitions), so I don't have to worry about remembering to update my .rc and compile for the .res.
I'm compiling C# code using CodeDom. Even when there are no resources specified, it still compiles a Win32Resource called "VERSIONINFO". I know I can remove it with BeginUpdateResource after it is compiled, but that will leave "PADDINGXXPADDINGXX" in the file, which I don't want. Is there a way to compile C# code to .exe without any resources?
Fretting about this is actually fairly troublesome. The EXE doesn't just contain the VERSIONINFO resource, it also has a manifest. Best way to see it is open the EXE in Visual Studio with File + Open + File. The manifest is under the RT_MANIFEST node.
It is important because it declares your program to be UAC compatible. Without it, Windows treats it like a legacy Windows app. Which some pretty unpredictable behavior, remapping file and registry access to isolated storage.
You can get what you want. Create an empty .rc text file in Notepad (not Visual Studio) and compile it with rc.exe to a .res file. Use /win32manifest in your CompilerOptions to force the compiler to use it so that it omits the auto-generated native resources.
I've built against the release profile and this creates an executable build within the release directory in my project.
How do I best distribute to clients from this executable? There are a lot of files within this folder which don't appear when installed through the installer, such as the mainifest and one called application.exe.xml (which is confusing when Windows hides the extension in Windows Explorer).
Are these all necessary? Can I just send the executable? Or will I need to send with all the files? Is there a way to build without all these files?
You must send the EXE file and any DLL file that you reference locally. If you use COM references and the like, you need to register them during the installation. The same thing for the GAC I think, but I haven't used that for stand-alone applications myself.
The application.exe.config file contains the application settings (a copy of app.config). If you don't use settings or the user doesn't typically care about them, you can omit the file, and it will use the default values you built the application with.
The vshost files are not needed (if you have them). They are used by Visual Studio's debugger. The .pdb files contain debug data used to facilitate DLL file to source matching. Unless you plan on attaching a debugger to the application, there is no point sending those.
Usually, in an XCopy deployment you have to deploy (literally copy all files deployment with no setup/installer program) the content of the output folder (like debug or release) without:
*.pdb - debug symbols
*.xml - xml documentation
?vshost? - Visual Studio hosting files
In fact, it anyway also depends on your specific application. As a developer, you need to know what you are producing; in case you are using an xml file which is not the result of the .NET documentation compiler, but a static file copied in the output folder, then do not forget to deploy it.
A last note: developers usually disable the option to hide file extensions in Windows Explorer ;-)
You need to understand what an installer does or why an installer is important.
An installer takes care of the basic environment. The installer can carry dependent assemblies/modules along with the application. It can also check if you need something before you run, like .NET on the target machine. It can also create the shortcuts on the desktop or start menu. Plus it also provides adequate options on the target machine to uninstall it.
If you wish to ship the executable alone, you might miss out some assemblies that the executable depends on. The target machine may or may not have the correct .NET version installed.
Use the program: HM NIS EDIT from HM Soft.
Build your project
Run NIS EDIT
Make a new script from the wizard (Ctrl + W)
Run all the steps
Select all the .dll and .exe files
Build a setup file
I have created a application with localization using visual studio 2008 and .net compact framework 3.5 on windows mobile 6.1.
To achieve localization, I have used many resource file for this, one for each langauge :
StringResources.de-DE.resx
StringResources.es-ES.resx
StringResources.en-GB.resx
StringResources.fr-FR.resx
StringResources.nl-NL.resx
I also have a StringResources.resx file with default strings for fallback in case other culture not supported by my app is chosen.
I have also created a .cab file by using a "SmartDeviceCabProject" (vdproj type) to perform installation of this application on the device. (using msdn.microsoft.com/en-us/library/aa446504.aspx)
Here is the problem that I am facing:
When I change the culture to anything other than the nl-NL, I always get default strings.
Please also note that when I copy paste the "bin" folder of the application into the device, all culture strings are seen. Only when application is installed via the cab file that the problem occurs.
Also if i remove the StringResources.nl-NL.resx file and only have
StringResources.de-DE.resx
StringResources.es-ES.resx
StringResources.en-GB.resx
StringResources.fr-FR.resx
as the culture specific resources and recreate the cab file, now see that when I change the culture to anything other than the fr-FR, I always get default strings. So only the last culture file is effective always.
Just to be sure I diffed the dlls that were installed in each of the culture folders via the cab file on the device :
de-DE\Application.StringResources.dll
es-ES\Application.StringResources.dll
en-GB\Application.StringResources.dll
fr-FR\Application.StringResources.dll
nl-NL\Application.StringResources.dll
Strangely I found all the dlls are exact same. However if I diff the dlls present in the "bin" folder, they are found to be different.
Thus I believe that the .cab file build is causing the same DLL to be copied to each folder.
With the above explanation in mind, please help me with :
**1. What do I do to make the cab file install the proper DLLs to the folders?
Is there any other way to place the correct dlls?
IS there any other way to achieve localization?**
This problem is registered as a bug in WizCab.exe: Smart Device CAB Project includes wrong localized resources.
I have found that the best way around the problem is to:
Add post-build events to the projects with localized resources that copies the resources files to unique (file) names:
copy "$(TargetDir)sv\$(TargetName).resources.dll" "$(TargetDir)sv\sv_$(TargetName).resources.dll"
for each present language.
perform a build and overwrite these unique resource files with an empty file - otherwise the visual studio GUI will not allow you to rename (step 4) the added files.
Add the copied localized assemblies as files (right click on .cab-project and choose "View" -> "File System") under "Application Folder" to the correct localization folders instead of using references to project output.
Rename the added assemblies in the "File System view" back to their original names ("YourProject.resources.dll".)
Not very nice but it works.
I'm publishing my wpf application using ClickOnce, however i also want to obfuscate it.
I am publishing my application to a local folder, obfuscating it, then resigning it using mageui and then uploading it to my web server.
The problem is, I can't seem to define my executable as an entry point, every time i select it, it will default back to an empty file type.
The weird thing is, this happens even if i don't obfuscate my assembly and try to resign it as is. I can define other dlls I've referenced as entry points (which isn't their use of course), but not the executable that starts my application.
any suggestions?
You are probably using the wrong version of mageui.exe for your project.
If you invoke mageui.exe from, for example, C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin you may not be able to set the entry point on your main executable, as you have found out.
Instead, go one folder deeper to NETFX 4.0 Tools (e.g. C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools) and try use mageui.exe from there. It should work...
To set an entry point, on the files tab in the file list -- when you populate the files in the application manifest, there's a file type column -- one of the dropdown items is an entry point. Nice little hidden feature, eh?