dotnet使用本地软件包文件添加软件包 [英] dotnet add package with local package file

查看:263
本文介绍了dotnet使用本地软件包文件添加软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 dotnet 命令行工具,如何添加对通过nuget下载的 not 现有的本地软件包的引用?我尝试将本地包添加到具有 dotnet 的项目 bar 中。

Using the dotnet command line tool, how can I add a reference to an existing local package that is not downloaded with nuget? I have tried adding a local package to a project bar with dotnet.

 $ dotnet add package /Users/sakra/foo/bin/Debug/foo.1.0.0.nupkg 

软件包 foo.1.0.0.nupkg 已使用 dotnet pack 在另一个项目中。命令 dotnet add package 但是尝试从下载文件 foo.1.0.0.nupkg https://api.nuget.org/ rel = noreferrer> https://api.nuget.org/ 当然会失败。

The package foo.1.0.0.nupkg has been created with dotnet pack in a different project. The command dotnet add package however tries to download the file foo.1.0.0.nupkg from https://api.nuget.org/ which of course fails.

推荐答案

无法直接安装单个 .nupkg 软件包。 NuGet只能从提要中安装和还原,因此您需要将包所在的目录作为提要添加。

There isn't a way to directly install a single .nupkg package. NuGet can only install and restore from feeds, so you'll need to add the directory where the package is in as a feed.

为此,请添加 NuGet.Config 文件,该文件将目录的位置添加为提要,因此您不必将源参数添加到每个与puget相关的命令中(esp dotnet恢复):

To do this, add a NuGet.Config file that adds the location of the directory as feed so you don't have to add the source parameter to each puget-related command (esp dotnet restore):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="local-packages" value="../foo/bin/Debug" />
  </packageSources>
</configuration>

或者在.NET Core 2.0工具/ NuGet 4.3.0中,也可以将源代码直接添加到应该消耗NuGet的csproj文件:

Alternatively in .NET Core 2.0 tools / NuGet 4.3.0, you could also add the source directly to the csproj file that is supposed to consume the NuGet:

<PropertyGroup>
  <RestoreSources>$(RestoreSources);../foo/bin/Debug;https://api.nuget.org/v3/index.json</RestoreSources>
</PropertyGroup>

这将使所有命令都可以使用该软件包:

This will make all commands be able to use the package:


  • dotnet添加软件包foo (可选地添加 -v 1.0.0

  • dotnet恢复

  • dotnet运行

  • dotnet add package foo (optionally add -v 1.0.0)
  • dotnet restore
  • dotnet run

请注意,在开发过程中,如果更改了nuget程序包,但在两个项目中都没有增加它的版本,产生nupkg并在使用它的项目中,您需要先清除本地软件包缓存,然后再恢复:

Note that during development, if you change the nuget package but don't increment it's version in both the project that produces the nupkg and in the project that consumes it, you'll need to clear your local packages cache before restoring again:

dotnet nuget locals all --clear
dotnet restore

我在< a href = https://github.com/dasMulli/LocalNupkgExample rel = noreferrer> https://github.com/dasMulli/LocalNupkgExample

这篇关于dotnet使用本地软件包文件添加软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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