本文介绍了Microsoft.AspNetCore.App-版本控制/是否应在非ASP.NET类库中引用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找出使用Microsoft.AspNetCore.App元包的正确方法。



Visual Studio在构建我不应该指定的报告时

 < PackageReference Include = Microsoft.AspNetCore.App Version =  2.2.1 /> 

所以我将以上内容替换为:

 < PackageReference Include = Microsoft.AspNetCore.App /> 

下一个问题是,我的项目所依赖的任何类库项目或软件包都包含对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 />

所以我也删除了这些引用的版本:

 < PackageReference Include = Microsoft.Extensions.Configuration /> 
< PackageReference Include = Microsoft.Extensions.Configuration.Json />
< PackageReference Include = Microsoft.Extensions.Options.ConfigurationExtensions />

现在当我运行 dotnet restore 时,我看到警告:

 < Project>没有为依赖项
Microsoft.Extensions.Configuration提供包含范围的下限。解决了
Microsoft.Extensions.Configuration 1.0.0的最佳匹配问题。

因此,现在可以构建该应用程序,但是正在解决旧的且可能已过时的软件包版本。 / p>

维护所有这些软件包的下限版本似乎有些开销。



阻力最小的途径似乎是仅引用Microsoft.AspNetCore.App软件包(未版本化)来代替meta软件包中包含的任何软件包。 。但是我隐式地引用了很多不必要的东西(目前有150个软件包)。我可能想在不面向Web的项目中重用类库,因此所有引用的包似乎效率低下。另外,我是否认为Microsoft.AspNetCore.App的较新版本在将来构建时会破坏我的应用程序?

解决方案

我认为您可能希望遵守



这是我正在从事的项目,我必须明确引用某些程序包(要获取ActionResults,我必须添加2个特定引用。):





使用NuGet表示法可以在需要时提供细粒度的库,或者通过范围/通配符API更新来保证面向未来的模块化,或者可以引用完整的工具包和cabo​​odle。


I'm trying to work out the correct way of using the Microsoft.AspNetCore.App meta package.

Visual Studio on building reports that I shouldn't specify a version for the Microsoft.AspNetCore.App meta package.

<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.

<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:

<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. But then I'm implicitly referencing a lot of unnecessary stuff (150 packages at present). 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. Also, am I right in thinking that newer versions of Microsoft.AspNetCore.App could break my app when I build in the future?

解决方案

I think you might want to observe the NuGet Version ranges and wildcards notation.

When referring to package dependencies, NuGet supports using interval notation for specifying version ranges, summarized as follows:

+-----------+---------------+-------------------------------------------------------+
| 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:

<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1" />

Ref: How to correct dotnet restore warning NU1604, does not contain an inclusive lower bound?

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:

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.):

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.

这篇关于Microsoft.AspNetCore.App-版本控制/是否应在非ASP.NET类库中引用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 20:18