[英]Microsoft.AspNetCore.App - Versioning / Should it be referenced in non ASP.NET class libraries?
I'm trying to work out the correct way of using the Microsoft.AspNetCore.App meta package. 我正在尝试找出使用Microsoft.AspNetCore.App元数据包的正确方法。
Visual Studio on building reports that I shouldn't specify a version for the Microsoft.AspNetCore.App meta package. 构建报表时,Visual Studio不应指定Microsoft.AspNetCore.App元包的版本。
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.1" />
So I replace the above with: 所以我用上面的代替:
<PackageReference Include="Microsoft.AspNetCore.App" />
The next issue is that any class library projects or packages that my project depends on that contain versioned references to packages that are also included in the Microsoft.AspNetCore.App metapackage break the build because there is a version conflict. 下一个问题是我的项目所依赖的任何类库项目或包都包含对Microsoft.AspNetCore.App元数据包中包含的包的版本化引用,因为存在版本冲突,会破坏构建。
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" />
So I remove the versions on these references too: 所以我也删除了这些引用上的版本:
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
Now when I run dotnet restore
, I see a warning: 现在当我运行
dotnet restore
,我看到一个警告:
<Project> does not provide an inclusive lower bound for dependency
Microsoft.Extensions.Configuration. An approximate best match of
Microsoft.Extensions.Configuration 1.0.0 was resolved.
So now the app builds, but an old and possibly out of date package version is being resolved. 所以现在应用程序构建,但旧的,可能已过时的软件包版本正在解决。
It seems like a bit of an overhead to maintain lower bound versions for all of these packages. 维护所有这些软件包的下限版本似乎有点开销。
The path of least resistance seems like it might be to just reference the Microsoft.AspNetCore.App package (unversioned) in place of any packages that are contained within the meta package. 最小阻力的路径似乎只是引用Microsoft.AspNetCore.App包(无版本)代替元包中包含的任何包。 But then I'm implicitly referencing a lot of unnecessary stuff (150 packages at present).
但后来我隐含地引用了许多不必要的东西(目前有150个包)。 I might want to reuse the class library in a project that is not web facing and so all of the referenced packages seem like inefficient bloat.
我可能希望在不面向Web的项目中重用类库,因此所有引用的包似乎都是低效的膨胀。 Also, am I right in thinking that newer versions of Microsoft.AspNetCore.App could break my app when I build in the future?
另外,我认为较新版本的Microsoft.AspNetCore.App可能会在我未来构建时破坏我的应用程序吗?
I think you might want to observe the NuGet Version ranges and wildcards notation. 我想你可能想要观察NuGet版本范围和通配符表示法。
When referring to package dependencies, NuGet supports using interval notation for specifying version ranges, summarized as follows: 在引用包依赖关系时,NuGet支持使用区间符号来指定版本范围,总结如下:
+-----------+---------------+-------------------------------------------------------+
| Notation | Applied rule | Description |
+-----------+---------------+-------------------------------------------------------+
| 1.0 | x ≥ 1.0 | Minimum version, inclusive |
| (1.0,) | x > 1.0 | Minimum version, exclusive |
| [1.0] | x == 1.0 | Exact version match |
| (,1.0] | x ≤ 1.0 | Maximum version, inclusive |
| (,1.0) | x < 1.0 | Maximum version, exclusive |
| [1.0,2.0] | 1.0 ≤ x ≤ 2.0 | Exact range, inclusive |
| (1.0,2.0) | 1.0 < x < 2.0 | Exact range, exclusive |
| [1.0,2.0) | 1.0 ≤ x < 2.0 | Mixed inclusive minimum and exclusive maximum version |
| (1.0) | invalid | invalid |
+-----------+---------------+-------------------------------------------------------+
So instead of removing the Version property altogether use a range or wildcard, eg: 因此,不要删除Version属性,而是使用范围或通配符,例如:
Minimum version, inclusive
最低版本,包括在内
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1" />
Ref: How to correct dotnet restore warning NU1604, does not contain an inclusive lower bound? 参考: 如何更正网络还原警告NU1604,不包含包含下限?
It takes some configuring and I hope Microsoft sort all this out in RTM 3.0 with a wizard to update the dependency tree... Here's a project from 6 months ago it contains a reference to Microsoft.AspNetCORE.Mvc
: 它需要一些配置,我希望微软在RTM 3.0中对这一切进行排序,并使用向导更新依赖树...这是一个项目,从6个月前开始,它包含对
Microsoft.AspNetCORE.Mvc
的引用:
Here's a project I'm working on and I had to explicitly reference certain packages (to get ActionResults I had to add 2 specific references.): 这是我正在研究的项目,我必须明确引用某些包(要获得ActionResults,我必须添加2个特定的引用。):
Using the NuGet notation allows finely grained libraries when you need it, or future-proof modularity with range/wildcard API updates or you can reference the full kit and caboodle. 使用NuGet表示法可以在需要时使用细粒度的库,或者使用范围/通配符API更新的未来模块化模块,或者您可以参考完整的工具包和caboodle。
It appears the answer is in the replies. 似乎答案在答复中。 Choose one of these strategies:
选择以下策略之一:
Don't reference Microsoft.AspNetCore.App
meta-package but instead reference the specific packages that you need. 不要引用
Microsoft.AspNetCore.App
元数据包,而是引用您需要的特定软件包。 Best for distributed libraries. 最适合分布式库。
Reference Microsoft.AspNetCore.App
with a specific version, and ensure this version is the same throughout the entire solution. 引用具有特定版本的
Microsoft.AspNetCore.App
,并确保整个解决方案中的此版本相同。 It requires that you own the entire stack, so it's probably only helpful for monoliths with many dependent projects in a single solution. 它要求您拥有整个堆栈,因此它可能仅对单个解决方案中具有许多依赖项目的整体块有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.