首页 > 解决方案 > Nuget 问题:接口一直引用旧版本

问题描述

我正在运行一个解决方案,其中使用了多个 nuget 包。在我的“域”nuget 中,我指定了以下接口:

(在文件:ecnuget.domain中,nuget 版本设置为1.0.10):

    public interface IItemPriceStore
    {
        Task<bool> AddPriceUpdateAsync(PriceUpdate priceUpdate);

        Task<bool> InitializeAsync();

        Task<IEnumerable<PriceUpdate>> GetByItemName(string itemName);
    }

最后两种方法在 nuget 包的 1.0.7 版本中不存在,但它们是在相同的 1.0.10 版本中添加的。

现在,在一个实现中,我更新了对版本 1.0.10 的引用,并且预计会看到构建错误,因为 ItemPriceStore 类还没有实现这两个新方法,但是它仍然可以构建!当我 F12 界面时,我看到:

#region Assembly ecnugget.domain, Version=1.0.7.0, Culture=neutral, PublicKeyToken=null
// C:\Users\pedro\.nuget\packages\ecnugget.domain\1.0.10\lib\netcoreapp3.1\ecnugget.domain.dll
#endregion

using digitaldias.ec.domain.Entities;
using System.Threading.Tasks;

namespace digitaldias.ec.domain.Contracts.Writers
{
    public interface IItemPriceStore
    {
        Task<bool> AddPriceUpdateAsync(PriceUpdate priceUpdate);
    }
}

而且我一生都无法弄清楚为什么或什么引用了旧的 1.0.7 版本。我尝试过的事情:

我已经通过重新启动 Visual Studio 完成了所有这些操作,甚至关闭了所有 Visual Studio 实例。

我的 .csproj 只引用了这个包的 1.0.10 版本,然而,由于某种神秘的原因,当我构建时,它一直在创建对 1.07 版本的元数据引用。我无法为我的生活找出引用 1.0.7 的位置。我在任何源文件中都找不到它!

这是我当前实现接口的 .csproj 中的引用:

    <ItemGroup>      
      <PackageReference Include="ecnugget.domain" Version="1.0.10" />      
      <PackageReference Include="PubSub" Version="4.0.1" />
      <PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
    </ItemGroup>

希望有人有同样的经验,可以帮助我。

标签: c#nugetvisual-studio-2019

解决方案


只是一个提示,请参阅此线程

尝试启用自动绑定重定向。将此添加到您的 .csproj 文件中

<PropertyGroup>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

推荐阅读