The "XamlCTask" task failed unexpectedly on visual studio for xamarin - visual-studio

When I am trying to run application on Xamarin on visual studio, I am getting error as mentioned below and not able to run the application on device or emulator:
The "XamlCTask" task failed unexpectedly.
Microsoft.Cci.Pdb.PdbDebugException: Unknown custom metadata item kind: 6
at Microsoft.Cci.Pdb.PdbFunction.ReadCustomMetadata(BitAccess bits)
at Microsoft.Cci.Pdb.PdbFunction..ctor(ManProcSym proc, BitAccess bits)
at Microsoft.Cci.Pdb.PdbFunction.LoadManagedFunctions(BitAccess bits, UInt32 limit, Boolean readStrings)
at Microsoft.Cci.Pdb.PdbFile.LoadFuncsFromDbiModule(BitAccess bits, DbiModuleInfo info, IntHashTable names, ArrayList funcList, Boolean readStrings, MsfDirectory dir, Dictionary`2 nameIndex, PdbReader reader)
at Microsoft.Cci.Pdb.PdbFile.LoadFunctions(Stream read, Dictionary`2& tokenToSourceMapping, String& sourceServerData)
at Mono.Cecil.Pdb.PdbReader.PopulateFunctions()
at Mono.Cecil.Pdb.PdbReader.ProcessDebugHeader(ImageDebugDirectory directory, Byte[] header)
at Mono.Cecil.ModuleDefinition.ProcessDebugHeader()
at Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader reader)
at Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition module, ReaderParameters parameters)
at Mono.Cecil.ModuleReader.CreateModuleFrom(Image image, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(Stream stream, ReaderParameters parameters)
at Mono.Cecil.ModuleDefinition.ReadModule(String fileName, ReaderParameters parameters)
at Xamarin.Forms.Build.Tasks.XamlCTask.Compile()
at Xamarin.Forms.Build.Tasks.XamlCTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__1.MoveNext() MyFirstProject
Before adding this "Xamarin.Forms.Maps" NuGet package, my application working but as I have added this suddenly application stops running and getting error.
Anybody could help me what causes this type of issue?

This issue arise, if your Xamarin.Form version is not compatible/matching with your NuGet package which you have installed.
So, I have just updated Xamarin.Forms for both xx.Droid and PCL and make the match the dependencies with NuGet package.
Now it is working fine. Hope so this will work for you.

Delete your old package /[your project root]/packages/Xamarin.Forms.[old version number].

This kind of issue may also come if by mistake you have any syntactical error like in my case: two text cells were present in the ListView -
<ListView x:Name="ProductsView">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding ProductId}" />
<TextCell Text="{Binding ProductDescription}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I went through other posts for this issue and found the same issue occurred due to the presence of syntactical errors, which VS doesn't report directly. So look for this, otherwise, reinstall the compatible version of xamarin.forms -> clean solutions -> rebuild by reopening VS.

I removed all Xamarin references from ALL projects, removed ALL Xamaring packages. Deleted all mention of Xamarin in PROJ files and readded all nuget packages for Xamarin. (lost days on this) :)

Updating Xamarin.Forms to the latest version on both android and iOS project and reopened the project worked for me.

I am getting this error with Xamarin.Mac in Visual Studio for Mac. I unloded the Xamarin.Mac Project. Than remove it from solution. Finally delete the xamarin.Mac folder from the solution folder. Atlast deleted the packages folder from the solution folder. Remove all nuget packages from xamarin forms project.
Now I again add the nuget packages to xamarin forms project. Added Xamarin.Mac project to the solution and make necessary modifications. This results in a successful build. Though my problem was with xamarin.mac this process may solve problem with other projects also.

When We Add ContentPage Page in Xamarin.Forms. and in that page we add more then one ContentPage.Content in same page. Then also we get this type of the error.

If you have XML errors in your XAML files, this may happen too. Example:
<Label Text="<- go back" />
(You cannot use the character < there, use < instead.)
Or two attributes with the same name:
<Label Text="someText" HorizontalOptions="Center" Text="someText" />

