Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

visual studio - How do I specify a project reference as a Nuget package reference when publishing my own Nuget package?

I have a Visual Studio solution that has (as well as test projects etc) two projects that will end up as Nuget packages. ProjectA doesn't have any dependencies, but ProjectB depends on ProjectA. The solution is in a GitHub repository, with workflows set up to build and publish the two projects to Nuget.

In Visual Studio, I have a project reference from ProjectB to ProjectA, which makes development and testing easy. However, when I publish, I would like to have ProjectB have a Nuget package dependency on ProjectA, rather than including the DLLs in the package.

Is there an easy way to do this? I saw this SO answer, but it seems very manual. I was hoping there was some way to do this as part of the build and publish workflow.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

By default, when you use ProjectReference to Reference Project A into Project B under new-sdk project, it actually views the Project A as a nuget dependency.

Make sure you did not add <PrivateAssets>All</PrivateAssets> under Project B's ProjectReference. PrivateAssets will break the nuget dependency for Project A when you pack Project B.

If you have this:

<ItemGroup>
    <ProjectReference Include="..ProjectAProjectA.csproj">
      <PrivateAssets>All</PrivateAssets>
    </ProjectReference>
  </ItemGroup>

Please remove <PrivateAssets>All</PrivateAssets>.

In my side, when I publish the Project B, it has the nuget project of A.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...