Visual studio project configuration file settings priority

csproj in explorerTHE PROBLEM
For multiple versions (Dev, Test, Prod) of a single ClickOnce application one has to name assemblies differently. In this way you can have all three versions on the same computer. This can be easily achieved by using configuration in Visual Studio. The problem I had was that no matter what the assembly name I specified in the configuration, it would not use it during build.

SOLUTION
The problem was hidden on the bottom of the “application.csproj” file. All the properties of each configuration were placed on top of the csproj file and the bottom parameter was always setting like a default value.

 
.
.
.
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
   <OutputPath>bin\Release\</OutputPath>
   <DefineConstants>TRACE</DefineConstants>
   <Optimize>true</Optimize>
   <DebugType>pdbonly</DebugType>
   <PlatformTarget>AnyCPU</PlatformTarget>
   <ErrorReport>prompt</ErrorReport>
   <CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
   <AssemblyName>Application Test</AssemblyName>
   <ProductName>Application Test</ProductName>
   <InstallUrl>https://localhost/install/</InstallUrl>
   <PublishUrl>C:\Deploy\</PublishUrl>
   <UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
.
.
.
<PropertyGroup>
   <AssemblyName>Application</AssemblyName>
</PropertyGroup>
.
.
.

Just remove the bottom PropertyGroup and your configuration setting will be applied at build time. Don’t forget to always reload the project when you change the configuration file, as visual studio always reads it only at project load.

PS: To edit the csproj you must first unload the project. Then you can right click on it and choose edit. (or use a text editor in explorer)

Comments

Leave a Reply

%d bloggers like this: