XAML中的调试和发布程序集引用 [英] Debug and Release Assembly Refrences in XAML

查看:114
本文介绍了XAML中的调试和发布程序集引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在XAML命名空间声明中,是否有一种方法可以根据您当前的配置消除名称不同的程序集的歧义?

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

我正在重新设计项目构建系统.旧系统的调试和发布程序集用于分隔目录,这意味着以下(大约)可以在XAML文档的顶部正常工作:

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"
...

我们收到的关于重组的请求是通过对Debug和Release配置进行不同的命名来区分我们的程序集.因此,我们以前建立在两个单独目录中的SampleAssembly.dll现在是同一目录中的两个程序集SampleAssemblyDebug.dll和SampleAssemblyRelease.dll.有没有一种方法可以根据配置调整该XAML行以引用正确的程序集?

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?

推荐答案

当前,如果没有一些讨厌的预编译技巧,这是不可能的.但是,您可以做的是定义程序集级别属性 XmlnsDefinitionAttribute 在程序集上,然后使用您在XAML中定义的uri命名空间.

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.

例如,在AssemblyInfo.cs文件中,您可以具有以下内容:

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

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

然后在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>

MyButton是TestNameSpace命名空间中的一种类型.

Where MyButton is a type in the TestNameSpace namespace.

这篇关于XAML中的调试和发布程序集引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