How to enforce same nuget package version across multiple c# projects?

前端 未结 4 2079
失恋的感觉
失恋的感觉 2020-12-15 15:59

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

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-15 16:55

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

    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 looks like this:

    
      
        
      
      
        
      
    
    

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

     
    

    Once you're done, you can copy .nupkg from cache to localnuget folder to check it in.

    There are 3 things I LOVE about this setup:

    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.

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

    3. 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.

提交回复
热议问题