本文介绍了为什么 ServiceStack.Text 没有被复制到 Bin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已通过 Nuget 将 ServiceStack.Redis 添加到我拥有的程序集中.该包依赖于 ServiceStack.Common,后者依赖于 ServiceStack.Text

I have added ServiceStack.Redis via Nuget to an assembly that I have. That package has a dependency on ServiceStack.Common which has a dependency on ServiceStack.Text

这个项目是从我的 web 项目中引用的,但是当我构建网站并在浏览器中加载它时,我收到错误

this project is referenced from my web project, but when I build the Website and load it in a browser I get the error

无法加载文件或程序集ServiceStack.Text, Version=3.9.24.0, Culture=neutral, PublicKeyToken=null"或其依赖项之一.系统找不到指定的文件.

果然,当我转到我网站的 Bin 目录时,它不在那里.奇怪的是,如果我转到我引用的类库的 Bin 目录(我将 Nuget 包拉入的那个),它就在那里.

Sure enough, when I go to the Bin directory of my website it isn't there. Oddly enough, if I go to the Bin directory of the class library I am referencing (the one I pulled the Nuget package into) it IS there.

总结

  • 类库
    • ServiceStack.Redis 通过 Nuget(包括 ServiceStack.Common 和 ServiceStack.Text)
    • 所有这些都在构建时位于 Bin 目录中
    • 引用类库
    • 所有依赖项都移到 Bin 除了 ServiceStack.Text
    • Refs ClassLibrary
    • all dependencies are moved to Bin except ServiceStack.Text

    我被难住了.有谁知道为什么?

    I'm stumped. Does anyone know why?

    注意:该错误似乎是在寻找版本 3.9.24,但 Nuget 提取的版本是 3.9.26.如果我手动将它移动到 Web/Bin,它虽然可以工作

    Note: The error appears to be looking for version 3.9.24, but the version Nuget pulled is 3.9.26. If I move it to the Web/Bin manually it works though

    推荐答案

    我在多个版本的 Visual Studio atm 2013 中遇到了这个有点奇怪的问题.它是随机发生的.

    I had this somewhat bizarre problem in several versions of Visual Studio, atm 2013. It has occurred at random.

    我也依赖于 ServiceStack.Common,它隐式地依赖于 ServiceStack.Text.但是,我没有在任何地方直接引用 ServiceStack.Text 二进制文件中的任何类、结构或类似内容.

    I too have dependencies on ServiceStack.Common, which implicitly depends on ServiceStack.Text. However, I am not directly at any place referencing any class, struct or the like inside ServiceStack.Text binary.

    即使设置了

    复制本地 = 真

    ServiceStack.Text.dll 被复制到输出文件夹.

    ServiceStack.Text.dll is not being copied to the output folder.

    我在许多版本的 ServiceStack dll 中都遇到过这种情况,目前是 v4.0.15.这可能是一个更普遍的 Visual Studio 错误,涉及在未直接使用的库中具有死角的依赖链?可能 ServiceStack.Text 被标记为其他 ServiceStack dll 中的依赖项,但 Visual Studio 试图通过看到可以排除该库来超越这一点(我只是推测).

    I have experienced this with numerous versions of ServiceStack dll's, currently v4.0.15. This could be a more general Visual Studio bug concerning dependency-chains with dead ends in not directly used libraries? Probably ServiceStack.Text is marked as a dependency in other ServiceStack dll's, but Visual Studio tries to outsmart this by seeing, the library can be excluded (I'm just speculating).

    无论如何,我通过简单地在私有方法中直接使用 ServiceStack.Text 解决了它,该方法放在我自己的库中随机使用的文件中:

    Anyway, I solved it by simply using ServiceStack.Text directly in a private method put in a random used file in my own library:

    /// <summary>
    /// Needed because of Visual Studio bug? Don't use this method.
    /// </summary>
    private JsonValue DontDoIt()
    {
        return new ServiceStack.Text.JsonValue();
    }
    

    我希望编译器排除一个未使用的私有方法 - 实际上它可能在 IL 代码中这样做,但这仍然使 VS 将 dll 复制到输出目录.

    I would expect the compiler to exlude an unused private method - indeed maybe it does in the IL code, but none the less this makes VS copy the dll to the output directory.

    这篇关于为什么 ServiceStack.Text 没有被复制到 Bin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:06