[英]Can I use dynamic in a .NET Standard class library?
I'm having a hard time trying to migrate from a regular Windows desktop development to ASP.NET Core MVC.我很难从常规的 Windows 桌面开发迁移到 ASP.NET Core MVC。 One issue I'm coming across is to create my solution.
我遇到的一个问题是创建我的解决方案。 I would like to remove everything that is not UI related from the default project that ships with VS 2015 and put into a separate project.
我想从 VS 2015 附带的默认项目中删除与 UI 无关的所有内容,并将其放入单独的项目中。
I noticed that ASP MVC Core references to .NETCoreApp
and the Class Library project references to .NETStandard
.我注意到到ASP MVC核心引用
.NETCoreApp
和类库项目引用.NETStandard
。
My problem is that I need to use the dynamic
keyword in the class library and it does not support it.我的问题是我需要在类库中使用
dynamic
关键字并且它不支持它。 The MVC project supports without any problem. MVC 项目支持没有任何问题。 I guess it's because of the different .NET versions.
我想这是因为不同的 .NET 版本。
What is the difference between NETStandard and NETCoreApp? NETStandard 和 NETCoreApp 有什么区别?
Can I create a class library that uses the same reference as the MVC project so I can use the dynamic keyword on it?我可以创建一个使用与 MVC 项目相同的引用的类库,以便我可以在其上使用 dynamic 关键字吗?
Or should I stick with a one project solution with all domain, infrastructure, etc in the same place?或者我应该坚持使用一个项目解决方案,将所有域、基础设施等放在同一个地方?
Yes, it's possible to put non-UI code into a separate library.是的,可以将非 UI 代码放入单独的库中。 As you guessed,
netcoreapp1.0
is for applications (console or web), and netstandard1.X
is for class libraries.如您所料,
netcoreapp1.0
用于应用程序(控制台或 Web),而netstandard1.X
用于类库。
A .NET Standard class library shouldn't have any problem with the dynamic
keyword. .NET Standard 类库的
dynamic
关键字应该没有任何问题。 You do need to reference NETStandard.Library
, though.不过,您确实需要引用
NETStandard.Library
。 Here's a barebones working library example:这是一个准系统工作库示例:
MyLibrary/project.json我的图书馆/project.json
{
"description": "My awesome library",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.3": { }
}
}
Your ASP.NET Core web application can reference this library if it's part of the same solution like this:如果您的 ASP.NET Core Web 应用程序属于相同解决方案的一部分,则它可以引用此库,如下所示:
{
(... other stuff)
"dependencies": {
"MyLibrary": {
"target": "project"
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.