Gra*_*ler 9 nuget asp.net-core asp.net-core-2.0 .net-standard-2.0
据我所知,.Net Core 2有一个兼容性垫片,允许它使用不专门针对.Net Core/Standard 2的Nuget包.这使它可以访问70%的Nuget.很棒 - 很棒的功能.
如何防止安装与.Net Core 2/.Net Standard 2不完全兼容的nuget软件包?或者在安装时告诉我它是否与垫片一起使用?
我创建了一个新的.Net Core 2.0项目,安装了EF 6.1.3(我知道它不起作用)并且没有任何阻止我或警告它在安装时没有以.Net Standard <= 2为目标.
我很高兴"用剪刀跑"但我觉得在将MVC5和EF 6.1.3安装到.Net Core 2应用程序之前我应该收到警告.我真的想阻止初级开发人员安装不受支持的软件包等.
我想Matt Ward的回答是 - 我的主要观点是 - 可以检测到某些东西在安装时实际上是100%兼容的,或者我们总是只是在需要自己确定包装"足够好"的情况下.我希望有一个技术机制可以检测到覆盖API覆盖范围,并且可以告诉我们nuget包可能不像以前那样运行.所以我想MS说70%的兼容性 - 如果我尝试安装30%,我想失败
将Entity Framework 6.1.3安装到.NET Core 2.0项目中的错误窗口中有一个NU1701警告,指出正在使用.NET Framework 4.6.1还原的Entity Framework 6.1.3并且它可能不完全兼容.
您可以将NU1701警告变为项目中的错误,因此您无法安装任何未明确支持.NET Core 2.0的NuGet软件包.这可以通过将WarningAsErrors属性添加到项目来完成.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<WarningsAsErrors>NU1701</WarningsAsErrors>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
然后,如果您尝试安装Entity Framework 6.1.3,则还原将失败,更改将被回滚,并且将不会安装NuGet包.
您还可以将DisableImplicitAssetTargetFallback属性设置为true,这将阻止将.NET 4.6.1添加到AssetTargetFallback属性,该属性在检查NuGet包与.NET Core 2.0项目的兼容性时使用.
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<DisableImplicitAssetTargetFallback>true</DisableImplicitAssetTargetFallback>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
If you wan to be 100% sure, run the package against .NET Portability Analyzer and .NET Standard 2.0 profile.
It won't tell you if the API will be called or not (and is in no way an automatic process), just if the Assembly contains any API which is not .NET Standard 2.0 compatible.
However, you can also only run your application against the Analyzer, as the .NET Portability Analyzer should be able to follow any references made from the application and check these too.
You can als build this into your build server pipeline, to get a more automatic guarantees.
The .NET Portability Analyzer Docs.
Visual Studio is not required for this, just download it from https://github.com/Microsoft/dotnet-apiport/releases and run
From the docs:
- Type the following command to analyze the current directory:
\...\ApiPort.exe analyze -f .- To analyze a specific list of .dll files, type the following command:
\...\ApiPort.exe analyze -f first.dll -f second.dll -f third.dll
未经测试,但尝试一下:
<!-- old dotnet tooling/.NET Core 1.x -->
<PackageTargetFallback>netstandard2.0;portable-net45+win8</PackageTargetFallback>
<!-- new dotnet tooling/.NET Core 2.0 -->
<AssetTargetFallback>netstandard2.0;portable-net45+win8</AssetTargetFallback>
Run Code Online (Sandbox Code Playgroud)
通常你想要它像
<!-- old dotnet tooling/.NET Core 1.x -->
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
<!-- new dotnet tooling/.NET Core 2.0 -->
<AssetTargetFallback>$(AssetTargetFallback);dotnet5.6;portable-net45+win8</AssetTargetFallback>
Run Code Online (Sandbox Code Playgroud)
where$(PackageTargetFallback)将告诉 MSBuild 保留旧值并将其后的值附加到它。但由于$(PackageTargetFallback)可能(现在无法更深入地查看/挖掘)那里有 .NET Framework 名称,因此您将用自己的值覆盖它。
鉴于PackageTargetFallback现在已弃用,人们应该使用AssetTargetFallback它。
| 归档时间: |
|
| 查看次数: |
922 次 |
| 最近记录: |