为多个解决方案中存在的C#项目管理Nuget软件包 [英] Managing Nuget packages for C# project present in multiple solutions

查看:453
本文介绍了为多个解决方案中存在的C#项目管理Nuget软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正处于一个大型项目的重构疯狂阶段,该项目具有很多旧版和不稳定的模块.我决定拆分解决方案,该解决方案目前已链接了所有项目(因此大约有20个项目,由于单元测试项目肯定会在下个月推出,因此还会有更多项目),以使其更加独立和颗粒状.

I am now on the phase of refactoring madness of a big project which has a lot of legacy and unstable modules. I've decided to split the solution that currently has ALL projects (so around 20 and there will be more because of unit test projects that would surely come in next months) chained in it to make it more independent and granular.

通过这种方法,有一些模块,例如需要在多个解决方案中引用或添加的API客户端.

With this approach there are modules e.g. API clients that needs to be either referenced or added in multiple solutions.

问题在于,Nuget软件包仅在最初首次添加的解决方案上得到恢复.所以最简单的例子:

The problem is that Nuget packages are getting restored only on the solution that it was added originally for the first time. So the simplest example:

解决方案A:

------ ProjectA

------ ProjectA

------ APIClient

------ APIClient

解决方案B:

------ ProjectB

------ ProjectB

------ APIClient

------ APIClient

由于我们不包括packages文件夹,因此会导致Nuget软件包出现问题:

Since we are not including packages folder it causes problems with Nuget packages:

  1. 克隆存储库.

  1. Clone the repo.

打开解决方案B,进行构建并还原Nugets作为解决方案.

Open Solution B, build it and restore the Nugets for solution.

解决方案B中的ClientAPI软件包错误.

Errors with packages of ClientAPI in Solution B.

转到解决方案A进行构建并还原Nugets以获得解决方案

Go to Solution A build it and restore the Nugets for solution

回到解决方案B.

在解决方案B中为ClientAPI还原了螺母,并且错误消失了.

Nugets are restored for ClientAPI in Solution B and errors are gone.

有什么办法吗?

  • 使每个解决方案的项目使用不同的路径吗?
  • 也许正在构建链式解决方案以使解决方案A始终与解决方案B一起构建?但这听起来失去了将这一大解决方案拆分为更小的解决方案的某些好处.
  • 使用任何其他方法使它更精细,但又不会因重建所有内容而遭受问题吗?我听说过私人的Nuget供稿,如果我的配置允许的话,是否可以解决此问题?

我的配置:

  • VCS:带有TFVC的TFS
  • IDE:Visual Studio Proffesional 2017
  • 默认软件包管理格式:Packages.config

推荐答案

为多个解决方案中存在的C#项目管理Nuget软件包

Managing Nuget packages for C# project present in multiple solutions

感谢您的回复.我用两个解决方案(项目APIClientSolutionA)重现了此问题.然后SolutionB,将SolutionA中的现有项目APIClient添加到SolutionB.

Thanks for you reply. I have reproduced this issue with two solutions, SolutionA with Project APIClient. And SolutionB, add the existing project APIClient in the SolutionA to the SolutionB.

然后,如果我们在SolutionB上还原nuget程序包,则默认情况下将在 SolutionB 文件夹的\packages文件夹中还原SolutionB中项目APIClient中的程序包.在SolutionA文件夹中.

Then if we restore the nuget package on the SolutionB, package in the project APIClient in the SolutionB will be restored in the \packages folder in the SolutionB folder by default rather than in the SolutionA folder.

在这种情况下,项目APIClient仍然缺少SolutionB中的.dll引用,您仍然必须转到SolutionA并还原nuget包.这就是您遇到该问题的原因.

In this case, the project APIClient still missing the .dll reference in the SolutionB, you still have to go to SolutionA and restore the nuget packages. That the reason why you got that issue.

要解决此问题,可以在SolutionASolutionB旁边添加NuGet.Config文件,其内容如下:

To resolve this issue, you could add a NuGet.Config file next to the SolutionA and SolutionB with the following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="C:\Packages" />
  </config>
</configuration>

因此,\packages文件夹与解决方案文件无关.

So, the \packages folder not related to the solution file.

此外,如果您有兴趣,可以尝试将项目APIClientpackages.config转换为packagereference,并使用此设置将nuget软件包保存在全局软件包文件夹C:\Users\<UserName>\.nuget\packages中. .

Besides, if you are interested, you can try to convert the packages.config to the packagereference for the project APIClient, with this setting, the nuget package will be saved in the global packages folder, C:\Users\<UserName>\.nuget\packages.

希望这会有所帮助.

这篇关于为多个解决方案中存在的C#项目管理Nuget软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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