_From @Styxxy on September 5, 2018 12:19_
(Sorry if I am in the wrong repo, or if it is a duplicate issue (but I didn't find one when searching).)
I noticed that the XmlSerializer dll is not being copied, while in the old packages.config style.
Having a package with following nuspec (see nupkg (remove the zip extension),
Styxxy.MyPackage.1.0.0.nupkg.zip):
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>Styxxy.MyPackage</id>
    <version>1.0.0</version>
    <authors>Styxxy</authors>
    <owners>Styxxy</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Styxxy.MyPackage</description>
    <references>
      <reference file="Styxxy.MyPackage.dll" />
    </references>
  </metadata>
</package>
Package content:
My project is in SDK format and targets net47, although this problem (xmlserializer not being copied) also happens with the old project format but with PackageReference.
_Copied from original issue: dotnet/project-system#3953_
_From @Pilchie on September 5, 2018 17:4_
@livarcocc - this sounds like a NuGet MSbuild task issue. Does this below on https://github.com/dotnet/sdk?
I will move this issue to NuGet.
This seems to be a dupe of https://github.com/NuGet/Home/issues/6890 and https://github.com/NuGet/Home/issues/6858.
One possible workaround that was suggested by @rohit21agrawal in https://github.com/NuGet/Home/issues/6890#issuecomment-385772650 is to use these extension points/targets to add the serializer assembly to your package: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#targetsfortfmspecificbuildoutput.
Closing as a dupe.
@PatoBeltran Actually it is not a duplicate. Those mentioned issues are about nuget pack, while this issue is about consuming a package.
So when I have a package with the XmlSerializer assembly included. Now I consume this package in a project. I expect the XmlSerializer assembly also to be copied to the build output of my project, but it is not the case.
@Styxxy sorry for the confusion. will re-open and triage.
If i understand correctly, this problem only happens with PackageReference, and not packages.config?
@NuGet/nuget-client as per documented behavior, when there is a references element in the nuspec of a package, only the assemblies listed in the references element should be added as a reference to the project, but everything from the lib fodler should still be copied to the bin dir.
@rohit21agrawal Yes exactly. The same happens for pdb files (already logged as an issue somewhere) and actually also xml documentation files (if you compare it to the packages.config system).
Related to pdb and xml (doc) files: on build some of the MSBuild properties should be respected, eg. AllowedReferencedRelatedFileExtensions .
I am also having this problem for with the https://www.nuget.org/packages/OpcLabs.QuickOpc/ for versions 5.52.91, 5.52.184, and 5.53.315. The <references/> only includes:
OpcLabs.BaseLib.dllOpcLabs.BaseLibForms.dllOpcLabs.EasyOpcClassic.dllOpcLabs.EasyOpcUA.dllWith <PackageReference/>, the following files are not copied to the output folder. However, they are necessary for this package to work. With packages.config, the following files are not included in <ItemGroup><Reference/></ItemGroup>, but they still end up copied to the output folder:
App_Web_OpcLabs.EasyOpcClassicRaw.amd64.dllApp_Web_OpcLabs.EasyOpcClassicRaw.x86.dllI鈥檓 using visualstudio-15.8.4 and msbuild/r.
After investigating the same kind of issue for another customer yesterday, I can recommend something that will work. In the next few days I plan to update the docs to make it clearer as well. To work with PackageReference, the assemblies listed in the reference section of the nuspec needs to be duplicated in the ref/<tfm> directory in the package. Therefore, using the original question as an example, the package should contain the following files
lib\net47\Styxxy.MyPackage.dll
lib\net47\Styxxy.MyPackage.pdb
lib\net47\Styxxy.MyPackage.xml
lib\net47\Styxxy.MyPackage.XmlSerializer.dll
ref\net47\Styxxy.MyPackage.dll
The file in the ref directory does not need to be a "full" assembly, but can be a reference assembly to reduce package size. You can add the MSBuild property <ProduceReferenceAssembly>true</ProduceReferenceAssembly> to have the compiler build it for you at the same time as the full assembly, but when I tested the reference assembly's filename was referenceAssembly.dll, so you need to take this into account when preparing your NuGet package.
Projects using packages.config do not use the ref feature, so will continue to use the files in lib\<tfm>, copying all files on build, but only referencing the dlls as defined in the nuspec references section. Using the ref\<tfm> files in the package will allow projects using PackageReference to ignore the references section in the nuspec. Therefore this way the package will work as intended in both packages.config and PackageReference use-cases.
Be aware however that PackageReference ignores the lib\<tfm> folder when it selects an asset from runtime\<RID>\. Therefore, if you have any runtime assests that are selected by RID, you will need to duplicate the lib\<tfm> files into runtime in order to support PackageReference.
PR to add info to docs: NuGet/docs.microsoft.com-nuget#1443.