Jehof
Jehof

Reputation: 35544

Renaming executable (.exe) afterwards

Is it save to rename an (entry) assembly (.exe) including it´s configuration file (.config) afterwards? May the .net runtime throw an exception, cause the name is diffrent that the name it was build with?

There are no other assemblies that have dependencies on this file.

The use case is that we run our programm multiple times in our hosting environment as service and we want to identify the programms better in the TaskManager (Internal Support) by including the company name in the file name of the .exe.

Normal name by Build process:

OurApplication.exe
OurApplication.exe.config

New name by Installation process:

OurApplication.CompanyName.exe
OurApplication.CompanyName.exe.config

I have tried this manually once and it seemed to work, but I am unsure if I have missed something.

Upvotes: 1

Views: 1673

Answers (1)

Jcl
Jcl

Reputation: 28272

Nope, there's no problem doing so. It works perfectly fine unless there's a hard-coded reference to the executable name somewhere.

As explained in the MSDN (bold is mine):

The name and location of the application configuration file depend on the application's host, which can be one of the following:

  • Executable–hosted application.

    The configuration file for an application hosted by the executable host is in the same directory as the application. The name of the configuration file is the name of the application with a .config extension. For example, an application called myApp.exe can be associated with a configuration file called myApp.exe.config.

Update: as @MicroVirus pointed out in the comments, you may have problems if you store user settings in the default location, which uses AppDomain.CurrentDomain.FriendlyName which defaults to the exe name. But in your case, being the installer the one changing the name, it should be no problem (the user settings will be stored in the correct path once they are saved)

Upvotes: 3

Related Questions