Use Continuous Integration to modify .NET project file

290 Views Asked by At

We have two code bases for testing and production. The only differences between these two code bases are in two files:

  • The config file
  • The build file (.csproj)

Maintaining two branches is a considerable effort which could be eliminated by merging the code bases into one and using a Continuous Integration (such as Hudson, e.g.) to modify the files according to the target environment.

As of VS2010, there is a very smart solution for the config files that allows us to define different config file transformations for two build configurations "Release-Test" and "Release-Prod".

However, we have some differences that are reflected in the project file (.csproj) such as:

  • The name of the resulting assembly: Foo.exe vs. Foo-Test.exe.
  • The assembly version.
  • The ClickOnce deployment settings.

Is there any smart way how the csproj file can be transformed based on the build configuration, or how these settings can be extracted into a config file or C# code?

Update:

I tried with conditional MSBuild properties in the csproj file as suggested by @JaredPar, but it has a couple of caveats (see my comments for details). Are there any other ways to achieve this?

1

There are 1 best solutions below

3
On BEST ANSWER

It sounds like you want to use a single csproj and control elements like the assembly name based on a specific build configuration. If so then you're looking for the Conditional element on MSBuild properties

<AssemblyName Condition="'$(Configuration)' == 'Release-Prod'">Foo</AssemblyName>
<AssemblyName Condition="'$(Configuration)' == 'Release-Test'">Foo-Test</AssemblyName>