views:

198

answers:

2

In a XAML namespace declaration, is there a way to disambiguate differently named assemblies depending on your current configuration?

I'm in the process of reworking a projects build system. The old system had the debug and release assemblies building to seperate directories, which meant the following (roughly) would work fine at the top of a XAML document:

<Window x:Class="test.MainWindow"
...
    xmlns:tns="clr-namespace:TestNameSpace;assembly=SampleAssembly"
...

A request we recieved for the restructure is to differentiate our assemblies by naming them differently for Debug and Release configurations. So our SampleAssembly.dll, which was previously built in two seperate directories, is now two assemblies in the same directory, SampleAssemblyDebug.dll and SampleAssemblyRelease.dll. Is there a way to adjust that XAML line to reference the proper assembly depending on the configuration?

+1  A: 

Currently this is not possible, without some nasty precompilation tricks. However what you can do is to define an assembly level attribute XmlnsDefinitionAttribute on your assembly and then use the uri namespace that you have defined in your XAML.

For example in your AssemblyInfo.cs file you can have something like this:

[assembly: XmlnsDefinition("http://mytest.com", "TestNameSpace")]

And then in the XAML:

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:test="http://mytest.com"&gt;
    <Grid>
        <test:MyButton></test:MyButton>
    </Grid>
</Window>

Where MyButton is a type in the TestNameSpace namespace.

ligaz
A: 

The XmlnsDefinitionAttribute setup worked out great. The assembly I'm trying to load in the XAML comes out of a CLI project. To get the XmlnsDefinition to work properly, I had to add a reference to WindowsBase (the assembly with the System.Windows.Markup namespace in it) in my CLI project.

Once I had it building, it worked like a charm. Good tip.

Perculator