Create nuget package with multiple DLLs

后端 未结 8 1683
忘了有多久
忘了有多久 2020-12-25 09:58

Let\'s say I have a project with this structure:

MyLibrary\\
  MyLibrary.sln
  MyLibrary.Core\\
    MyLibrary.Core.csproj
  MyLibrary.Extensions\\
    MyLibr         


        
相关标签:
8条回答
  • 2020-12-25 10:22

    I had the same problem and I decided to create Nuget which will allow to create other nugets from chosen project.

    Package is deployed on the Nuget.org site. After referencing it in the project You need to add nuspeck file to the projects which should generate the projects.

    Project with the required nuspeck file

    Last thing which should be done by you is invoke command Create-Nuspec in Package Manager. Than the powershell module will take all libraries which are result of the build it will add also the required dependencies and create the nuget in the output directory.

    Description about this package is placed here.

    0 讨论(0)
  • 2020-12-25 10:24

    You'll run NuGet on a single project (or nuspec file), but it supports pointers to other projects via the file element. This element uses the names of your project's References, so you avoid having to a) find the location of other project files, and b) copy files to a particular place as a post-build step.

    Supposing you have a nuspec file for MyLibrary.Core.csproj, and it references MyLibrary.Extensions and MyLibrary.Tests such that they end up in the bin directory after a build:

    <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
      <metadata>
        ...
      </metadata>
      <files>
        <file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40" />
        <file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40" />
      </files>
    </package>
    

    With this setup, all of your references should end up in the appropriate place in the NuGet package. You still have the hard-coded 'Release' in there, but I'd wager most probably don't distribute NuGet packages of their debug builds anyway.

    0 讨论(0)
  • 2020-12-25 10:28

    I had an issue when adding extra dlls references to a Nuget packages, and testing the package on a sample project, the extra dlls was not being added apparently, no matter the way that I create the Nuget Package.

    Then I released that when you uninstall and install again a local Nuget Package with the same version number the changes no take effect, the extra dlls are not added.

    So each time you uninstall the package, close visual studio and clear the Nuget Cache,

    How to clear NuGet package cache using command line?

    Then open again Visual Studio and reinstall the local package to make the change takes effect.

    Or make the package version to increase each time to be for Visual Studio to recognize your changes.

    For example:

    • Package-1.0.0
    • Package-1.0.1
    • Package-1.0.2
    • .....

    To create a Nuget package from a sample project there are some ways, for example:

    1. Right click to your Visual Studio project and choose the "Pack" option

    Then install the nuget package explorer:

    https://www.microsoft.com/es-ec/p/nuget-package-explorer/9wzdncrdmdm3?activetab=pivot:overviewtab

    And add manually your extra references (dlls files) to your specific targets.

    1. Create a nuget package using a .nuspec file how specified in the documentation:

    https://docs.microsoft.com/en-us/nuget/guides/create-packages-for-xamarin

       <files>
            <file src="Plugin.LoggingLibrary\bin\Release\Plugin.LoggingLibrary.dll" target="lib\netstandard1.4\Plugin.LoggingLibrary.dll" />
            <file src="Plugin.LoggingLibrary\bin\Release\Plugin.LoggingLibrary.xml" target="lib\netstandard1.4\Plugin.LoggingLibrary.xml" />
            <file src="Plugin.LoggingLibrary.iOS\bin\Release\iOsDependence.dll" target="lib\Xamarin.iOS10\iOsDependence.dll" />
            <file src="Plugin.LoggingLibrary.Android\bin\Release\AndroidDependence.dll" target="lib\MonoAndroid10\AndroidDependence.dll" />
       </files>
    

    In your files part add your .dll files.

    And dont forget, each time you uninstall and install again the nuget package from your local source.

    • Or you increase the version of the package each time:

    • Or close Visual Studio, clean the nuget cache and Rebuild your project.

    In order to take effect the changes.

    0 讨论(0)
  • 2020-12-25 10:32

    It seems your problem is the same as this question: Why doesn't nuget include the referenced project when packing?. If so, you can use the -includereferencedprojects option (See http://docs.nuget.org/docs/reference/command-line-reference#Pack_Command).

    0 讨论(0)
  • 2020-12-25 10:34

    I recently published a solution for this...

    My solution enables automatic creation of NuGet packages when you build the solution where each package can contain multiple assemblies, references to both external NuGets and NuGets created during the same build and even include the source code for debugging.

    In your case, all you will need to do is add a new class library project to your solution, reference the projects you want to package, then add a post build event.

    You can find an article with a walk-through guide here and the source code + binary here.

    0 讨论(0)
  • 2020-12-25 10:40

    Did you generate a blank nuspec file with:

    nuget spec
    

    If you use that file and then put your dlls in a folder under it named lib, it will package them up.

    I had a little trouble with trying to generate a nuspec file from a project or dll. Also, if you manually reference any files in the nuspec file, the conventions are not used. This is probably the problem with nuspecs generated from dlls or projects.

    Also, if you are trying to run this from a build script that executes in a different folder, you can tell nuget the location of your .\lib folder via the -BasePath command line:

    build\nuget.exe pack nuget\Company.Project.nuspec -BasePath nuget\
    
    0 讨论(0)
提交回复
热议问题