Changing Assembly name at Build time
Hi all
I have an GUI application written in c# VS 2005. I want to be able to to modify the assembly name and other assembly information depending on the context in which the application is built. for example whether it is built as debug or release, or some other configuration.
I had thought of doing this as a prebuild step but have been unable to find any examples of this.
Anybody have any suggestions ?
any help would be appreciated
regards
simon
Re: Changing Assembly name at Build time
You can use #if compiler pragma in AssemblyInfo.cs too.
Something like
Code:
#if DEBUG
[assembly: AssemblyTitle("Debug build of application")]
#else
[assembly: AssemblyTitle("Application")]
#endif
should be possible. But keep in mind, that it has not to be compatible with some tasks for msbuild.
Re: Changing Assembly name at Build time
You can also do this from the project file, which normally looks like this:
Code:
<PropertyGroup>
...
<AssemblyName>WindowsForms1</AssemblyName>
...
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
</PropertyGroup>
You can add the assembly name to each configuration:
Code:
<PropertyGroup>
...
<AssemblyName>WindowsForms1</AssemblyName>
...
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
...
<AssemblyName>WindowsForms1D</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
<AssemblyName>WindowsForms1R</AssemblyName>
</PropertyGroup>
Re: Changing Assembly name at Build time
But this change the name of the output file, not just the metainformation in it. I cannot now image a scenario where I'd use it, but is not bad to know it.
Re: Changing Assembly name at Build time
Hi Boudino & Cilu
thanks for the replies. I put some conditional statements in the assemblyinfo.cs. Like you state this changes the assembly title etc which is half of what I wanted to achieve.
I also wanted to have the name of the exe changed as well, so I'll experiment with changing the project file.
thanks
simon