My department has started using Ranorex for automated GUI test about a year ago. In order to work corrently, Ranorex will have to identfy certain UserControls for which we are using a PreBuild event in our projects that makes sure that basically every XAML-element gets an unique x:Uid-tag:
"$(MSBuildBinPath)\MSBuild.exe" /p:Configuration=$(ConfigurationName) /p:Platform=$(PlatformName) /t:updateuid "$(ProjectPath)" > NUL
While this current solution is working, it comes with two drawbacks that I do not like: 1. Every element gets an x:Uid-tag, even those that will never need one (about 80% of the XAML). 2. If x:Name was not defined for the element then the AutomationId will receive a generic name like "TextBox_1", "TextBox2_", "TextBox3_", ... from the msbuild.exe, which sometimes makes it hard for the testers to identify the correct UserControl when creating their tests.
It would be nicer for us if we could make Visual Studio enforce the use of x:Name for certain UserControl types. In 99% of all cases only the UserControls that are used for user input, like for example TextBox, ComboBox and CheckBox, are used by our testers. I know that it is one of the nice parts of WPF to not require x:Name, but in our case it would really make sense, so the question remains:
Is there a way to make Visual Studio enforce the usage of x:Name?