1

I have to one library which I want to package and use in other projects. This library has reference to another project, that I do not want to publish as a package. To include it in the package I have added this lines in .cproj file:

 <PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
      </PropertyGroup>

      <Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
        <ItemGroup>
          <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
        </ItemGroup>
      </Target>

As a result I have both .dlls in packages lib folder, and this kind of nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>NugetSample</id>
    <version>1.0.1</version>
    <authors>NugetSample</authors>
    <owners>NugetSample</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package Description</description>
    <dependencies>
      <group targetFramework=".NETCoreApp3.1">
        <dependency id="referenced project name" version="1.0.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
</package>

But I get this error again:

Unable to find package referenced project name. No packages exist with this id in source(s): Local Nuget, Microsoft Visual Studio Offline Packages, nuget.org

It seems that visual studio tries to find this dependency as a nuget package again. How can I solve this problem?

user12832050
  • 13
  • 1
  • 3

1 Answers1

0

You can keep the project as a simple reference in your main project you want to package. Then in nuspec file, as sibling of dependencies element add references:

<references>
   <reference file="referencedfile.dll" />
</references>

If you want to add simple files you can also use the sibling element files:

<files>
    <file src="bin\$configuration$\referencedfile.pdb" target="lib\net461" />
</files>
Luca Mazzanti
  • 619
  • 5
  • 10
  • Thanks, I will try it now. – user12832050 Feb 03 '20 at 11:13
  • you must remove it from dependences and move to references – Luca Mazzanti Feb 03 '20 at 13:07
  • I tried it, but same happens. there is no way to solve this without modifying nuget package after pack? – user12832050 Feb 03 '20 at 13:24
  • i stop here sorry, but i try to recap your issue. if you use dependencies, it is expected in a nuget server source (the message says: i can't find a nuget with that name) as a nuget package. if you use references, it copy inside the package the dll project you are referencing. change correctly the nuspec file (you can read on msdn the clear documentation about the file structure), regenerate the package, publish it with a fix version incremented. good luck. – Luca Mazzanti Feb 03 '20 at 14:10