December 22, 2024

Apple macOS and Document Templates (Excel & Word)

Part 6 of the series about the new Mac Mini M4 and Power Platform, this time I will check the built-in template functionality available in model-driven apps.

This functionality allows to upload a template (Excel or Word) and users can download a document with data coming from the app.

An important thing to remember is that Excel templates are applied to views and Word templates are applied to a single record.

Let's start with Excel templates: the documentation is pretty straightforward, with the Mac version of Excel I was able to update the template and uploaded it again back to the model-driven app.

Word templates are not possible to create with the Mac version of Word, as written inside the documentation, we need to use the XML Mapping pane (under the Developer tab) but this functionality is not available inside the Word for Mac, it's only available inside the Windows version:

I took this screenshot from Word installed inside the virtual machine (check the first post if you need to setup it), so no problems to use it with Windows 11 Arm64 edition.

It's a bummer I can't use Word for Mac for creating templates but the Mac Mini M4 is very fast, the virtual machine has only 4 GB of RAM and Word runs perfectly.
Also some customers use third party add-ons to generate documents inside the Power Platform instead of the standard Word templates.

December 21, 2024

Apple macOS and Dataverse Plugins

We've probably come to the topic that sooner or later every developer working with the old .NET Framework wonders: does it work on Mac?

As we saw in the previous posts the recent .NET versions are cross-platform and they work on Mac (like the one I have that is ARM based) but older .NET Framework versions (4.x) are meant to run on Windows.

Dataverse Plugins still require .NET Framework 4.6.2 (as stated in the tutorial), so what are our options?

Let's separate in three main topics:

  • Write the Plugin
  • Build the Plugin
  • Register the Plugin
Writing the Plugin is not an issue, technically we can use just a simple text editor to write the code but we have Visual Studio Code. In addition if we install the Microsoft Power Platform CLI (as we did for PCF development) we have a command to create a Plugin project:

pac plugin init

This command is very important for one reason, it creates the .snk file (signing file), as far as I know it's not possible to create the signing file inside Visual Studio Code as a standalone action.
After we can open the project folder we see a familiar structure:
This wireframe contains a PluginBase.cs file, for my tests I prefer to have a simpler structure, so I create my plugin classes implementing just the IPlugin interface.

Sample code:
using Microsoft.Xrm.Sdk;
using System;

namespace MacPlugins
{
public class Example1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
Entity currentEntity = null;
if (context.InputParameters.Contains("Target")
&& context.InputParameters["Target"] is Entity)
{
currentEntity = (Entity)context.InputParameters["Target"];

if (currentEntity != null &&
currentEntity.LogicalName != "account") { return; }
}
if (currentEntity == null) { return; }

string name = currentEntity.GetAttributeValue<string>("name");
currentEntity["name"] = $"{name} - UPDATED BY PLUGIN Example1";
}
}
}

We will register this plugin on the Create message of Account Pre-Operation, it will change the name to confirm the plugin is working.

We now have the project, how we build it?
Over the last few days I've been thinking about how to do this: virtual machine, creating something on Azure, etc etc.
Let's try first the simple approach: build it inside Visual Studio Code. I ran the command

dotnet build

and under the folder "bin/Debug/net462/publish" a dll file was created.
Ok, it compiled, but this dll is ok to be registered?

Let me be crystal clear: I will never register a plugin using the pac plugin push command, I wrote plugins and registered them using Plugin Registration Tool for over a decade, I know that on Mac I can't have the same experience as Windows but at least should be comparable, not a complete downgrade.

So I started the virtual machine (check the first post if you need to setup it), opened XrmToolBox and launched the Plugin Registration Tool. I selected the dll generated by Visual Studio Code on Mac and it worked, I was able to register it. I quickly added the step, I created an account and the plugin worked!

This result opens new questions:
  • How can I debug a Plugin?
  • How can I generate Early Bound classes?
  • What about Plugin Packages and Managed Identity Plugins?
Let me explain how I usually work: I rarely debug plugins (I tend to keep them short and I prefer to write a small console application with the logic and debug the console application instead of debugging the plugin directly) and I prefer to use late bound (sometimes I use the tool Latebound Constants Generator) instead early bound (sorry Daryl!).

If I have time I can explore these topics but they are not my priority.

The setup (building the plugin on Mac and registering them using Windows) works but it's not ideal.
What will solve this situation? Simple: a cross-platform version of the Plugin Registration Tool.
It does not exist today but I hope it will exist in the future ("in the fullness of time"?).

If you are familiar with Mac/Linux you may be aware of a software called WineHQ, I wanted to test if it can run the Microsoft Plugin Registration Tool or XrmToolBox itself. Sadly they do not, but was interesting and I discovered some insights.

First of all I tried the Microsoft Plugin Registration Tool, I downloaded the NuGet package, renamed it to a zip file and extracted the content. Tried to launch it with WineHQ and it doesn't load, patience.

After I copied the XrmToolBox folder from the virtual machine to Mac and launched it with WineHQ, it opens but it returns often a GDI+ error, plus it's not able to connect to Dataverse environments:

