如何实施跨多个C#项目相同的NuGet包版本? [英] How to enforce same nuget package version across multiple c# projects?

查看:320
本文介绍了如何实施跨多个C#项目相同的NuGet包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆它们使用一对夫妇的NuGet包的小C#项目。我希望能够自动更新一个给定的包的版本。更多的则是:?我想被警告说,如果一个项目使用不同于其他版本

I have a bunch of small C# projects which use a couple of NuGet packages. I'd like to be able to update version of a given package automatically. More then that: I'd like to be warned if a project uses different version from the others.

我如何执行在多个C#项目相同版本的依赖

How do I enforce same version dependency across multiple C# projects?

推荐答案

我相信我已经找到了设置,其中解决了这个(和许多其他)问题(S)。

I believe I have found a setup which solves this (and many other) problem(s).

我才意识到可以使用一个文件夹的NuGet源。下面是我所做的:

I just realized one can use a folder as nuget source. Here is what I did:

root
  + localnuget
      + Newtonsoft.Json.6.0.1.nupkg
  + nuget.config
  + packages
      + Newtonsoft.Json.6.0.1
  + src
      + project1

nuget.config看起来是这样的:

nuget.config looks like this:

<configuration>                                                                                                            
  <config>                                                                                                                 
    <add key="repositoryPath" value="packages" />                                                                          
  </config>                                                                                                                
  <packageSources>                                                                                                         
    <add key="local source" value="localnuget">                                                              
  </packageSources>                                                                                                        
</configuration>         

您可以添加的NuGet服务器nuget.config以访问开发期间更新或新的依赖:

You can add Nuget server to nuget.config to get access to updates or new dependencies during development time:

<add key="nuget.org" value="https://www.nuget.org/api/v2/" /> 



一旦你做,你可以从缓存复制.nupkg [1]到<$ C $ 。C> localnuget 文件夹以检查它

有3事情我喜欢这个设置:

There are 3 things I LOVE about this setup:


  1. 我现在能够使用的NuGet功能,如添加的道具和目标。如果你有一个代码生成器(例如,protobuf的或储蓄),这将成为pricesless。

  1. I'm now able to use Nuget features, such as adding props and targets. If you have a code generator (e.g. protobuf or thrift) this becomes pricesless.

这(部分)解决了Visual Studio中没有复制所有的DLL [2的问题],因为你需要间接依赖关系自动指定 .nuspec 文件依赖性和负载的NuGet。

It (partially) solves the problem of Visual Studio not copying all DLLs [2], because you need to specify dependencies in .nuspec file and nuget loads indirect dependencies automatically.

我曾经有过这么更新的NuGet包是比较容易的所有项目的单一解决方案文件。我还没有试过,但我想我解决了这个问题了。我可以的NuGet包我想从给出的解决方案导出项目。

I used to have a single solution file for all projects so updating nuget packages was easier. I haven't tried yet but I think I solved that problem too. I can have nuget packages for the project I want to export from a given solution.

[1]的 http://www.hanselman.com/blog/HowToAccessNuGetWhenNuGetorgIsDownOrYoureOnAPlane.aspx

[2] http://www.google.com/search? q =视觉工作室+ + +不复制+ +引用DLL

这篇关于如何实施跨多个C#项目相同的NuGet包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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