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 Android Automation Blazor C# Desktop Developer General Getting Started Hybrid iOS macOS Mobile Preview Templates VS Code What's New Windows Xamarin Xamarin.Forms

Elevating .NET MAUI Item Templates: Simplified Namespace Resolution in Latest Release

Back in February, an article was published on the efficient utilization of Item Templates through the use of script automation. The article, titled .NET MAUI – Item Templates – Made Easy on CLI and VS Code, provides a detailed focus on this topic.

That article addressed two issues:

  • Better namespace resolution
  • Do more with fewer keystrokes

Now, the namespace resolution issue has been partially supported within the .NET SDK, eliminating the requirement for additional script files. A PR was submitted to the .NET Templating source repository, underwent review, and was subsequently merged into the main branch. This enhancement was then included in the release of .NET 9 Preview 6.

Categories
.NET .NET 8 .NET 9 .NET MAUI Android Automation Blazor C# Desktop Developer DevOps Extensions General Getting Started Hybrid iOS Mobile NuGet Templates Visual Studio VS Code Web What's New Windows Xamarin Xamarin.Forms

.NET MAUI All-in-One Templates Pack v5.6: NuGet CPM and Nightly Builds Support

Firstly, .NET MAUI 9 Preview 5 has just been released. The changelog can be found here. Notably, a new Blazor Hybrid Web template has been introduced in this version.

In short, this new template abstracts the Razor components into a distinct Razor Class Library (RCL). Furthermore, it provides the ability to create Blazor Web projects within the same solution and refers to the shared RCL.

The concept of abstracting the Razor components is already facilitated by the Hybrid project templates within the All-in-One template pack.

dotnet new mauiapp -o MyApp -dp Hybrid -rcl

Will review the modifications and cover them in a distinct article.

Categories
.NET .NET MAUI Android Automation Blazor Deep Dive Desktop Developer General Hybrid iOS Mobile MVVM NuGet Templates Visual Studio VS Code What's New Windows Xamarin Xamarin.Forms

.NET MAUI – Item Templates – Made Easy on CLI and VS Code

Even though the All-in-One item templates have the same set of features in VS2022 and on the CLI. The CLI has its own limitations and here are the notable ones:

  1. The namespace resolution is not on par with its VS counterpart
    • On CLI – Defaults to the root namespace
    • Whereas in VS to the exact folder where the item is created
  2. A lot of (repeated) typing is required
    • The underlying reason is CLI’s named parameters design