Creating one NuGet package from multiple projects in one solution

前端 未结 4 1447
孤街浪徒
孤街浪徒 2020-12-28 14:09

I have a solution that I\'m working on that contains 4 class library projects (A, B, C, D). A and B

相关标签:
4条回答
  • 2020-12-28 14:30

    2020 UPDATE

    I personally prefer to use dotnetcommand wherever it is possible.

    The solution I found working out fine is changing the default project reference in the main project <ProjectReference></ProjectReference> as below

      <ItemGroup>
        <ProjectReference Include="..\{ProjectFolder}\{ProjectName}.csproj">
          <ReferenceOutputAssembly>true</ReferenceOutputAssembly>
          <IncludeAssets>{ProjectName}.dll</IncludeAssets>
        </ProjectReference>
      </ItemGroup> 
    

    This solution is confirmed that it works when targeting netstandard2.0and above.

    0 讨论(0)
  • 2020-12-28 14:33

    If you have downloaded NuGet.exe You can run: nuget pack Myproject.csproj -IncludeReferencedProjects and this should include all of your projects. Here's a note from the NuGet docs:

    If the project references other projects, you can add the referenced projects as part of the package, or as dependencies with -IncludeReferencedProjects option. This is done recursively. For example, suppose you have project A.csproj, which references B.csproj and C.csproj, while B.csproj references D.csproj & E.csproj, C.csproj references F.csproj & G.csproj. Then, when you run:

    nuget pack A.csproj -IncludeReferencedProjects
    

    the generated package will contain files from projects B, C, D, E, F & G, in addition to files from project A.

    If a referenced project has a corresponding nuspec file with the same name, then that referenced project is added as a dependency instead. Using the same example, suppose now there is file C.nuspec in the same directory as project file C.csproj. When you run:

    nuget pack A.csproj -IncludeReferencedProjects
    

    the generated package will contain files from projects B, D, E, in addition to files from project A, and the package has dependency on C.

    Please also see the Command line reference.

    0 讨论(0)
  • 2020-12-28 14:38

    this probably will solve this exact: nuget.exe pack proj.csproj -IncludeReferencedProjects

    you can see: Create nuget package for a solution with multiple projects

    0 讨论(0)
  • 2020-12-28 14:44

    You have to define your own nuspec manifest. You can list containing assemblies in files section:

    <file src="A\bin\Release\A.dll" target="lib\net40" />
    <file src="B\bin\Release\B.dll" target="lib\net40" />
    ...
    

    For more details read NuSpec reference.

    Then reference that nuspec file in NuPack build step instead of proj.

    0 讨论(0)
提交回复
热议问题