【发布时间】:2016-03-22 09:03:45
【问题描述】:
我试图在调试和发布配置中的 WPF 控件中显示不同的视图元素以进行测试。我以这篇文章为指导: Does XAML have a conditional compiler directive for debug mode? (SO)
为了测试它,我创建了一个带有单个 WPF 应用程序项目的 VS2013 解决方案,称为 TestingAlternateContent。在我的 AssemblyInfo.cs 中,我添加了以下代码:
#if DEBUG
[assembly: XmlnsDefinition("debug-mode", "TestingAlternateContent")]
#endif
在我的 MainWindow.xaml 中,我创建了一个简单的代码示例来测试此行为,如下所示:
<Window x:Class="TestingAlternateContent.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:debug="debug-mode"
mc:Ignorable="mc debug"
Title="MainWindow" Height="350" Width="525">
<Grid>
<mc:AlternateContent>
<mc:Choice Requires="debug">
<TextBlock Text="Debug mode!!" />
</mc:Choice>
<mc:Fallback>
<TextBlock Text="Release mode here!" />
</mc:Fallback>
</mc:AlternateContent>
</Grid>
</Window>
在测试这个时,我总是看到带有“这里的发布模式!”的窗口。消息,无论我使用的是哪种配置(调试、发布)。我检查了 AssemblyInfo #if DEBUG 是否正常工作,当我在调试/发布配置之间进行更改时会相应更改。 我已经在 VS2008/VS2013 下使用 .NET Framework 3.5/4.5 版本测试了相同的代码,但没有一个有效。 我错过了什么?有人知道这里出了什么问题,或者可以发布一个工作代码作为参考吗?
【问题讨论】: