How do you share external dependencies between Visual Studio solutions?

后端 未结 3 719
清酒与你
清酒与你 2020-12-15 01:29

I have a Java background so I’m used to having Maven handle all problem around downloading and keeping dependencies up to date. But in the .NET environment I have not yet fo

3条回答
  •  醉话见心
    2020-12-15 02:01

    1. Find some place to store the assemblies. For example, I store the .Net core assemblies like so:

      • >\NetFX\2.0527\*
      • >\NetFX\3.0\*
      • >\NetFX\3.5\*
      • >\NetFX\Silverlight 2\*
      • >\NetFX\Silverlight 3\*
    2. Use the ReferencePath property in MSBuild (or AdditionalReferencePath in Team Build) to point your projects at the appropriate paths. For simplicity and easy maintenance, I have 1 *.targets file that knows about every such directory; all of my projects Import that file.

    3. Make sure your version control strategy (branching, merging, local<->server mappings) keeps the relative paths between your projects & your reference paths constant.

    EDIT

    In response to the update in the question, let me add one more step:

    4) Make sure every assembly reference in every project file uses the full .Net strong name and nothing else.

    Bad:

    
      False
      ..\..\..\..\..\..\..\Program Files (x86)\Microsoft SQL Server\100\Shared\Microsoft.SqlServer.Smo.dll
    
    

    Good:

    
    

    Advantages of the latter format:

    • Using a HintPath in a collaborative development environment will inevitably lead to situations where "it works for me" but not others. Especially your build server. Omitting it forces you to get your reference paths correct or it won't compile.
    • Using a weak name invites the possibility of "DLL hell." Once you use strong names then it's safe to have multiple versions of the same assembly in your reference paths because the linker will only load ones that match every criterion. In addition, if you decide to update some assemblies in place (instead of adding copies), then you'll be notified of any breaking changes at compile time instead of whenever the bugs start coming in.

提交回复
热议问题