[英]Referencing libraries in .NET Framework not in .NET Standard
I'm currently in progress of migrating a class library project to dotnet cli (RC2) from DNX (RC1). 我目前正在从DNX(RC1)将类库项目迁移到dotnet cli(RC2)。 Previously, the project referenced the .NET v4.5.1 framework libraries, and the
project.json
file looks like this: 以前,该项目引用了.NET v4.5.1框架库,而
project.json
文件如下所示:
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": "4.0.10.0",
"System.Web": "4.0.0.0",
"System.DirectoryServices": "4.0.0.0",
"System.DirectoryServices.AccountManagement": "4.0.0.0",
"System.ServiceModel": "4.0.0.0",
"System.ServiceModel.Security": "4.0.0.0"
}
}
}
Now as far as I'm aware, (and I could be wrong,) unlike DNX, the new dotnet Cli doesn't support .NET 4.5.1, and instead supports .NET Standard. 现在据我所知,(我可能错了),与DNX不同,新的dotnet Cli不支持.NET 4.5.1,而是支持.NET Standard。
So problem is, .NET Standard doesn't have all the libraries I want. 问题是,.NET Standard没有我想要的所有库。 What do I have to change so I can reference the .NET 4.5.1 framework libraries?
我需要更改什么才能引用.NET 4.5.1框架库? I read about the imports statement, but I can't get it to work.
我读到了有关进口声明的内容,但我无法让它发挥作用。 Here is what I have so far (updated) :
这是我到目前为止(更新) :
"frameworks": {
"net451": {
"frameworkAssemblies": {
"System.Runtime": "4.0.10.0",
"System.Web": "4.0.0.0",
"System.DirectoryServices": "4.0.0.0",
"System.DirectoryServices.AccountManagement": "4.0.0.0",
"System.ServiceModel": "4.0.0.0",
"System.ServiceModel.Security": "4.0.0.0"
}
},
"netstandard1.5": {
"imports": [ "dnxcore50", "portable-net451+win8" ]
}
}
I get errors such as this: 我得到这样的错误:
I am a bit lost on what else I need to do... Any ideas? 我有点失去了我还需要做什么...有什么想法吗?
dotnet
supports net451
. dotnet
支持net451
。 Here's an example of application that has both net451
and netstandard
. 这是一个同时
net451
和netstandard
的应用程序netstandard
。
If you app was running on full desktop in RC1, there should be not problem migrating it to full desktop in RC2. 如果您的应用程序在RC1中的完整桌面上运行,那么在RC2中将其迁移到完整桌面应该没有问题。
Try rolling with netcoreapp1.0
instead of netstandard1.5
. 尝试使用
netcoreapp1.0
而不是netstandard1.5
。
The new RC2 templates generate the following project.json
framework element (by default): 新的RC2模板生成以下
project.json
框架元素(默认情况下):
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"dnxcore50",
"portable-net45+win8"
]
}
},
There's a little discussion about this on GitHub . 在GitHub上对此有一点讨论。 To quote richlander:
引用richlander:
- netstandard -> NETStandard.Library (this is expected to work on all .NET
netstandard - > NETStandard.Library(预计这适用于所有.NET
- netstandardapp -> NETStandard.App (same as NETStandard.Library + app hosts)
netstandardapp - > NETStandard.App(与NETStandard.Library + app hosts相同)
- netcoreapp -> Microsoft.NETCore.App (this is the .NET Core base install)
netcoreapp - > Microsoft.NETCore.App(这是.NET Core基础安装)
Check on the .NET Platform Standard documentation on GitHub. 查看GitHub上的.NET Platform Standard文档 。
The netstandard1.5
target moniker targets .NET 4.6.2, which means you can't run it with .NET 4.5.1 projects. netstandard1.5
目标名字对象是.NET 4.6.2,这意味着您无法使用.NET 4.5.1项目运行它。
The correct moniker to target .NET 4.5.1 and above is netstandard1.2
. 以.NET 4.5.1及更高版本为目标的正确名字是
netstandard1.2
。
In essence, the target moniker tells you which framework is the lowest supported. 本质上,目标名字对象告诉您哪个框架是最低支持的。 The lower the supported frameworks, the more of them you can target with a single moniker w/o the need of conditional preprocessor directives.
支持的框架越低,您可以使用单个名字对象进行定位,而不需要条件预处理程序指令。
But also, the lower the target moniker, the less of the newer features won't be available (ie Task.CompletedTask
). 但是,目标名字对象越低,新功能就越少(即
Task.CompletedTask
)。
When you need to target a older framework and want to use new functionality you have to use multiple targets, ie netstandard1.2
which uses the old api and netstandard1.3
that uses the .NET 4.6+ Api and use conditional preprocessor directives to use new Api calls in a specific target. 当您需要定位旧框架并希望使用新功能时,您必须使用多个目标,即
netstandard1.2
,它使用旧的api和netstandard1.3
,它使用.NET 4.6+ Api并使用条件预处理程序指令来使用新的Api呼叫特定目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.