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>
<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.
0 comments:
Post a Comment