减少 .net 中的包依赖性 core/standard

Reducing Package Dependencies in .net core/standard

我正在尝试将我在 VS2015/.net core 中构建的一些库升级到 VS2017。虽然 project.json > *.csproj 转换进行得相当顺利,但我在尝试使我的库不依赖于完整框架而仅依赖于我真正需要的包时遇到了麻烦。

我之前所做的记录在 https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/reducing-dependencies

一切正常。升级后,我的"Dependencies"安装了SDK nuget,无法删除。

Project.csproj 包含以下内容:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <AssemblyTitle>DDS.Core.Commons.Annotations</AssemblyTitle>
        <VersionPrefix>17.03.08.1526</VersionPrefix>
        <TargetFrameworks>netstandard1.6;net46</TargetFrameworks>
        <AssemblyName>DDS.Core.Commons.Annotations</AssemblyName>
        <PackageId>$(AssemblyName)</PackageId>
        <RootNamespace>DDS.Core.Commons.Annotations</RootNamespace>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
        <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
        <DebugType>full</DebugType>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
        <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
        <PublicSign>true</PublicSign>
        <DebugType>portable</DebugType>
        <GenerateDocumentationFile>true</GenerateDocumentationFile>
        <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    </PropertyGroup>
</Project>

为简洁起见,我省略了一些属性(描述、作者等)。

现在有人知道如何实现上述目标吗?提前致谢。

可以设置

<PropertyGroup>
    <DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
</PropertyGroup>

在您的 .csproj 中。这告诉 SDK 不要隐式引用 NETStandard.Library 或 Microsoft.NETCore.App。