i want to change AssemblyInfo
of copied executeable file to a new location and keep the main information of main executeable file safe.
i am using the codes below to copy my file to new location with new file name.
String fileDestination = Path.Combine(Environment.GetFolderPath(folder), "settings.exe");
if (!File.Exists(fileDestination))
File.Copy(Application.ExecutablePath, fileDestination);
but AssemlyInfo
of new file is same as source file and i want to change them.
how can i do that before copying original file?
MoonLight,
This is possible, however not exactly an easy solution. You have a few options here.
I must note, that to answer your question. It is not possible to change the assembly information during a simple copy. The assembly information is "cooked" into the assembly and not changeable.
Option 1:
If at all possible I would do this before the assemby has been built. Typically this can be done using SharedAssembly information that you can move across your application. In this event you "could" use a pre-build "Event" to copy a SharedAssembly info over to the target directory. The SharedAssembly path is quite easy and is described here. http://blogs.msdn.com/b/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx It uses the process of linked files between your solution projects giving applying all or partial of the assembly info (or all) to your projects. In this case you could use the pre-build event to do an
xcopy
of the preffered SharedAssembly Information thus linking the new Assembly Information. Now to make this process whole I would do this.Pre-Build.
Post-Build
Option 2:
There is a package from the Mono framework that "could" do this. However this is much more difficult, in addition this package only changes the assembly definition and not the Win32Resources that are visibile when viewing the File properties -> details tab.
Using the Package Mono.Cecil on Nuget this is possible. Here you can change \ add assembly attributes, Names etc.
Here is a sample to change some attributes (note there are many more and best to use your debugger and review the available attributes).
In the end if you really, really want to change the file details it will have to be done at compile time using Option 1.
I hope this helps.