Pain-free local development while also referencing NuGet packages

后端 未结 7 621
青春惊慌失措
青春惊慌失措 2020-12-12 19:24

I am attempting to publish and consume versioned NuGet packages of class libraries while avoiding headaches for local development. Here is a sample Visual Studio solution la

相关标签:
7条回答
  • 2020-12-12 19:58

    Update for .NET Core (2.x ++)

    .NET Core 2.x actually has this functionality built in!

    If you have a project reference to project A in project B, and project A is a .NET Standard or Core project with proper package information (Properties -> Package with Package id set to your NuGet package ID), then you can have a regular project reference in project B's .csproj file:

    <ItemGroup>
      <ProjectReference Include="..\..\A\ProjectA.csproj" />
    </ItemGroup>
    

    When you pack (dotnet pack) project B, because of the Package id in project A, the generated .nuspec file will be set up with a NuGet dependency to that Package ID, together with other NuGet references you might have, instead of just including the built DLL file.

    <dependencies>
      <group targetFramework=".NETStandard2.0">
        <dependency id="Project.A" version="1.2.3" exclude="Build,Analyzers" />
        <dependency id="Newtonsoft.Json" version="12.0.2" exclude="Build,Analyzers" />
      </group>
    </dependencies>
    
    0 讨论(0)
提交回复
热议问题