Categories
.NET .NET 10 ASP.NET Core Aspire Automation Azure Blazor C# CLI Code Desktop Developer Getting Started Linux macOS Mobile Visual Studio VS Code Web What's New Windows

Using C# Ignored Directives: A Guide for Programmers

C# – Preprocessor Directives are highly useful for writing code that can be compiled conditionally, depending on factors like the target framework, target platform, or build configuration.

For example:

#if NET9_0_OR_GREATER
// The code within this block will execute only on .NET 9 or higher
#endif

#if ANDROID
// The code within this block will execute only on the Android OS
#endif

#if DEBUG
// The code within this block will execute only in Debug mode
#endif

C# – Ignored Directives have a similar syntax but are ignored by the compiler because they are for tooling.

The real purpose of this feature is to execute a C# source file directly from the CLI. It doesn’t need a project file. Now, even the plain console app requires a project file, despite the much-simplified top-level statements feature.

Categories
.NET .NET 8 .NET 9 .NET MAUI Blazor C# Code Desktop Developer General Hybrid Mobile MVVM NuGet Quick Fix Windows Windows 10 Windows 11 WinUI 3 Xamarin Xamarin.Forms

CommunityToolkit.Mvvm: Resolving Windows 10 MVVM Project Build Issues

Undoubtedly, CommunityToolkit.Mvvm, aka Microsoft MVVM Toolkit, has recently become one of the most popular NuGet packages among MVVM developers.

It effectively abstracts away the boilerplate code, enabling developers to concentrate exclusively on the task.

However, after the release of package version 8.3 and later, while building the project referencing this Toolkit has encountered failures, accompanied by perplexing error messages like System.TypeInitializationException or Found conflicts between different versions of 'WinRT.Runtime' that could not be resolved. when targeting the Windows 10 platform.

Categories
.NET .NET 8 .NET MAUI Android Code Desktop Developer Mobile NuGet Quick Fix Toolkit Xamarin

Trusting Microsoft and .NET MAUI Toolkit NuGet Packages

While trying to restore the recent release of .NET MAUI Community Toolkit v6.0.0 and Markup Toolkit v3.3.0, faced this issue This package is signed but not by a trusted signer.

A similar signing issue came up while installing the workload of .NET MAUI on .NET 8 RC1. However a workaround was provided to overcome the signing issue by bypassing the sign check by trusting NuGet as the package source.