Compile two versions of C# program automatically - c#

I have to make the same program for two different companies (different logo, different name).
I would like to have this done automatically when I do a release.
I am thinking to use a resource file or a satellite assembly, but I am not sure how to proceed.
Which way do you think is the best?
Thanks.
EDIT:
The differences are only one image and one string.
I would like to
have everything generated in one click.
We might get more clients in
the future.
I must also add that I use SmartAssembly to merge all my dependencies into one exe file.

You could create a class library that contains 99% of the code, and then have two projects which each reference the common library with the 1% that differs for each company. Then a build of the whole solution will generate an executable for each company. Use this if the differences between what each company wants is just enough that you need to have [slightly] different code.
Alternatively, you could make the sections that vary dependent on data, not code. In this case, it might mean getting the logo from a file, rather than embedding it in the executable, and having a configuration xml file with the company name. This would allow you to have just a single executable for both companies.

Resource string in separate assembly would be the easiest distribution.
But honestly, I'd have it be a customization feature.
Last thing you want is to maintain everyone's logo changes due to: legal reasons, copywrite cases, whimsical artistic license, etc.
Which is short for.... have them provide a formatted image, and have them assign the company name during installation and store that off in the registry or in a meta file of some type (XML, manifest, etc.)

The best I can think of it a batch script.
Get your project to reference files (images (logo), text (company name), etc). i.e. C:\MyProject\Resources. So that when the project builds it complies them into the application/installer etc.
This way, you can write a script (.bat file) which copies in the resources needed per company.
Step 1 - Delete all files in the Resources folder
Step 2 - Use MSBuild.exe to build you project
Step 3 - Copy the files needed from the bin/release folder to a directory (i.e. C:\Release\CompanyA)
Step 4 - Change the variables in the script to load the details for the next company. And repeat from step 1, so it copies over the needed resource files and rebuilds.

Related

Can you add a language without forcing a rebuild?

My app has been designed to be able to run on two different languages, english and czech. In order to accomplish this, I've created 2 resource files:
If an end-user would like to add another language, for example GlobalStrings.fr-FR.resx, is it possible to allow for this functionality without rebuilding the application?
If we look at the properties of these resource files:
I'm not understanding what embedded resource means. Does this mean that in order for the app to consume this file, the application must be rebuilt?
How do we create a resource file, that is open to be extended/changed by the end user, without having to rebuild the entire application
?
Regular .Net resources are compiled into assembly with particular name and loaded by matching that name. So if "end-user" is ok to translate strings in resx file and compile resources into assembly with particular name (like "MyResources.cs-cz.dll") you can do that with default .Net behavior without recompiling main code. See MSDN:Packing and Deploying resources and related links for more information.
Note that you don't need Visual Studio for it and can use csc command line compiler to embed resources on user's machine - so if your really want you can provide simple script that compiles corresponding resx locally. Note that editing XML (resx) as text is generally not possible by regular person due to required encoding of some characters - consider technical level of your "end-users" before going that route. Plain text version of source for resource may work in more cases.
Usually this is not the case - if end-user localization is requirement you would create some sort of custom resource string management by loading strings from plain text files or database that users can update locally.

How can I programmatically add content to new/existing executable using c# and possibly make the solution work on a mac?

I've seen a number of variations on this question and im not sure if this question has been completely duplicated.
I would like to be able to at run-time run an existing executable (SOURCE exe) and have it:
1) take an existing TARGET exe at run time and add content of any size and type to the TARGET exe (pdf, image, word, excel file type, etc)
2) be able to run the modified TARGET exe so that when the TARGET exe is run, it will find the embedded content inside of itself and copy the content to the hard drive and then run the program associated with the content (foe example, run excel on a copied xls file)
I've seen examples where you embed resources at compile time in visual studio but I want to do this at run-time in code (c#, java, whatever works). Either the host TARGET exe needs to already exist and content should be added to it OR the exe will need to be generated from scratch at run-time and content again added to it.
I also would prefer not to use any of the cmd-line tools that visual studio or any other tool would run behind the scenes (if possible) to create an exe to minimize the enduser needing to download any more libraries/sdks than necessary.
This product is in line with what i want to do
http://www.boomeranglistbuilder.com/instructions/usingsoftware.php
(I want to improve upon it) :)
Lastly it'd be great if the solution could be cross platform compatible (doubt it though)
Could this be done in java?
I've seen the window library resource method updateresource method mentioned in my searches but I'm not sure if that would completely fit my situation. can anyone comment?
I hope my question is clear. Please let me know.
Any help would be graciously appreciated.
Thank you,
Carlos
I think that it's true for most binary file formats (including the executables), appending data to a well-formed file will not affect the usage of the file, the way it is typically interpreted by most programs. You could, maybe, take advantage of this.
To embed, you'll need to take your (existing) target executable and simply append some binary data to it. That data will have two parts:
A magic word (to denote the presence of an appended resource)
The resource itself.
So, this:
[target executable data]
Becomes this:
[target executable data]
[magic word]
[resource]
To read the resource from the target executable, simply have that executable open itself, search for the magic word and, if it's present, start reading the resource appended after it.
This is what WinRAR does (or at least did four years ago, when I last checked) to recognize the archives inside of its self-extracting files.

