首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >试图从cmd编译时找不到元数据文件。

试图从cmd编译时找不到元数据文件。
EN

Stack Overflow用户
提问于 2019-07-05 23:14:14
回答 1查看 604关注 0票数 0

这是我的样本:

代码语言:javascript
运行
复制
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提示符):

代码语言:javascript
运行
复制
csc program.cs /r:Windows.Networking.Vpn.dll

下面是我安装的工具包的屏幕截图:

这是我的输出:

代码语言:javascript
运行
复制
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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-06 07:48:12

您要寻找的类型在Windows运行时元数据文件中定义,并在本机代码中实现。您需要引用winmd,有一些快捷方式(比如引用安装在操作系统中的元数据),但这会使您的项目变得脆弱。通常,您需要引用已安装的SDK版本。您可以使用VS命令提示符中的路径变量来提供一些帮助,例如(使用17763 SDK):

代码语言:javascript
运行
复制
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信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56910056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档