简体   繁体   English

如何在 dynamics c# 插件中使用 google lib-phonenumbers

[英]How to use google lib-phonenumbers in dynamics c# plugin

For validating and formatting phone numbers with a plugin, I'd like to use google's libphonenumber-csharp package. When I download this in the NuGet Package Manager, I first get the error that the package is not strongly signed (which is the case).为了使用插件验证和格式化电话号码,我想使用谷歌的 libphonenumber-csharp package。当我在 NuGet Package 管理器中下载它时,我首先得到的错误是 package 没有强签名(就是这种情况) . Once I use for example BrutalDev strong signer, to ensure the package is strongly signed, or use the strongsigned variant 'libphonenumber-csharp-portable', and the following code一旦我使用例如 BrutalDev 强签名者,以确保 package 被强签名,或者使用强签名变体'libphonenumber-csharp-portable',以及以下代码

using PhoneNumbers;
PhoneNumberUtil phoneUtil = PhoneNumberUtil.GetInstance();

I get the following error:我收到以下错误:

Could not load file or assembly 'libphonenumber-csharp-portable, Version=4.10.0.62, Culture=neutral, PublicKeyToken=ff8820ca68ac9de8' or one of its dependencies.无法加载文件或程序集“libphonenumber-csharp-portable,Version=4.10.0.62,Culture=neutral,PublicKeyToken=ff8820ca68ac9de8”或其依赖项之一。 The system cannot find the file specified.该系统找不到指定的文件。

Apparently, the company that made the plugin (code) that I want to reuse, merged DLL's to include this third-party library.显然,制作我想重用的插件(代码)的公司合并了 DLL 以包含这个第三方库。

Is this the way to go to use this package in Dynamics Plugins, or does anyone else have other recommandations on how to make this work?这是 go 在 Dynamics 插件中使用这个 package 的方式,还是其他人对如何使这项工作有其他建议? And, can onyone share how to properly merge DLL's, its benefits and risks?而且,任何人都可以分享如何正确合并 DLL,它的好处和风险吗?

You should add it as a NuGet package(project>dependencies>packages no need to define with using), the version I used is 8.10.10 with .net6.您应该将其添加为 NuGet 包(project>dependencies>packages 无需使用 using 定义),我使用的版本是 8.10.10 with .net6。 sample usage:示例用法:

        var phoneNumberUtil = PhoneNumbers.PhoneNumberUtil.GetInstance();
        if (!PhoneNumbers.PhoneNumberUtil.IsViablePhoneNumber(input.From))
            return result;
        var phoneNumber = phoneNumberUtil.Parse(input.From, null);
        result.PhonePrefix = phoneNumber.CountryCode;
        result.Number = phoneNumber.NationalNumber;
        result.CountryCode = phoneNumberUtil.GetRegionCodeForCountryCode(phoneNumber.CountryCode);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM