Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.5k 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 Reply

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...