5

这基本上相当于,“我如何克隆一个 .NET 项目,进行修改,并使用它而不是发布的项目?”

在 NodeJS 中,我们有npm link,它允许您将 node_modules/ 目录中的本地包(模块)链接到当前项目。因此,例如,您可以在 package.json 中不使用 Express,而是

  1. 克隆快递
  2. 进行修改以表达
  3. 编译(必要时编译)和/或构建
  4. 在 Express repo 中运行npm link以创建全局可用的本地包
  5. 在您当前的项目中运行npm link express以使用您的本地快递,而不是您将获得的快递npm install

使用 .NET,到目前为止我看到的最接近的解决方案包括创建本地提要,但在我的实验中这似乎不起作用。关于堆栈溢出的其他问题,例如如何在 .net 中使用本地包,似乎提供了使用 RestoreSources 的解决方案,这在整个网络中几乎没有记录。当尝试更改 RestoreSources 以使用 LocalPackages 目录时,我不清楚是否正在使用本地包(obj/ 目录中的源似乎仍然来自 nuget 包而不是本地包)。

4

2 回答 2

8

For anyone in the future wondering this, the correct answer is to use the local feed. My problem was that I had cached nuget packages which were being resolved during dotnet restore.

The following command before restore solved my issues:

dotnet nuget locals all --clear
dotnet restore

Essentially, you need to have a nuget config (NuGet.config) in your solution that sets up your local packages directory:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
    <clear />
    <add key="LocalDev" value="./my-project/artifacts" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
</configuration>

Where artifacts/ directory contains all of the .nupkg packages you want to use during restore. It is obviously also essential that you must make sure those packages are built/compiled before you dotnet restore in your primary solution:

dotnet pack /p:Version=5.22.12 --configuration Release --force --output "%~dp0artifacts";
于 2019-06-04T20:23:41.643 回答
0

有一个项目试图做npm link类似的体验,叫做NuLink。它实质上创建了从缓存的 nuget 包到包bin/Debug文件夹的符号链接。使用本地提要将是更好的体验。

我对安装 3d 派对.exe文件有点谨慎,所以我使用了NuLink不需要任何 3d 派对工具的简单版本的方法:

  1. 安装旧版本的软件包(例如 1.0.0)。您可以在您的消费项目中引用它并运行dotnet restore例如
  2. lib从已安装的包中重命名/删除文件夹。窗口示例:rename C:\Users\<USERNAME>\.nuget\packages\MyPackage\1.0.0\lib lib_old
  3. 从它创建一个符号链接/连接到您的包调试文件夹。在 Windows 上,它将是这样的:mklink /J C:\Users\<USERNAME>\.nuget\packages\MyPackage\1.0.0\lib C:\Source\MyPackage\bin\Debug
  4. 在您使用的项目中“降级”到您的包的 1.0.0 版本

现在,只要您使用 1.0.0,您的消费项目就应该使用包中的 .dll/.pdb 文件引用该文件夹。您只需构建您的包,然后它应该立即可用,包括导航到文件和调试(因为 .pdb 文件位于同一文件夹中)。

PS 根据您使用的dotnet/版本,可能会有很多调整nuget,但要点应该仍然是相同的,文件夹结构有一些变化。

于 2021-08-20T08:54:15.037 回答