Visual Studio C#

Started by
2 comments, last by SiCrane 11 years, 8 months ago
1. How do you set your project to refer to different references based on the build mode? For example, how do I reference

"Libs\someDebugLib.dll" in my debug build

and

"Libs\someReleaseLib.dll" in my release build

2. How come when using .net libraries you dont have to select debug or release versions? ... is the correct one being chosen under the hood? .. if so, how?
Advertisement
1. In C# you don't. In general when you add a reference you add the debug version. When you are ready to release just include the release version.
2. The only real difference between the two is when in debug the optimizations are disabled. This makes it harder to debug. But you can include either one and they will both work.

1. In C# you don't. In general when you add a reference you add the debug version. When you are ready to release just include the release version.
2. The only real difference between the two is when in debug the optimizations are disabled. This makes it harder to debug. But you can include either one and they will both work.


But lets say you're working on a project with lots of references, and if as you say, you just set the debug references, but having to change these to the release versions each time you want to build a release version (which could be quite often, especially if you're keeping track on performance), is a real pain.
I don't know of any way to do it from the IDE, but you can manually modify the .csproj to change references to conditional references. Basically you find a line that looks like

<Reference Include="MyAssembly, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>path\to\MyAssembly.dll</HintPath>
</Reference>

in your project and change it to something like

<Reference Include="MyAssembly, processorArchitecture=MSIL"
Condition=" '$(Configuration)'=='Debug' ">
<SpecificVersion>False</SpecificVersion>
<HintPath>path\to\MyDebugAssembly.dll</HintPath>
</Reference>
<Reference Include="MyAssembly, processorArchitecture=MSIL"
Condition=" '$(Configuration)'=='Release' ">
<SpecificVersion>False</SpecificVersion>
<HintPath>path\to\MyReleaseAssembly.dll</HintPath>
</Reference>

For the MSBuild condition syntax see this.

This topic is closed to new replies.

Advertisement