Skip to content

Instantly share code, notes, and snippets.

@Danthar
Created December 31, 2019 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Danthar/6fbc506249f5d57a2d7d5aeb3d4afc4c to your computer and use it in GitHub Desktop.
Save Danthar/6fbc506249f5d57a2d7d5aeb3d4afc4c to your computer and use it in GitHub Desktop.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);PackReferencedProjectOutputs</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
// we put this target in an props file and import it
<Target Name="PackReferencedProjectOutputs" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="@(ReferenceCopyLocalPaths-&gt;WithMetadataValue('ReferenceSourceTarget', 'ProjectReference'))" />
</ItemGroup>
</Target>
<ItemGroup>
<PackageReference Include="some public nuget" Version="0.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\yourprivateproject.csproj" PrivateAssets="all" />
</ItemGroup>
</Project>
@Danthar
Copy link
Author

Danthar commented Dec 31, 2019

What this does is it adds the output of your project dependency as an private asset to the nuget generated by the current project.
That way when use nuget to add the subsequently generated package to your project, it will show the 'private' project depedencies as being private, and not public nugets. This will prevent nuget from trying to resolve them as a nuget.

Also yourprivateproject.csproj output binary will be part of your nuget and be copied in if you reference that nuget.

@Danthar
Copy link
Author

Danthar commented Dec 31, 2019

Even better ofcourse would be if your project level dependency would be marked internal for the entire package. (which is not possible at this time as far as i know)
Or use ILMerge to merge the project in on build.

We use this for a few internal packages as a stopgap while we are transitioning/refactoring these packages to such a state where we don't need those projectreference dependencies anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment