我是否需要在.NET标准库或可执行项目或两者上安装NuGet包? [英] Do I need to install NuGet package on .NET standard library or executable project or both?

查看:100
本文介绍了我是否需要在.NET标准库或可执行项目或两者上安装NuGet包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2017并创建.Net标准库。在此库中,我通过使用WCF连接服务选项添加对WCF服务的引用。由于这个项目是一个类库,我在控制台应用程序(可执行项目)中添加它的引用。



在我的.net标准项目中,我正在调用一个方法来自WCF服务库。当我运行项目时,我收到错误 -

System.IO.FileNotFoundException:'无法加载文件或程序集'System.ServiceModel.Primitives,Version = 4.1.1.0, Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。系统找不到指定的文件。'



因此,在包管理器控制台中,我安装了System.ServiceModel.Primitives包。 net标准库项目,但我仍然得到同样的错误。如果我也为可执行项目安装了相同的NuGet,那么错误就会消失。



我的问题是,我是否必须安装所有NuGet包两次(一次用于类库,然后一次在可执行项目上)?



我尝试过:



我试过在可执行项目中添加对System.ServiceModel和System.ServiceModel.Primitives dll的引用

I am using Visual Studio 2017 and creating .Net Standard Library. In this library, I am adding reference to WCF Service by using WCF Connected Service option. As this project is a class library, I am adding its reference in a console app (Executable project).

In my .net standard project, I am calling a method from WCF service library. When I run the project, I get error -
System.IO.FileNotFoundException: 'Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

So, In package manager console, I install System.ServiceModel.Primitives package for .net standard library project, but I still get the same error. If I also install the same NuGet for executable project, then the error goes away.

My question is, do I have to install all NuGet packages two times (once for class library and then once on executable project)?

What I have tried:

I have tried adding reference to System.ServiceModel and System.ServiceModel.Primitives dll in executable project

推荐答案

是的,你必须install-package在每个将要使用它的项目上,但您只在解决方案中安装一次可执行文件。每个项目都会添加引用,它们将指向该库的二进制文件的公共文件夹。



构建项目时,需要。 DLL将最终出现在构建的bin文件夹中,\ bin \Debug,\ bin \ Release。这些文件需要与每个项目可部署文件一起使用。
Yes, you have to "install-package" on every project that's going to use it, but you're only installing the executable files once in the solution. Each project is going to have references added to it where they will point to the common folder for the binaries for that library.

When you build the project, the required .DLL's will end up in the bin folder for your build, \bin\Debug, \bin\Release. Those files need to go with each of your project deployables.


这篇关于我是否需要在.NET标准库或可执行项目或两者上安装NuGet包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