Related

Set up a Xamarin UI Test getting error is incompatible with the Android SDK

I am trying to run a xamarin UI Test but I keep getting
"The running adb server is incompatible with the Android SDK version in use by UITest"
Googled it and cannot find answer I am using
XamarinUITest= 3.0.7
Nunit3TestAdapter 3.17
Android SdK built tools 29.0.2 Set up
Android_Home = C:\Program Files (x86)\Android\android-sdk
Why Am I keeping getting the above error what am I Missing?
Where do I find instructions and what is compatible to what?
Refer to the link below to confirm your project is ready for automated UI testing.
https://learn.microsoft.com/en-us/appcenter/test-cloud/frameworks/uitest/
After that add UITest support to Xamarin.Forms apps. To enable the UITest code to reference controls, each control needs a unique identifier.
<Button x:Name="b" AutomationId="MyButton" Text="Click me"/>
<Label x:Name="l" AutomationId="MyLabel" Text="Hello, Xamarin.Forms!" />
For more details, please check the MS docs. https://learn.microsoft.com/en-us/appcenter/test-cloud/frameworks/uitest/xamarin-forms
Basically if you have any directory in the androidSdK with a name "old" you should delete them and this fixed it for me

How to use CarouselView in Visual Studio 2019 4.4+ and Xamarin.Forms?

