I have below three projects, all are created using VS2022 and targeting .net 6.
- ExternalProject (.dll)
- InternalProject (.dll)
- TestProject (.exe)
ExternalProject contains a reference to the InternalProject, also I am creating NuGet package of ExternalProject using the below command
dotnet pack ExternalProject.csproj /p:NuspecFile=ExternalClass.nuspec
The content of ExternalClass.nuspec file is below
<?xml version="1.0"?>
<package >
<metadata>
<id>ExternalProject</id>
<version>1.0.10</version>
<title>ExternalProject</title>
<authors>Ustad</authors>
<owners>Ustad</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
</metadata>
<files>
<file src="..\InternalProject\bin\Debug\net6.0\*.*" target="lib\net6.0" />
</files>
</package>
The problem is, that InternalProject dll is not being added to the ExternalProject NuGet package. Not sure what I am missing here.
CodePudding user response:
Since the answer in my comment is one year older than the current documentation I'll include here.
According to the docs:
NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. If the packed project has references to other projects, the other projects are not included in the package. Currently, you must have a package per project if you have project-to-project dependencies.
I.e. just like the linked answer says, there's no official way to do it other than publishing a package per project. If that's not an option, you can use the work arounds described there.
CodePudding user response:
I got the solution, one should edit ExternalProject.csproj file and add below xaml. Also add PrivateAssets="all" in the ProjectReference element.
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetMyPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="GetMyPackageFiles">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)InternalProject.dll">
</BuildOutputInPackage>
</ItemGroup>
</Target>