Using Resources (resx) Inside a ClassLibrary, that can be changed without recompiling

I need to make a ClassLibrary, to contain different Resource Files (resx). This needs to be done, so I can reuse these resources on multiple projects.
After reading for quite a while on how to achieve this, I'm still nowhere near close to an answer.
Note that i need to achieve this in a way that I don't have to recompile the proyect if I want to change a value
Is there a simple way to achieve this that I'm missing?
Hate to be the bearer of bad news, but I'm afraid you're trying to use RESX files for something other than what they're designed to do. RESX files are compiled into .resources files, which are then embedded into the assembly during the build. In other words, if you don't recompile, you won't see any changes that are made to the resx file reflected in the module.
The benefits of RESX files extends far beyond providing compiled cultural/language text tightly coupled to a deployed solution. They have the potential to provide a simple and flexible set of content managed outside the software development process. Some views here:
What are the benefits of resource(.resx) files?
Yes you can work with your RESX files without having to compile them. See here:
Edit ASP.NET MVC 3 resx files in deployment server without recompiling
Yes you can share RESX files between different projects and even roll your own resource manager. You can maintain alternate sets of resources, serving up alternate content depending on for example the user context. I have been involved in a project where we implemented something along these lines to great affect, in my case the solution was used to provide white labeling. Some detail to get you started here:
http://msdn.microsoft.com/en-us/library/aa905797.aspx

How to loop through folders if I do not necessarily know their structure but only the destination?

I'm writing a program that needs to access a file inside of c:\program files\program_name\.
My target file will always be inside of \program_name\program_name\bin\something.exe
However, because the program is extracted from an archive, if the user unpacks it improperly, it'll be simply \program_name\bin\something.exe, skipping a whole level.
Currently I'm basically getting the contents of c:\program files\, collecting the names of all folders that contain program_name, then adding them to the list and then using the list to loop through each one of those seeing if there's a program_name inside of it, etc, which should eventually lead me to the result.
Basically I'm creating large chunks of code for each individual possibility. Is there a smarter way to go about this?
Sounds like you could benefit from having an installer that writes to the registry. Then you'll know where all the files and folders are, even if the user installs to a weird location.
To expand on what Charlie said -- you could wrap the original app in some kind of unified installer type thing that would write the registry and extract the app to whatever place the user decides. The installer would prompt the user for the location to install to, and would extract to that location. InnoSetup can be configured to write the uninstall info, put uninstall links, etc. You can customize the uninstaller part of the InnoSetup script to do whatever cleanup you need, and/or call other external programs, if necessary.
InnoSetup allows you to package stuff in the actual installer exe, so you only have to distribute one flle. I can verify that this works -- although I've never tried it for packing huge files.
Here's a link to InnoSetup: http://www.jrsoftware.org/isinfo.php

How To Store Files In An EXE

Alright, so I'm working on programming my own installer in C#, and what I'd like to do is something along the lines of put the files in the .exe, so I can do
File.Copy(file, filedir);
Or, if this isn't possible, is there another way of doing what I am attempting to do?
I wouldn't code my own installer, but if you truely want to embed files into your assembly you could use strongly typed resources. In the properties dialog of your project open up the "Resources" tab and then add your file. You'll then be able to get the file using:
ProjectNamespace.Properties.Resources.MyFile
Then you'll be able to write the embedded resource to disk using:
System.IO.File.WriteAllBytes(#"C:\MyFile.bin", ProjectNamespace.Properties.Resources.MyFile);
Honestly, I would suggest you NOT create your own installer. There are many many issues with creating installers. Even the big installer makers don't make their own actual installers anymore, they just create custom MSI packages.
Use Mirosoft Installer (MSI). It's the right thing to do. Make your own custom front-end for it, but don't recreate the already very complex wheel that exists.
UPDATE: If you're just doing this for learning, then I would shy away from thinking of it as "an installer". You might be tempted to take your "research" and use it someday, and frankly, that's how we end up with so many problems when new versions of Windows come out. People create their own wheels with assumptions that aren't valid.
What you're really trying to do is called "packaging", and you really have to become intimately familiar with the Executable PE format, because you're talking about changing the structure of the PE image on disk.
You can simulate it, to a point, with putting files in resources, but that's not really what installers, or self-extractors do.
Here's a link to Self-Extractor tutorial, but it's not in C#.
I don't know enough about the .NET PE requirements to know if you can do this in with a managed code executable or not.
UPDATE2: This is probably more of what you're looking for, it embeds files in the resource, but as I said, it's not really the way professional installers or self-extractors do it. I think there are various limitations on what you can embed as resources. But here's the like to a Self-Extractor Demo written in C#.
I'm guessing here, but if you are trying to store resources in your application before compilation, you can in the Project Explorer, right click a file you would like to add, chose properties and change the type to Embedded Resource.
You can then access the embedded resources later by using the instructions from this KB:
http://support.microsoft.com/kb/319292
in case you simply want to store multiple files in a single file storage (and extract files from there, interact etc.) you might also want to check out NFileStorage, a .net file storage. written in 100% .NET C# with all sources included. It also comes with a command line interpreter that allows interaction from the command line.

Categories

Resources