Debug and remove crashes in XAML

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

I am currently reworking the project build system. On the old system, debug and release builds were created to separate directories, which meant the following (roughly) would work fine at the top of the XAML document:

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

      

The request we received for the restructuring is to differentiate our builds by naming them differently for Debug and Release configurations. Thus, our SampleAssembly.dll, which was previously built in two separate directories, now consists of two assemblies in the same directory: SampleAssemblyDebug.dll and SampleAssemblyRelease.dll. Is there a way to customize this XAML string to reference the appropriate assembly depending on the configuration?

+1


source to share


2 answers


This is currently not possible without some nasty precompilation tricks. However, you can define the assembly level attribute XmlnsDefinitionAttribute on your assembly and then use the uri namespace that you defined in your XAML.

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

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

      



And then in 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">
    <Grid>
        <test:MyButton></test:MyButton>
    </Grid>
</Window>

      

Where MyButton is the type of the TestNameSpace namespace.

+2


source


The XmlnsDefinitionAttribute setting did a great job. The assembly I'm trying to load into XAML exits the CLI project. To get XmlnsDefinition to work correctly, I had to add a reference to WindowsBase (an assembly with the System.Windows.Markup namespace in it) in my CLI project.



Once I built it, it worked like a charm. Good advice.

0


source







All Articles