Can you tell Visual Studio to output a different name of an exe file depending on if a specific conditional compilation symbol is set?
views:
289answers:
3If you load the .csproj file into a text editor, you can control the AssemblyName
property:
<AssemblyName Condition="'$(Configuration)' == 'Debug'">WindowsFormsApplication9.Debug</AssemblyName>
<AssemblyName Condition="'$(Configuration)' != 'Debug'">WindowsFormsApplication9</AssemblyName>
Note though that this does not only change the file name, but the assembly name, which might mean trouble if you have other code referencing the assembly.
I never did this myself, so I can't really say how good or bad the idea is.
You can edit the csproj file, which is just an MSBuild file which contains 'tasks'. There is a section in the csproj file which is called 'AfterBuild'.
Perhaps, you can add a command there which renames your exe file to the filename of your choice.
(Offcourse, You'll have to uncomment that section).
Perhaps something like this:
<Target Name="AfterBuild">
<Copy SourceFiles="" DestinationFiles="" Condition="" />
<Delete Files="" Condition="" />
</Target>
I haven't worked it out further, but you should complete the Condition attribute, so that you can check whether the conditional symbol is defined or not.
Since defining a condition to the assemblyname tag as suggested by Fredrik seems to make Visual Studio cranky, you can change the assembly name later in the csproj file. Using the Choose element is kind of like an if statement, so a name can be appended if a condition is met, demonstrated below.
Getting a substring out of for instance DefineConstants
in a condition attribute does not seem possible (according to MSDN) with "plain vanilla MSBuild", but one can define their own build targets and set a property when compiling with a /p:Tag=value
(MSBuild command line reference)
...
<Tag>true</Tag>
</PropertyGroup>
<Choose>
<When Condition=" '$(Tag)' == 'true' ">
<PropertyGroup>
<AssemblyName>$(AssemblyName).TagDefined</AssemblyName>
</PropertyGroup>
</When>
</Choose>
<ItemGroup>
...