繁体   English   中英

生成的nuget包中缺少Project .dll本身

[英]Project .dll itself is missing in generated nuget package

我正在使用c#.net核心项目。 项目名称为Master ,它具有外部NuGet程序包的依赖关系,如“ SpecFlow.CustomPlugin”。 主项目有两个类Shape.csFactory.cs

当我生成Master项目的NuGet包时,Shape.cs和Factory.cs类的实现可以用作其他项目中的库。 在生成Master项目的NuGet包后,我只看到“SpecFlow.CustomPlugin”内容及其自己的相关dll文件,但我无法在新生成的NuGet包中看到dll的Master项目。

假设消费者是另一个项目中包含的新生成的NuGet包。 消费者希望使用Shape.cs方法和Factory.cs方法,但无法访问。

主项目依赖关系看起来像: 在此输入图像描述

首先,确保ShapeFactory是公开的。 如果您不指定它们的可见性,则默认情况下它们是私有的,这意味着它们不能被其他项目直接用作包参考或项目参考。

master打包到NuGet软件包中时,它将创建的默认文件为bin\\Debug\\master.1.0.0.nupkg 假设master以.NET Standard 2.0为目标, lib\\netstandard20\\master.dll master的dll保存为nupkg中的lib\\netstandard20\\master.dll 您需要将此nupkg添加/推送到nuget feed(可以是您的计算机或网络上的目录,nuget.org,或者您可以托管自己的Feed )。 comsumer项目将需要一个nuget.config ,增加了正确的NuGet饲料的来源,那么你添加到主包装基准。 还原后(如果通过UI添加了包,Visual Studio会自动执行该操作),然后可以使用master的任何公共类。

您可以在命令行上运行以下命令来设置两个项目,一个是程序包,另一个将使用它。 如果您在Visual Studio中使用.NET Core,则它必须已经下载了.NET Core SDK,这会将dotnet cli放在您的路径上。 您还需要从https://www.nuget.org/downloads/下载nuget.exe。

dotnet new nugetconfig
nuget source -configfile nuget.config add -name local -source feed

# create an isolated nuget environment, because I don't like to populate
# my global packages folder with test packages
nuget config -configfile nuget.config -set globalPackagesFolder=gpf

# create a library, pack it, and add the nupkg to our local feed
dotnet new classlib -n MyLib
dotnet pack MyLib\MyLib.csproj -o nupkgs\
nuget add MyLib\bin\Debug\MyLib.1.0.0.nupkg -s local

# create console app and reference MyLib
dotnet new console -n MyApp
dotnet add MyApp\MyApp.csproj package MyLib --version 1.0.0

#if you want to open these projects in Visual Studio
dotnet new sln -n sample
dotnet sln add MyLib\MyLib.csproj
dotnet sln add MyApp\MyApp.csproj
start sample.sln

通常,您不会使用NuGet包在同一解决方案中使用另一个项目中的一个项目。 只需为它们提供项目引用,然后将项目打包到NuGet包中时,该项目引用将成为NuGet依赖项。 我这样做只是为了演示如何轻松使用自己创建的包。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM