You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio 2017中连接Dataverse?替代方案咨询

无需升级Visual Studio 2017连接Dataverse的方案

1. 直接使用Dataverse .NET SDK编码连接

你不需要依赖Visual Studio插件,通过NuGet安装官方SDK包就能直接在VS2017中编写连接和插入逻辑:

  • 打开VS2017的NuGet包管理器,搜索并安装 Microsoft.PowerPlatform.Dataverse.Client(推荐的最新SDK版本)或旧版的 Microsoft.CrmSdk.CoreAssemblies
  • 以下是基础的连接和数据插入示例代码:
using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.Xrm.Sdk;
using System;

class Program
{
    static void Main(string[] args)
    {
        // 替换为你的Dataverse实例连接信息
        string connectionString = "AuthType=OAuth;Url=https://your-org.crm.dynamics.com;Username=your-user@domain.com;Password=your-password;AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;RedirectUri=app://58145B91-0C36-4500-8554-080854F2AC97";

        using (var serviceClient = new ServiceClient(connectionString))
        {
            if (serviceClient.IsReady)
            {
                // 构造要插入的实体数据(替换为你的表和字段逻辑名称)
                Entity newRecord = new Entity("your_entity_logicalname");
                newRecord["your_field_logicalname"] = "测试导入数据";
                newRecord["createon"] = DateTime.Now;

                Guid recordId = serviceClient.Create(newRecord);
                Console.WriteLine($"数据插入成功,记录ID: {recordId}");
            }
            else
            {
                Console.WriteLine($"连接失败: {serviceClient.LastError}");
            }
        }
    }
}

注:连接字符串中的AppId可使用官方公共客户端ID(示例中已提供),也可注册自己的Azure AD应用获取。

2. 使用Power Apps CLI生成早期绑定实体类

Power Apps CLI是独立命令行工具,不依赖特定VS版本,可用来生成Dataverse实体的强类型类,再导入VS2017项目使用:

  • 下载安装Power Apps CLI(无需Visual Studio)
  • 打开命令行,登录你的Dataverse组织:
    pac auth create --url https://your-org.crm.dynamics.com
    
  • 生成指定实体的类文件:
    pac modelbuilder build --entitynamesfilter "your_entity_logicalname" --outfile "YourEntity.cs"
    
  • 将生成的YourEntity.cs添加到VS2017项目中,配合SDK包使用强类型语法操作数据,类型安全性更高。

3. 晚期绑定快速操作(无需实体类)

如果不需要强类型支持,可直接用Entity类进行晚期绑定操作,只需知晓表和字段的逻辑名称即可,适合简单场景或快速开发,参考第一个示例中的实体构造逻辑即可。

内容的提问来源于stack exchange,提问作者JasonYeung

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 02:20:15