I updated my Xamarin.Forms version from 3.4.0.1 to the latest build: 4.4.0.991477, but the CarouselView I was using before, Xamarin.Forms.CarouselView does not work anymore and I get this error:
The type 'CarouselView' exists in both 'Xamarin.Forms.CarouselView,
Version=1.0.7.0, Culture=neutral, PublicKeyToken=null' and
'Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null'
I've looked all over for a solution and replacement for Xamarin.Forms.CarouselView but the best I've seen is Alex Rainman's plugin, CarouselView.FormsPlugin, https://github.com/alexrainman/CarouselView, but I've read people complaining about some bugs in that plugin.
I've also heard that Xamarin Forms has its own new plugin now? https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/carouselview/
But it's very new and there's no one talking about it, not much documentation at all...
So.. for current Xamarin.Forms developers (4.4+), what are you using right now to implement CarouselViews? Is CarouselView.FormsPlugin trustworthy? (I have to update the old CarouselView for a big company so I need to make sure it's good before I push the updated version).
Edit: After uninstalling the plugin:
I'm getting a Failed to resolve assmebly: 'Xamarin.Forms.CarouselView, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' error now.
I'm guessing it's because I have the line
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView" in my xaml file, but if I take it out, then my code using CarouselView
<cv:CarouselView
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
ItemsSource="{Binding ReadingList}"
Position="{Binding Position}">
<cv:CarouselView.ItemTemplate>
...
gets squiggled out
Edit 2: I figured that I needed to change cv:____ to something else because it obviously isn't using the same plugin anymore, so I tried removing the cv: from both and it worked.. is that right?
I figured that I needed to change cv:____ to something else because it
obviously isn't using the same plugin anymore, so I tried removing the
cv: from both and it worked.. is that right?
Yes, what you did is right.
In Xamarin.forms 4.4.0.991477, CarouselView is a class in Namespace: Xamarin.Forms and Assembly:Xamarin.Forms.Core.dll.
So you can modify your cv___ to :
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.Core"
And use it like:
<cv:CarouselView/>
Generally, it is unnecessary to use cv because the default namespace has specified that elements defined within the XAML file with no prefix refer to Xamarin.Forms classes:
xmlns="http://xamarin.com/schemas/2014/forms"
So, after you remove the cv: from both and your project worked.

Xamarin Studio - can not login - One of the identified items was in an invalid format

As part of my Microsoft Action Visual Studio eligibility for using/developing in Xamarin I'm trying to login in Xamarin Studio (Mac). I still have Xamarin Studio on my Mac (until recently I had an Indie subscription). Now when trying to login I get the error message(s) below.
Anyone an idea how to avoid this error?
Thanks.
System.FormatException: One of the identified items was in an invalid format.
at Xamarin.Components.Ide.Activation.ActivationService.GetErrorWorkflow (Xamarin.Components.Ide.Activation.LicenseSyncResult[] results, Boolean ignoreSyncErrors) [0x00264] in /Users/builder/data/lanes/2968/8dc6bca6/source/md-addins/Xamarin.Ide/Xamarin.Components.Ide/Activation/ActivationService.cs:762
at Xamarin.Components.Ide.Activation.ActivationService+<GenerateFullWorkflowSequence>c__Iterator3.MoveNext () [0x00410] in /Users/builder/data/lanes/2968/8dc6bca6/source/md-addins/Xamarin.Ide/Xamarin.Components.Ide/Activation/ActivationService.cs:654
at Xamarin.Components.Ide.Activation.ActivationDialog.DisplayWorkflowStep (Xamarin.Components.Ide.Activation.ActivationWorkflowStep step) [0x0002c] in /Users/builder/data/lanes/2968/8dc6bca6/source/md-addins/Xamarin.Ide/Xamarin.Components.Ide/Activation/ActivationDialog.cs:463
at Xamarin.Components.Ide.Activation.ActivationDialog+<StartSpinnerTaskAndScheduleContinuation>c__AnonStorey4.<>m__0 (System.Threading.Tasks.Task t) [0x0005b] in /Users/builder/data/lanes/2968/8dc6bca6/source/md-addins/Xamarin.Ide/Xamarin.Components.Ide/Activation/ActivationDialog.cs:561
Guys from Xamarin Support already post an answer to this
http://forums.xamarin.com/discussion/63675/activation-error/p1
In general you should
Update to the "Cycle 6 – Service Release 3" versions or newer.
The minimum version of Xamarin Studio that supports MSDN licenses is here: http://download.xamarin.com/studio/Mac/XamarinStudio-5.10.3.51-0.dmg
Log out and log back into your Xamarin account following the "Quick manual refresh steps" on https://kb.xamarin.com/customer/en/portal/articles/1641743-how-do-i-manually-resynchronize-xamarin-licenses-.
Update Xamarin to the latest stable version. That worked for me.
My mistake was in grid I had added ** instead of *,
ie:
<RowDefinition Height="**" />
instead of
<RowDefinition Height="*" />
Check if same applies to you

Xamarin.Forms - InitializeComponent doesn't exist when creating a new page

I'm using Visual Studio to try out Xamarin.Forms. I'm trying to follow the guide:
http://developer.xamarin.com/guides/cross-platform/xamarin-forms/xaml-for-xamarin-forms/getting_started_with_xaml/
In short, I create a Xamarin.Forms solution using a PCL and then try to add a Forms XAML Page to the PCL-project.
The code-behind that gets created looks like this:
public partial class Page1 : ContentPage
{
public Page1()
{
InitializeComponent();
}
}
The problem here is that InitializeComponent(); is red.
When I try to build I get informed that The name 'InitializeComponent' does not exist in the current context
I've been looking around for solutions and even though others have had the same trouble, their solutions wont work for me. Here is one suggestion i tried to use:
http://blog.falafel.com/xamarin-error-initializecomponent-does-not-exist-in-the-current-context/
Please let me know if you have a solution for this problem. Thanks!
Update:
My PCL (which is where I also want to add my XAML-page) contains:
App.cs:
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!"
}
}
}
};
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
And my XAML-page:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamaTest.MyXamlPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
Code-behind:
public partial class MyXamlPage : ContentPage
{
public MyXamlPage()
{
InitializeComponent();
}
}
UPDATE:
This error doesn't usually appear in VS 2015, if it does, here's my original answer:
Found the solution!
Right click on the .XAML file, select Properties.
You will see a Property called Custom Tool. Change its value from MSBuild:Compile to MSBuild:UpdateDesignTimeXaml
This will solve the problem.
Dont know about the downvote, but here's my screenshot:
UPDATE:
It reappears rarely. If it does, just open the Xaml and code behind files and save them. I know, its not the best solution, but it gets the job done.
I get this sometimes and here's the checklist that solved them so far:
Make sure the namespace in .xaml and .xaml.cs match
Inherit from the correct parent - ContentPage for a page and ContentView for a control
Set build action of the .xaml file to Embedded Resource if in the shared project.
As far as my observation is concerned, in Visual Studio 2015, XAML properties are already set as suggested by highly-voted answers here by default, specifically :
Custom Tool = MSBuild:UpdateDesignTimeXaml
Build Action = Embedded Resource
but the error still appears sometimes... (like in this other question).
Editing the corresponding XAML file and then hit CTRL+S should work fine, but you don't have to. A cleaner way to force Custom Tools to be run is by right-clicking on the XAML file and then click on "Run Custom Tool" context menu.
I have met this problem. It's associated with the encoding of XAML files in VS. I'm using VS2015.
I solved this problem as follows:
Open the *.xaml file in the project and click Save button. (There will be applying the correct encoding in VS2015).
Then reopen the project and rebuild it. Now there are no errors.
Updating the Xamarin.Forms NuGet package should do the job
This is probably not your case but I had similar problem and mine was xaml and code behind name missmatching. for example according to your sample,
if code behind namespace is XamaTest(name of your app in most cases) and class is called MyXamlPage, your xaml class name must be XamaTest.MyXamlPage ([namespace].[classname])
I was silly after creating an empty xaml with code behind, I changed name of the class in xaml and i was getting this error.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamaTest.MyXamlPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
</ContentPage>
Code-behind:
public partial class MyXamlPage : ContentPage
Try adding a x:Name="..." on the xaml page... Nothing else worked for me - but after adding the x:Name attribute on some of the elements on the page the error dissapeared (most of the times - I still get it sometimes). I use the latest build (1.5.0.6447) of Xamarin.Forms...
XAML don't work on shared projects - it only works in portable projects...
It looks like the (re)generation of the blah.xaml.g.cs files is actually the problem. I get this a LOT in shared projects (which is why I don't use them unless I have no other choice). It happens way more in Xamarin Studio than Visual Studio, for me, for some reason. I try not to use XS at all.
Often unloading one of the other platforms (e.g. if you're building droid, unload ios) and doing a clean and rebuild will fix it.
You can also try doing something like opening one of the offending .xaml files and changing some of the xaml markup (e.g. adding or changing an x:Name to one of the controls or views). This will force a regeneration of the xaml.g.cs file, and (for me at least) usually solves the problem.
This really shouldn't be a thing tho.
I came across this error when;
I removed a ContentPage-cs+xaml and the App-cs+xaml from the project without actually deleting it.
Re-added these to the project in another folder.
This was fixed by;
Select the .xaml file of the class in which the issue is present.
Right click and select properties.
In Build action select "Embedded Resource"
In Custom Tool type "MSBuild:UpdateDesignTimeXaml"
Clean and Build and it was gone.
Check page text x:Class="AppName.Page1". AppName must be your app name
If you get intellisense errors such InitializeComponent in your Xamarin.Forms pages but the project actually builds and runs fine, just add a new Forms page using the wizard to fix all errors...
Then you can delete that new page.
I had similar problem in Visual Studio 2013 update 4 environment and I tried all recommendations what I found on the web. Nothing solved my problem.
Then I tried workaround approach. I installed Visual Studio 2015 preview and create new blank app with xamarin forms project.
When I added new Xaml file everything was OK and issue with InitialComponent method disappeared.
I don t know where exactly is the reason of the problem but it seems to be issue around configuration settings.
A Clean and rebuild did the trick for me!
Right click *.xaml and click properties,and change "Custom Tool" value to "MSBuild:UpdateDesignTimeXaml", next change "Build Action" properties to "Embedded Resource",
build project works.
Very simple solution that worked for me:
Copy contents of the xaml/cs file
Delete the xaml/cs file
Create a new class and paste the contents
Now the InitializeComponent() function appears without red underline.
Hope this helps someone.
Check the class name properly.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="{AppName}.{ClassName}">
</ContentPage>
The class name should be a combination of App name and partial class name
This problem appears when the projects of solution are referencing the version 1.4.0.0 of the dlls "Xamarin.Forms.Core", "Xamarin.Forms.Xaml" and "Xamarin.Forms.Platform" version 1.0.0.0.
To solve it I've had to downgrade to version 1.3.3.0 of the dlls but with this version Xamarin.Forms.Platform 1.0.0.0 don't exists.
Check the version of Xamarin.Forms package referenced in your project.
I have been having the same issue now and then, and this is what I have been doing to fix it: When in the PCL project, I add a new cross-platform XAML page to the project. Adding a new XAML page takes a few seconds for the references to "hook". After the new XAML page is successfully added to the project, the red underlines on the XAML Pages (with issues) will get cleared. Once the problem is solved, I simply delete the XAML file that I have just added. - So, in summary, adding a new XAML page then deleting it has been solving the issue for me.
I Just updated All packages, works fine.
Change Page properties to :
BuildAction => Embedded resource
CustomTools => MSBuild:UpdateDesignTimeXaml
I had a caching issue when I encountered this error.
To get this fixed, simply uninstall last version of Xamarin.Forms package and reinstall a previous working version.
When the rebuild is successful, then update the package again to the latest version.
It appears this is caused by many things so if you've read all of these and haven't resolved it yet:
Mine was caused by the Solution Configuration being set to Release. Changed to Debug and error resolved.
In my case the problem was the project path.
The generated code file gets a name including the absolute path encoded to make it a valid filename.
The path was "D:\Projekt C#\ProjectRootFolder\Project".
The filename generated by the build tool was "Project.Droid.D_.Projekt_C_. Namespace etc."
Moving the project to a path like "D:\project\ProjectRootFolder" helped in my case.
I'm using Visual Studio 2015, I got the same problem, and found none of the answers on the net was a full solution.
Here I'll explain what worked for me.
My primary goal here was to eliminate the red error message that kept coming up
The name InitializeComponent does not exist in the current context
Basically I created a function called InitializeComponent2() that does exactly the same thing as InitializeComponent() and used that instead, I literally copied the code for InitializeComponent().
Does the job.
It looks like this (and I'll explain):
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent2()
{
// Change to:
// this.LoadFromXaml(typeof(Page2)); // for Page2
// this.LoadFromXaml(typeof(Page3)); // for Page3
// and put
// using Xamarin.Forms.Xaml;
// at the top of each source file.
this.LoadFromXaml(typeof(Page1));
}
Put the function in the definition of each of your pages (.cs files) e.g.
public partial class Page1 : ContentPage
{
[System.CodeDom.Compiler.GeneratedCodeAttribute("Xamarin.Forms.Build.Tasks.XamlG", "0.0.0.0")]
private void InitializeComponent2()
{
// Change to:
// this.LoadFromXaml(typeof(Page2)); // for Page2
// this.LoadFromXaml(typeof(Page3)); // for Page3
// and put
// using Xamarin.Forms.Xaml;
// at the top of each source file.
this.LoadFromXaml(typeof(Page1));
}
}
Also you need to put using Xamarin.Forms.Xaml; at the top of each .cs page
where LoadFromXaml(..) is used.
And then of course change InitializeComponent() to
InitializeComponent2() to call the new function.
i.e. you have put the function into the same context as the page making the error go away. I can't imagine the real InitializeComponent function will get anything added to it as you modify your project but that is a possibility.
It's been fine for me so far.
I tried many things, changing the Build Action, the XAML namespace, restarting vs, cleaning+rebuilding, looking for NuGet package updates.
Basically, Visual Studio compiled and ran the program fine on my android device + emulator, but that error message wouldn't go away.
My solution is for Android, but it may also work for iOS etc.
I went back to the root of the problem InitializeComponent() The actual code for this function is generated in a file called <Your Project Name>.Page1.xaml.g.cs or Page2.xaml.g.cs for example. However, it (the file) is
only generated when a certain event gets fired. I was lucky to discover
it by typing text into "Custom Tool Namespace", which fired that event, for one of the xaml pages(a file ending in .xaml, not .cs - make sure you have .xaml file selected), type some text and press enter and the file will be created.
Then I had the great idea of making InitializeComponent2(), a function exactly the same as InitializeComponent() and putting it in each cs file so it exists
without having to generate the .xaml.g.cs every time you want the error to
go away.
I don't know if this is solved, but for me, the only thing I had to do is remove the first line of the XAML ("xml version="1.0" encoding="utf-8")
Sometimes source version control, tries to identify which type of file is and add this kind of stuff.
add using Xamarin.Forms.Xaml
tested on Visual Studio 2017
Select the App.xaml and MainPage.xaml file of the class in which the issue is present.
Right click and select properties.
In Build action select "Embedded Resource"
In Custom Tool type "MSBuild:UpdateDesignTimeXaml"
Clean and Build and it was gone.
Ultimate solution would be to edit the project file in a text editor and just copy the pattern from another non-conflicting file. This solution worked for me. Usually, you would look for this syntax:
<Compile Update="Your\Path\YourContentPage.xaml.cs">
<DependentUpon>YourContentPage.xaml</DependentUpon>
</Compile>
In Xaml Page Properties only set
Build Action = Embedded resource
It works in visual studio 2017.

AlternateContent Tags causing issues with IDE, but not compiler

I am working on a legacy product. I need to make regions of a complex UI optional, based on build constants. It is not feasible to move these regions into controls, so I am using AlternateContent Tags (mc:AlternateContent).
This works perfectly, at compilation and the application runs as expected.
However, the IDE claims one error for each AlternateContent, and enclosed Choice Tag, and will not load the Design window/preview (in VS or Blend):
The name "AlternateContent" does not exist in the namespace "http://schemas.openxmlformats.org/markup-compatibility/2006"
The name "Choice" does not exist in the namespace "http://schemas.openxmlformats.org/markup-compatibility/2006"
I have tried, rebuilding, cleaning and rebuilding, changing build settings between release, debug, x86, x64, and rebooting. Nothing helps. It even give the same errors in Blend.
I am hoping that this is just something stupid that I am doing, and I can fix it; or possibly a newer Namespace URI I should be using. If I cannot resolve the errors, I am hoping someone knows a trick to suppress these errors in the IDE, so can use it.
I have a fully updated VS2013 Premium installation. However, It has the glitch on a test machine running VS14 CTP, and another running VS2012 (fully updated), both without any add-ins; so I have to assume it is not a problem with my PCs install.
A little late to the party, but if you add the mc tag to your Ignorable attribute the error goes away. Your content won't show in the designer but worked for me when I compiled the different flavours of my project.
<UserControl...
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conditional="defined-in-assembly.cs"
mc:Ignorable="d mc"/>
What about this:
public class BuildConstants
{
public bool IsDebug
{
get
{
#if DEBUG
return true;
#else
return false;
#endif
}
}
}
and the xaml:
<Application.Resources>
<BooleanToVisibilityConverter x:Name="BooleanToVisibilityConverter"></BooleanToVisibilityConverter>
<l:BuildConstants x:Key="BuildConstants" />
</Application.Resources>
<Grid Visibility="{Binding IsDebug, Source={StaticResource BuildConstants}, Converter={StaticResource BooleanToVisibilityConverter}}">
<TextBlock Text="This will be visible only when DEBUG build constant is present"></TextBlock>
</Grid>

Resources