这是我的示例:
using System;
using Windows.Networking.Vpn;
static void main()
{VpnManagementAgent mgr = new VpnManagementAgent();
VpnNativeProfile profile = new VpnNativeProfile() { AlwaysOn = false,
NativeProtocolType = VpnNativeProtocolType.L2tp,
ProfileName = "MyConnection",
RememberCredentials = true, RequireVpnClientAppUI = true,
RoutingPolicyType = VpnRoutingPolicyType.SplitRouting,
TunnelAuthenticationMethod = VpnAuthenticationMethod.PresharedKey,
UserAuthenticationMethod = VpnAuthenticationMethod.Mschapv2, };
profile.Servers.Add("vpn.example.com");
VpnManagementErrorStatus profileStatus = await mgr.AddProfileFromObjectAsync(profile);
Console.WriteLine($"{profileStatus}\n"); }
这是我尝试编译的方式(来自 VS 2019 的开发人员命令提示符):
csc program.cs /r:Windows.Networking.Vpn.dll
这是我安装的工具包的截图:
这是我的输出:
Microsoft (R) Visual C# Compiler version 3.100.119.28106 (58a4b1e7)
Copyright (C) Microsoft Corporation. All rights reserved.
error CS0006: Metadata file 'Windows.Networking.Vpn.dll' could not be found
这是来自msdn的链接:
程序集:Windows.Networking.Vpn.dll、Windows.dll