这是我的样本:
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年的Developer Command提示符):
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的链接
Assemblies:Windows.Networking.Vpn.dll,Windows.dll
发布于 2019-07-06 07:48:12
您要寻找的类型在Windows运行时元数据文件中定义,并在本机代码中实现。您需要引用winmd,有一些快捷方式(比如引用安装在操作系统中的元数据),但这会使您的项目变得脆弱。通常,您需要引用已安装的SDK版本。您可以使用VS命令提示符中的路径变量来提供一些帮助,例如(使用17763 SDK):
csc Program.cs \
-reference:"%WindowsSdkDir%\References\%WindowsSdkVersion%\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd" \
-reference:"%WindowsSdkDir%\References\%WindowsSdkVersion%\Windows.Foundation.UniversalApiContract\7.0.0.0\Windows.Foundation.UniversalApiContract.winmd"
但是,随着SDK的升级,这些路径中的契约版本号将发生变化,因此仍然存在一些脆性。VS项目系统从"%WindowsSdkDir%\Platforms\UAP\%WindowsSdkVersion%\Platform.xml“或"%WindowsSdkDir%\Platforms\UAP\%WindowsSdkVersion%\PreviousPlatforms.xml”读取当前合同,以获得目标操作系统版本的正确API信息。
https://stackoverflow.com/questions/56910056
复制相似问题