Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

PackageReference to project in the same Solution/git repository

$
0
0

At the moment I'm trying to setup a solution with a implementations class library and an abstractions project. I want to have both packages on nuget.org.

Normally when you're just using ProjectReferences, you'd only have to point to the csproj:

Random.Abstractions:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework><GeneratePackageOnBuild>true</GeneratePackageOnBuild><Description>Abstractions for the Randomizer</Description><PackageLicenseExpression>Apache-2.0</PackageLicenseExpression><Company>MyCompany</Company><Authors>Pieterjan De Clippel</Authors></PropertyGroup><ItemGroup><PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" /></ItemGroup></Project>

Random

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework></PropertyGroup><ItemGroup><ProjectReference Include="..\Random.Abstractions\Random.Abstractions.csproj" /></ItemGroup></Project>

But off course when you build a nuget package, you don't want the Random.Abstractions.dll to be inside the Random nuget package, but the Random package to depend on the Random.Abstractions package. But since this package doesn't exist yet, you can't build it yet.

Microsoft is able to solve this problem like this:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>    ...</PropertyGroup><ItemGroup>    ...</ItemGroup><ItemGroup>    ...<Reference Include="Microsoft.AspNetCore.DataProtection.Abstractions" /></ItemGroup></Project>

So this is neither a ProjectReference nor a PackageReference, which is why they are able to:

  1. build and test the solution locally (so there they'd be acting as ProjectReferences)
  2. push the code to GitHub and let the GitHub Actions create and publish the new version of the packages, while they depend on each other (so there they'd be acting as PackageReferences)

I've tried doing the same in my solution, but the project containing the concrete implementations is unable to find the abstractions project:

MyCompany.Random.Abstractions.csproj:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework><GeneratePackageOnBuild>true</GeneratePackageOnBuild><Description>Abstractions for the Randomizer</Description><PackageLicenseExpression>Apache-2.0</PackageLicenseExpression><Company>MyCompany</Company><Authors>John Wick</Authors></PropertyGroup><ItemGroup><PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" /></ItemGroup></Project>

MyCompany.Random.csproj

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFramework>netstandard2.0</TargetFramework></PropertyGroup><ItemGroup><Reference Include="MyCompany.Random.Abstractions" /></ItemGroup></Project>

So no ProjectReference (we don't want the dll to be in this nuget package), no PackageReference (the package is not yet published), but just Reference.But somehow I'm still getting an error that the Abstractions assembly cannot be found:

Abstractions assembly cannot be found

I've checked the NuGet.config but there's nothing really special in there.

How can I use the Reference tag in a dotnet-based project, in order to reference to code while building/testing locally and reference the new package while building/pushing in a CI pipeline?

Reference to Microsoft.NET.Sdk documentation

Update:

@pinkfloydx33, you're right. I can see only one assembly/dll inside the nupkg:

Contents of the nuget package


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>