开发者

NuGet and multiple solutions

开发者 https://www.devze.com 2023-04-04 22:03 出处:网络
We have two solutions:foo.sln and bar.sln I have a common library that is used by both foo and bar. Common.csproj is used by both.

We have two solutions: foo.sln and bar.sln

I have a common library that is used by both foo and bar. Common.csproj is used by both.

If I open foo and update nuget references, all references in Common.csproj point to foo/packages/. If I later open bar and update nuget references, all references get set to those in bar/packages/. Naturally, this pisses off the foo team as it can cause incompatibilities between Common.csproj and Foo-开发者_运维知识库specific stuff like Foo.Data.csproj, which still points to foo/packages.

There must be some obvious solution other than: "create a huge solution that contains all your projects, and if you need to touch nuget, only do it from that solution."

There seems to be an issue on codeplex, (the top voted issue, incidentally), but evidently I'm too thick to understand how this issue is resolved. Can someone explain how to fix this?


This problem preceeds NuGet. If you have a project referenced in two solutions, and change assembly references in the project when it is open in one solution, of course it will change the reference path for that project when it is open in the other solution. This has always been the case, regardless of how the reference was changed (with NuGet or otherwise).

But the real problem is that when you do an update, the updated packages do not appear in the foo/packages directory right?

The simple solution is to move Common.csproj into a solution of its own, with its own references, packages folder, build and release process. Then create a NuGet package of your own with any relevant dependencies built into it. Then you can install your Common package into both Foo and Bar and then the Foo team is free to update to the latest version of Common as and when they are ready.

The main argument that I have heard against this is that you might want to step through the Common code while debugging, but this is no longer an issue with Visual Studio 2010.

The fundamental question you need to ask is who owns Common.csproj? Is it the Foo team or the Bar team?


I fix the problem by changing the hint path in the project fil to contain the $(SolutionDir) variable:

Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>$(SolutionDir)packages\EntityFramework.6.1.3\lib\net40\EntityFramework.dll</HintPath>


Why not have common.csproj as a separate assembly that you reference and has its own dependencies rather than those of the solution its in.

By doing that you protect common from either foo or bar updating the referenced package and breaking it.


In our case, many developers and solutions with tfs, and multiple versions of it in different branches ... and each developer their understanding of where the source must lie.

Relative path in this case not work, absolute paths in case of coincidence disc are replaced by relative and also did not work.

Our solution consists in getting rid of the relative path. You can do it if you put NuGetPackages on a separate disk. like so:

net use /persistent:yes p: \\localhost\C$\NuGetPackagesDiskFolder

Any folder name you wont
After that, you can specify realy absolute path in the NuGet.Config

<config>
<add key="repositorypath" value="p:\NuGetPackages" />
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>

After all delete suo files

ps: Will a little trouble with the alteration of exsisting solutions, if they live in sourcecontrol easiest way is to correcting the path to p:\NuGetPackages in each .csproj Otherwise it is necessary to reinstall all the refs and manually undo all packages.config marked as deleted in the sourcecontrol

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号