我有一些c#书中的。nupkg文件。我如何安装它们?


当前回答

Add the files to a folder called LocalPackages next to you solution (it doesn't have to be called that, but adjust the xml in the following step accordingly) Create a file called NuGet.config next to your solution file with the following contents <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="LocalPackages" value="./LocalPackages" /> </packageSources> <activePackageSource> <!-- this tells that all of them are active --> <add key="All" value="(Aggregate source)" /> </activePackageSource> </configuration> If the solution is open in Visual Studio, close it, then re-open it.

现在您的包应该出现在浏览器中,或者可以使用Install-Package进行安装

其他回答

在Linux上,使用NuGet CLI,命令是类似的。安装我的。nupkg,跑

nuget add -Source some/directory my.nupkg

然后在该目录下运行dotnet restore

dotnet restore --source some/directory Project.sln

或者将该目录添加为NuGet源

nuget sources Add -Name MySource -Source some/directory

然后告诉msbuild使用/p:RestoreAdditionalSources=MySource或/p: restoreresources =MySource的目录。第二个开关将禁用所有其他源,例如,这适用于脱机场景。

如果你有一个.nupkg文件,只需要.dll文件,你所要做的就是将扩展名更改为.zip,然后找到lib目录。

使用以下3个选项之一打包你的库:

Visual Studio (csproj >属性>包>勾选“生成NuGet包构建”。然后构建解决方案) dotnet命令行(在项目文件夹的命令提示符中:dotnet build,然后dotnet pack命令) NuGet命令行(在项目文件夹的命令提示符中:dotnet build,然后NuGet pack命令)

添加生成的包(在项目文件夹bin >调试(或发布)> *。使用nuget add命令将nupkg文件添加到离线提要(VS2019中的默认位置是C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\) 在VS中,管理NuGet包>右上:更改包源为Microsoft Visual Studio Online Packages。

详细的说明可以在这里找到或在yt

Add the files to a folder called LocalPackages next to you solution (it doesn't have to be called that, but adjust the xml in the following step accordingly) Create a file called NuGet.config next to your solution file with the following contents <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="LocalPackages" value="./LocalPackages" /> </packageSources> <activePackageSource> <!-- this tells that all of them are active --> <add key="All" value="(Aggregate source)" /> </activePackageSource> </configuration> If the solution is open in Visual Studio, close it, then re-open it.

现在您的包应该出现在浏览器中,或者可以使用Install-Package进行安装

对于.nupkg文件,我喜欢使用:

Install-Package C:\Path\To\Some\File.nupkg