Note: if you download the zip folder from the site and launch it directly on WineHQ it doesn't work, so a copy of an already launched Windows folder is required, plus you will need to copy the content of the AppData folder inside a specific .wine folder.

The main issue for me is the connection to Dataverse, a Windows Forms application connecting to Dataverse can actually works with WineHQ?

I switched to Visual Studio 2022 on my Windows machine and I quickly created a Windows Forms application to connect with OAuth or with Client Id/Client Secret.

My first test was with .NET Framework 4.8.1 and the .NET 4.x CRM SDK, under WineHQ it's not able to connect.

My second test was with .NET Framework 4.8.1 and the Dataverse SDK, under WineHQ it's not able to connect.

My third test was with .NET 8 and the Dataverse SDK, WineHQ advised me I need to install .NET first (so I downloaded the runtime and launched it with WineHQ) and this time it worked:

So theoretically it's possible to build a version of XrmToolBox compatible with WineHQ, however this doesn't mean all the tools will work automatically without problems, it will depend on how the tool is written or if it uses some libraries not compatible with WineHQ.

I really hope Microsoft will build a Plugin Registration Tool that I can launch on a Mac because it's possible to do it.

Why I don't do it by myself? Because I know it takes time and honestly we cannot always ask the community to build something and maintain it. The developers behind the Plugin Registration Tool for XrmToolBox are already doing an amazing job for having such important tool inside XrmToolBox.

December 20, 2024

Apple macOS and the TDS endpoint

Part 4 about Mac Mini M4 and Power Platform, this time is about SQL and Dataverse.
Dataverse offers a way to access its data using SQL statements (read-only) by enabling the TDS endpoint.
The documentation shows how to use it with SQL Server Management Studio (SSMS) but this application is only for Windows.

The main reason I use the TDS endpoint is to run some queries (like a count or strange joins) and they are usually faster using SQL. For XrmToolBox there is SQL 4 CDS by Mark Carrington but for now I don't want to launch the virtual machine.

Lucky for us Microsoft has a cross-platform product with similar functionalities as SSMS:
Azure Data Studio
Just download the macOS Apple Silicon version and we are ready to go:

When connecting to the TDS endpoint the procedure requires to specify the database name, it's usually the same prefix of the server:

After the connection we can launch SQL queries and eventually save them in a Notebook:
I am sure SSMS offers different functionalities but for what I need Azure Data Studio is enough.

Before finishing, let's back a moment to SQL 4 CDS, did you know it is also available as Azure Data Studio plugin?
You can download the VSIX from the GitHub repository releases and it can be installed inside the Mac version of Azure Data Studio.
It requires .NET SDK 8 (for PCF development we installed .NET 9 SDK) so install it first (link) otherwise the extension will not work.

After the extension is installed we can create a new connection using SQL 4 CDS and run other commands like UPDATE:

It's nice to have this tool available also inside Azure Data Studio and I don't need to launch the virtual machine!

December 19, 2024

Apple macOS and Console Applications with Dataverse

Third episode with the Mac Mini M4, let's try to connect to Dataverse using a console application.
I like very much Visual Studio for Windows but the Mac version has been discontinued, details here: What happened to Visual Studio for Mac?
The alternative is Visual Studio Code (we used it for PCF development on the previous post) with the extension C# Dev Kit.
When you create a new project using this extension you get two default settings:
  • top level statements
  • implicit using
What it means? When you open the Program.cs file you see only the line

Console.WriteLine("Hello World!");

instead of the "classical" structure with the using statements and the Main method.

The top level statements can be turned off by showing the template options and there is a setting for it.
The implicit using can be disabled by removing the line
<ImplicitUsings>enable</ImplicitUsings>
inside the csproj file

After these two changes we get a more "familiar" structure, something like this:

using System;
namespace Test;
class Program
{
static void Main(string[] args)
{
}
}

Next step is to reference the Microsoft.PowerPlatform.Dataverse.Client NuGet package and write some code to execute the WhoAmI Message:

using System;
using Microsoft.Crm.Sdk.Messages;
using Microsoft.PowerPlatform.Dataverse.Client;
namespace Test;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello Dataverse!");

string userName = "guido.preite@___.it";
string url = "https://___.crm4.dynamics.com";
string connectionString = @$"AuthType='OAuth'; Username='{userName}'; Url='{url}';
AppId='51f81489-12ee-4a9e-aaae-a2591f45987d'; RedirectUri='http://localhost';
        LoginPrompt='Auto'";

ServiceClient service = new ServiceClient(connectionString);
WhoAmIResponse whoAmIResponse = (WhoAmIResponse)service.Execute(new WhoAmIRequest());

Console.WriteLine($"Connected with UserId: {whoAmIResponse.UserId}");
}
}

A screenshot with the result:

It's useful to know I can write a console application connecting to Dataverse, I may need to test some small logic or running some updates on a set of records, it's very common scenario for me to open the editor and launch this kind of code. Plus I can do this completely inside macOS without opening the Windows virtual machine.

December 18, 2024

Apple macOS and PCF Development

Second part about my journey with the new Mac Mini M4 (first post here) and surprise surprise is about PCF development!

I usually don't code PCF components because most of the time I can find the one I need inside PCF Gallery, there are more than 550 components listed there, so big kudos to all the authors.

PCF development usually brings people not familiar with Power Apps/Power Platform inside the ecosystem, when a new control is published inside PCF Gallery I don't ask where they developed it but I suppose someone used a Mac.

First piece is to install Visual Studio Code, it's cross platform, perfect.

To develop PCF controls we need two important components:

  • NPM
  • Microsoft Power Platform CLI (also knows as PAC CLI)
To install NPM there are several ways, I installed first Homebrew (remember to add to the path by using the commands listed after the installation) and after I launched the command brew install npm.

To install the Microsoft Power Platform CLI you can install this Visual Studio Code extension:
BUT before installing this extension you need to have the .NET SDK on your machine, otherwise you get an error.
The latest versions of .NET are cross platform, I installed the SDK Installer, macOS Arm64 version from the official site:

After the SDK, proceed to install the Power Platform Tools extension and we can verify the PAC CLI is installed by running inside the Visual Studio Code Terminal the command pac:


With NPM and PAC CLI we can now create a new PCF, just follow the Microsoft documentation for the right syntax:

Once you have the structure inside your Visual Studio Code you edit and test the PCF as usual, in my case I recreated my PCF Custom Url Control.

There is also a Microsoft documentation page on how to create a solution and package the PCF inside it:

Note: the path written inside the documentation is Windows style (c:\), as we are on Mac we need to use a different style, example:

pac solution add-reference --path /Users/username/folder

and because we have the .NET SDK installed we can use the command

dotnet build

this will create an unmanaged solution inside a debug folder, if you want a managed solution you can run the command

dotnet build -c release

Once you have the solution you can install it inside your environment and configure the PCF. A screenshot of my component inside a form:


I had no doubts I can create PCF controls with a Mac but to prepare the machine I needed some steps, however I had no problems by following the instructions I found from web searches and the Microsoft documentation.

What I will write inside the next episode? I don't know yet!

December 17, 2024

Apple macOS and Power Platform - Introduction

After watching numerous YouTube videos about the new Mac Mini M4 I decided to buy it, here a photo beside my mouse:
It's not my first Apple computer, I have a MacBook Air 2012 that I still use these days for browsing and of course I am a bit locked inside the ecosystem with my iPhone.

The majority (if not all) of the videos and articles about the new Mac Mini M4 is about editing videos, games and general productivity. All the reviews are ok but I wanted to know how this machine performs for MY work, considering I spend several hours with Visual Studio 2022.

I bought the basic model (16 GB of RAM and 256 GB of storage) for two reasons:
  • It's the entry level (so the cheapest model)
  • RAM is not expandable, so I want to know if they are enough or not (because RAM on these machines is expensive)
First of all: all the activities where only a browser is required works perfectly (basic tasks like modifying a table or adding a column) but I am sure everybody knows this.

Which is the first tool I need for my Power Platform activities? Of course XrmToolBox!

Let's go technical, this new Mac Mini M4 is an ARM machine and the current virtualization technology only allows (with decent performance) to run Windows 11 Arm edition, let's try it.

There are several virtualization software: Parallels, VMware and VirtualBox.
I like and use VirtualBox on Windows but I am not convinced of its performances about Windows 11 Arm.
I use Parallels but it's a paid product, I already spent money to buy the machine, let's skip it for now.
VMware offers a free version of VMware Fusion Pro, so I decided to use it.
You can follow this YouTube video: https://www.youtube.com/watch?v=LWXO4DhQRL0
Note: the download page is a bit different now, you need to download the latest version of the software and when you run the setup you get prompted to obtain the free version (some of the comments in the video are about this step).
The video also provides the step to install Windows 11, so it was perfect for me.

After I completed the installation, the question is: will XrmToolBox works?
And the answer is YES!

I quickly downloaded some tools (the one I used the most), in particular:
  • FetchXML Builder by Jonas Rapp (the most downloaded tool)
  • Plugin Registration Tool (a must for the work I do)
  • Custom API Manager by David Rivard (I am an avid user of this tool)
  • Ribbon Workbench by Scott Durow (still required sometimes)
  • Dataverse REST Builder by me
I don't know if they work 100% of the cases but I didn't experience crashes and also Ribbon Workbench that is still using the old Internet Explorer engine works under Windows 11 Arm.
My tool uses the WebView2 component (based on Edge) so I also wanted to know if it works as well.

The virtual machine to run Windows 11 Arm is configured with only 4 GB of RAM (Windows and XrmToolBox works fine), the used RAM in the moment I am writing is around 12 GB but I have several apps opened (including Teams for Mac occupying 800 MB and Google Chrome taking 1 GB), with only the Virtual Machine opened you use 8/9 GB total of RAM. In my opinion 16 GB of RAM to use XrmToolBox inside a Virtual Machine are enough, my goal is not to use the Virtual Machine for everything (I don't plan to install Visual Studio 2022 inside it) but only for the apps I cannot use directly on macOS.

I will be able to use this new Mac for everything? Let's see in the next episodes!